2008-01-05 13:32:06 +00:00
|
|
|
require 'abstract_unit'
|
2005-02-19 17:22:37 +00:00
|
|
|
|
2008-01-11 04:45:06 +00:00
|
|
|
class CustomHandler < ActionView::TemplateHandler
|
2005-02-19 17:22:37 +00:00
|
|
|
def initialize( view )
|
|
|
|
@view = view
|
|
|
|
end
|
|
|
|
|
2008-03-03 04:01:35 +00:00
|
|
|
def render( template )
|
|
|
|
[ template.source,
|
|
|
|
template.locals,
|
2005-02-19 17:22:37 +00:00
|
|
|
@view ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class CustomHandlerTest < Test::Unit::TestCase
|
|
|
|
def setup
|
2008-03-05 02:03:24 +00:00
|
|
|
ActionView::Template.register_template_handler "foo", CustomHandler
|
|
|
|
ActionView::Template.register_template_handler :foo2, CustomHandler
|
2005-02-19 17:22:37 +00:00
|
|
|
@view = ActionView::Base.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_custom_render
|
2008-04-19 15:16:32 +00:00
|
|
|
template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo")
|
2008-02-06 04:26:40 +00:00
|
|
|
|
|
|
|
result = @view.render_template(template)
|
2005-02-19 17:22:37 +00:00
|
|
|
assert_equal(
|
2005-09-27 16:45:39 +00:00
|
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
2005-02-19 17:22:37 +00:00
|
|
|
result )
|
|
|
|
end
|
|
|
|
|
2006-03-26 21:50:22 +00:00
|
|
|
def test_custom_render2
|
2008-04-19 15:16:32 +00:00
|
|
|
template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo2")
|
2008-02-06 04:26:40 +00:00
|
|
|
result = @view.render_template(template)
|
2006-03-26 21:50:22 +00:00
|
|
|
assert_equal(
|
|
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
|
|
|
result )
|
|
|
|
end
|
|
|
|
|
2005-02-19 17:22:37 +00:00
|
|
|
def test_unhandled_extension
|
|
|
|
# uses the ERb handler by default if the extension isn't recognized
|
2008-04-19 15:16:32 +00:00
|
|
|
template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "bar")
|
2008-02-06 04:26:40 +00:00
|
|
|
result = @view.render_template(template)
|
2005-02-19 17:22:37 +00:00
|
|
|
assert_equal "hello two", result
|
|
|
|
end
|
|
|
|
end
|