diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 8c7089cf571c261e8acbfe8a854f96f76740703c..36e8479441454e5b2720daa2084e19252328f520 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Add .rb template handler, this handler simply allows arbitrary Ruby code as a template. *Guillermo Iguaran* + * Add `separator` option for `ActionView::Helpers::TextHelper#excerpt`: excerpt('This is a very beautiful morning', 'very', :separator => ' ', :radius => 1) diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb index 41b14373a3f2631735b8435386ae704fcebf05aa..52e032bbd89e20440dba735458d7043ac49e1d36 100644 --- a/actionpack/lib/action_view/template/handlers.rb +++ b/actionpack/lib/action_view/template/handlers.rb @@ -10,6 +10,7 @@ def self.extended(base) base.register_default_template_handler :erb, ERB.new base.register_template_handler :builder, Builder.new base.register_template_handler :raw, Raw.new + base.register_template_handler :rb, :source.to_proc end @@template_handlers = {} diff --git a/actionpack/test/fixtures/ruby_template.rb b/actionpack/test/fixtures/ruby_template.rb new file mode 100644 index 0000000000000000000000000000000000000000..d99833a24d3efd14c4477f20a3db20582d314e7e --- /dev/null +++ b/actionpack/test/fixtures/ruby_template.rb @@ -0,0 +1,3 @@ +body = "" +body << ["Hello", "from", "Ruby", "code"].join(" ") +body diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index b26354e7ccb7fcc60276b85b6a8ad6767fb4f48a..6279abaae5f3f4bdd71cde3d0476ca15bb0cf37d 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -97,6 +97,14 @@ def test_render_raw_template_with_quotes assert_equal %q;Here are some characters: !@#$%^&*()-="'}{`; + "\n", @view.render(:template => "plain_text_with_characters") end + def test_render_rb_template_with_handlers + assert_equal "Hello from Ruby code", @view.render(:template => "ruby_template") + end + + def test_render_rb_template_inline + assert_equal '4', @view.render(:inline => "(2**2).to_s", :type => :rb) + end + def test_render_file_with_localization_on_context_level old_locale, @view.locale = @view.locale, :da assert_equal "Hey verden", @view.render(:file => "test/hello_world")