Permalink
Browse files

A back support for legacy TemplateHandler#render API

  • Loading branch information...
1 parent 2c01f2b commit bc4d05b244c78f03ade51d8b95f16dd48ceb63d3 @josh josh committed Nov 23, 2008
@@ -1,9 +1,34 @@
# Legacy TemplateHandler stub
-
module ActionView
+ module TemplateHandlers #:nodoc:
+ module Compilable
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def call(template)
+ new.compile(template)
+ end
+ end
+
+ def compile(template)
+ raise "Need to implement #{self.class.name}#compile(template)"
+ end
+ end
+ end
+
class TemplateHandler
def self.call(template)
- new.compile(template)
+ "#{name}.new(self).render(template, local_assigns)"
+ end
+
+ def initialize(view = nil)
+ @view = view
+ end
+
+ def render(template, local_assigns)
+ raise "Need to implement #{self.class.name}#render(template, local_assigns)"
end
end
end
@@ -4,10 +4,6 @@ module TemplateHandlers #:nodoc:
autoload :RJS, 'action_view/template_handlers/rjs'
autoload :Builder, 'action_view/template_handlers/builder'
- # Legacy Compilable stub
- module Compilable
- end
-
def self.extended(base)
base.register_default_template_handler :erb, TemplateHandlers::ERB
base.register_template_handler :rjs, TemplateHandlers::RJS
@@ -175,6 +175,17 @@ def test_render_inline_with_locals_and_compilable_custom_type
assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
end
+ class LegacyHandler < ActionView::TemplateHandler
+ def render(template, local_assigns)
+ "source: #{template.source}; locals: #{local_assigns.inspect}"
+ end
+ end
+
+ def test_render_legacy_handler_with_custom_type
+ ActionView::Template.register_template_handler :foo, LegacyHandler
+ assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
+ end
+
def test_render_with_layout
assert_equal %(<title></title>\nHello world!\n),
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")

0 comments on commit bc4d05b

Please sign in to comment.