提交 db17046b 编写于 作者: R Rafael Mendonça França

Merge pull request #7594 from guilleiguaran/rb-template-handler

Add .rb template handler
## Rails 4.0.0 (unreleased) ## ## 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`: * Add `separator` option for `ActionView::Helpers::TextHelper#excerpt`:
excerpt('This is a very beautiful morning', 'very', :separator => ' ', :radius => 1) excerpt('This is a very beautiful morning', 'very', :separator => ' ', :radius => 1)
......
...@@ -10,6 +10,7 @@ def self.extended(base) ...@@ -10,6 +10,7 @@ def self.extended(base)
base.register_default_template_handler :erb, ERB.new base.register_default_template_handler :erb, ERB.new
base.register_template_handler :builder, Builder.new base.register_template_handler :builder, Builder.new
base.register_template_handler :raw, Raw.new base.register_template_handler :raw, Raw.new
base.register_template_handler :rb, :source.to_proc
end end
@@template_handlers = {} @@template_handlers = {}
......
body = ""
body << ["Hello", "from", "Ruby", "code"].join(" ")
body
...@@ -97,6 +97,14 @@ def test_render_raw_template_with_quotes ...@@ -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") assert_equal %q;Here are some characters: !@#$%^&*()-="'}{`; + "\n", @view.render(:template => "plain_text_with_characters")
end 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 def test_render_file_with_localization_on_context_level
old_locale, @view.locale = @view.locale, :da old_locale, @view.locale = @view.locale, :da
assert_equal "Hey verden", @view.render(:file => "test/hello_world") assert_equal "Hey verden", @view.render(:file => "test/hello_world")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册