Skip to content

Commit

Permalink
Changed ActionView::TemplateHandler#render API method signature to re…
Browse files Browse the repository at this point in the history
…nder(template, local_assigns = {})
  • Loading branch information
josh committed Jul 11, 2008
1 parent 292501c commit 6ebdd0e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*

* Changed ActionView::TemplateHandler#render API method signature to render(template, local_assigns = {}) [Josh Peek]

* Changed PrototypeHelper#submit_to_remote to PrototypeHelper#button_to_remote to stay consistent with link_to_remote (submit_to_remote still works as an alias) #8994 [clemens]

* Add :recursive option to javascript_include_tag and stylesheet_link_tag to be used along with :all. #480 [Damian Janowski]
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/base.rb
Expand Up @@ -332,8 +332,8 @@ def assign_variables_from_controller
@assigns.each { |key, value| instance_variable_set("@#{key}", value) }
end

def execute(template)
send(template.method, template.locals) do |*names|
def execute(template, local_assigns = {})
send(template.method, local_assigns) do |*names|
instance_variable_get "@content_for_#{names.first || 'layout'}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/renderable.rb
Expand Up @@ -8,7 +8,7 @@ module Renderable

def render
prepare!
@handler.render(self)
@handler.render(self, @locals)
end

def method
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template_handler.rb
Expand Up @@ -8,7 +8,7 @@ def initialize(view)
@view = view
end

def render(template)
def render(template, local_assigns = {})
end

def compile(template)
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/template_handlers/compilable.rb
Expand Up @@ -14,8 +14,8 @@ def compilable?
end
end

def render(template)
@view.send(:execute, template)
def render(template, local_assigns = {})
@view.send(:execute, template, local_assigns)
end

# Compile and evaluate the template's code
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/layout_test.rb
Expand Up @@ -34,8 +34,8 @@ class MultipleExtensions < LayoutTest
class MabView < ActionView::TemplateHandler
def initialize(view)
end
def render(template)

def render(template, local_assigns)
template.source
end
end
Expand Down
9 changes: 4 additions & 5 deletions actionpack/test/template/render_test.rb
Expand Up @@ -95,8 +95,8 @@ def test_render_fallbacks_to_erb_for_unknown_types
end

class CustomHandler < ActionView::TemplateHandler
def render(template)
[template.source, template.locals].inspect
def render(template, local_assigns)
[template.source, local_assigns].inspect
end
end

Expand All @@ -115,18 +115,17 @@ class CompilableCustomHandler < ActionView::TemplateHandler

def compile(template)
"@output_buffer = ''\n" +
"@output_buffer << 'locals: #{template.locals.inspect}, '\n" +
"@output_buffer << 'source: #{template.source.inspect}'\n"
end
end

def test_render_inline_with_compilable_custom_type
ActionView::Template.register_template_handler :foo, CompilableCustomHandler
assert_equal 'locals: {}, source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo)
assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo)
end

def test_render_inline_with_locals_and_compilable_custom_type
ActionView::Template.register_template_handler :foo, CompilableCustomHandler
assert_equal 'locals: {:name=>"Josh"}, source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
end
end

0 comments on commit 6ebdd0e

Please sign in to comment.