From 18769aab73f04b3b8792242a0fecebf5ce247ab6 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Johan=20S=C3=B8rensen?= Date: Tue, 28 Apr 2009 13:15:28 +0200 Subject: [PATCH] Make partial rendering from within a content_for capture work with ruby 1.9 encodings --- actionpack/lib/action_view/renderable.rb | 5 +++-- .../test/fixtures/test/content_for_utf8.html.erb | 5 +++++ actionpack/test/template/render_test.rb | 12 ++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 actionpack/test/fixtures/test/content_for_utf8.html.erb diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index ff7bc7d..caa7719 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -36,7 +36,8 @@ module ActionView if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar)) view.capture(*names, &proc) elsif view.instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}") - view.instance_variable_get(ivar) + res = view.instance_variable_get(ivar) + res.respond_to?(:force_encoding) ? res.force_encoding(Encoding::UTF_8) : res end end end @@ -67,7 +68,7 @@ module ActionView source = <<-end_src def #{render_symbol}(local_assigns) - old_output_buffer = output_buffer;#{locals_code};#{compiled_source} + old_output_buffer = output_buffer;#{locals_code};#{compiled_source.respond_to?(:force_encoding) ? compiled_source.force_encoding(Encoding::UTF_8) : compiled_source} ensure self.output_buffer = old_output_buffer end diff --git a/actionpack/test/fixtures/test/content_for_utf8.html.erb b/actionpack/test/fixtures/test/content_for_utf8.html.erb new file mode 100644 index 0000000..3a91f38 --- /dev/null +++ b/actionpack/test/fixtures/test/content_for_utf8.html.erb @@ -0,0 +1,5 @@ +<% content_for :title do -%> +Русский текст +<%= render :partial => "test/partial_for_use_in_layout", :locals => {:name => " 日本語のテキスト"} -%> +<% end -%> +yay? \ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 9adf053..eae55a4 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -250,10 +250,18 @@ module RenderTestCases if '1.9'.respond_to?(:force_encoding) def test_render_utf8_template - result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield") - assert_equal "Русский текст\n日本語のテキスト", result + result = @view.render(:file => "test/utf8.html.erb", :layout => "layouts/yield") + assert_equal "\nРусский текст\n日本語のテキスト\n", result assert_equal Encoding::UTF_8, result.encoding end + + def test_render_utf8_template_with_named_yield_and_a_partial + assert_nothing_raised do + result = @view.render(:file => "test/content_for_utf8.html.erb", :layout => "layouts/yield") + assert_equal "Русский текст\nInside from partial ( 日本語のテキスト)\nyay?\n", result + assert_equal Encoding::UTF_8, result.encoding + end + end end end -- 1.6.1