mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Pass the view object as parameter to the handler. Useful if you need to access the lookup context or other information when compiling the template.
This commit is contained in:
parent
7b2f2c8b47
commit
f14c2bf582
2 changed files with 11 additions and 1 deletions
|
@ -269,7 +269,8 @@ module ActionView
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
code = @handler.call(self)
|
arity = @handler.respond_to?(:arity) ? @handler.arity : @handler.method(:call).arity
|
||||||
|
code = arity == 1 ? @handler.call(self) : @handler.call(self, view)
|
||||||
|
|
||||||
# Make sure that the resulting String to be evalled is in the
|
# Make sure that the resulting String to be evalled is in the
|
||||||
# encoding of the code
|
# encoding of the code
|
||||||
|
|
|
@ -221,6 +221,15 @@ module RenderTestCases
|
||||||
"@output_buffer << 'source: #{template.source.inspect}'\n"
|
"@output_buffer << 'source: #{template.source.inspect}'\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
WithViewHandler = lambda do |template, view|
|
||||||
|
%'"#{template.class} #{view.class}"'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_inline_with_template_handler_with_view
|
||||||
|
ActionView::Template.register_template_handler :with_view, WithViewHandler
|
||||||
|
assert_equal 'ActionView::Template ActionView::Base', @view.render(:inline => "Hello, World!", :type => :with_view)
|
||||||
|
end
|
||||||
|
|
||||||
def test_render_inline_with_compilable_custom_type
|
def test_render_inline_with_compilable_custom_type
|
||||||
ActionView::Template.register_template_handler :foo, CustomHandler
|
ActionView::Template.register_template_handler :foo, CustomHandler
|
||||||
assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo)
|
assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo)
|
||||||
|
|
Loading…
Reference in a new issue