Skip to content

Commit

Permalink
Removed lagacy TemplateHandler#render API. Left in a legacy TemplateH…
Browse files Browse the repository at this point in the history
…andler and Compilable stub so plugins will not have to change anything.
  • Loading branch information
josh committed Jul 18, 2008
1 parent ef6f662 commit d2ccb85
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 76 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/base.rb
Expand Up @@ -379,8 +379,8 @@ def assign_variables_from_controller
@assigns.each { |key, value| instance_variable_set("@#{key}", value) }
end

def execute(template, local_assigns = {})
send(template.method(local_assigns), local_assigns) do |*names|
def execute(method, local_assigns = {})
send(method, local_assigns) do |*names|
instance_variable_get "@content_for_#{names.first || 'layout'}"
end
end
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_view/renderable.rb
Expand Up @@ -19,16 +19,16 @@ def handler
memoize :handler

def compiled_source
handler.new(nil).compile(self) if handler.compilable?
handler.call(self)
end
memoize :compiled_source

def render(view, local_assigns = {})
view._first_render ||= self
view._last_render = self
view.send(:evaluate_assigns)
compile(local_assigns) if handler.compilable?
handler.new(view).render(self, local_assigns)
compile(local_assigns)
view.send(:execute, method(local_assigns), local_assigns)
end

def method(local_assigns)
Expand Down
23 changes: 8 additions & 15 deletions actionpack/lib/action_view/template_handler.rb
@@ -1,21 +1,14 @@
module ActionView
class TemplateHandler
def self.compilable?
false
end

def initialize(view)
@view = view
end
# Legacy TemplateHandler stub

def render(template, local_assigns = {})
end

def compile(template)
module ActionView
module TemplateHandlers
module Compilable
end
end

def compilable?
self.class.compilable?
class TemplateHandler
def self.call(template)
new.compile(template)
end
end
end
1 change: 0 additions & 1 deletion actionpack/lib/action_view/template_handlers.rb
@@ -1,5 +1,4 @@
require 'action_view/template_handler'
require 'action_view/template_handlers/compilable'
require 'action_view/template_handlers/builder'
require 'action_view/template_handlers/erb'
require 'action_view/template_handlers/rjs'
Expand Down
20 changes: 0 additions & 20 deletions actionpack/lib/action_view/template_handlers/compilable.rb

This file was deleted.

12 changes: 2 additions & 10 deletions actionpack/test/controller/layout_test.rb
Expand Up @@ -31,16 +31,8 @@ class ControllerNameSpace::NestedController < LayoutTest
class MultipleExtensions < LayoutTest
end

class MabView < ActionView::TemplateHandler
def initialize(view)
end

def render(template, local_assigns)
template.source
end
end

ActionView::Template::register_template_handler :mab, MabView
ActionView::Template::register_template_handler :mab,
lambda { |template| template.source.inspect }

class LayoutAutoDiscoveryTest < Test::Unit::TestCase
def setup
Expand Down
30 changes: 5 additions & 25 deletions actionpack/test/template/render_test.rb
Expand Up @@ -94,38 +94,18 @@ def test_render_fallbacks_to_erb_for_unknown_types
assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo)
end

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

def test_render_inline_with_custom_type
ActionView::Template.register_template_handler :foo, CustomHandler
assert_equal '["Hello, World!", {}]', @view.render(:inline => "Hello, World!", :type => :foo)
end

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

class CompilableCustomHandler < ActionView::TemplateHandler
include ActionView::TemplateHandlers::Compilable

def compile(template)
"@output_buffer = ''\n" +
"@output_buffer << 'source: #{template.source.inspect}'\n"
end
CustomHandler = lambda do |template|
"@output_buffer = ''\n" +
"@output_buffer << 'source: #{template.source.inspect}'\n"
end

def test_render_inline_with_compilable_custom_type
ActionView::Template.register_template_handler :foo, CompilableCustomHandler
ActionView::Template.register_template_handler :foo, CustomHandler
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
ActionView::Template.register_template_handler :foo, CustomHandler
assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
end
end

1 comment on commit d2ccb85

@josh
Copy link
Contributor Author

@josh josh commented on d2ccb85 Nov 14, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance.

Adding your own custom render is still easy. Nothing stops you from defining a method like render_foo.

Please sign in to comment.