aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-11-17 23:50:45 +0100
committerJosé Valim <jose.valim@gmail.com>2010-11-17 23:50:45 +0100
commitf14c2bf58204f488cbe589e077a124865ea595f5 (patch)
treedacea54739b3c2c0a5e06a77d285165794002fc3 /actionpack
parent7b2f2c8b477adae9bc7243fb9c895f8a823188a3 (diff)
downloadrails-f14c2bf58204f488cbe589e077a124865ea595f5.tar.gz
rails-f14c2bf58204f488cbe589e077a124865ea595f5.tar.bz2
rails-f14c2bf58204f488cbe589e077a124865ea595f5.zip
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.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/template.rb3
-rw-r--r--actionpack/test/template/render_test.rb9
2 files changed, 11 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index dbb1532cd4..6c6d659246 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -269,7 +269,8 @@ module ActionView
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
# encoding of the code
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index d2bf45a63a..8087429d62 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -221,6 +221,15 @@ module RenderTestCases
"@output_buffer << 'source: #{template.source.inspect}'\n"
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
ActionView::Template.register_template_handler :foo, CustomHandler
assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo)