2008-05-18 06:22:34 +02:00
|
|
|
require 'abstract_unit'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
class CustomHandler < ActionView::TemplateHandler
|
2007-01-22 14:43:50 +01:00
|
|
|
def initialize( view )
|
|
|
|
@view = view
|
|
|
|
end
|
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
def render( template )
|
|
|
|
[ template.source,
|
|
|
|
template.locals,
|
2007-01-22 14:43:50 +01:00
|
|
|
@view ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class CustomHandlerTest < Test::Unit::TestCase
|
|
|
|
def setup
|
2008-05-18 06:22:34 +02:00
|
|
|
ActionView::Template.register_template_handler "foo", CustomHandler
|
|
|
|
ActionView::Template.register_template_handler :foo2, CustomHandler
|
2007-01-22 14:43:50 +01:00
|
|
|
@view = ActionView::Base.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_custom_render
|
2008-05-18 06:22:34 +02:00
|
|
|
template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo")
|
|
|
|
|
|
|
|
result = @view.render_template(template)
|
2007-01-22 14:43:50 +01:00
|
|
|
assert_equal(
|
|
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
|
|
|
result )
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_custom_render2
|
2008-05-18 06:22:34 +02:00
|
|
|
template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo2")
|
|
|
|
result = @view.render_template(template)
|
2007-01-22 14:43:50 +01:00
|
|
|
assert_equal(
|
|
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
|
|
|
result )
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_unhandled_extension
|
|
|
|
# uses the ERb handler by default if the extension isn't recognized
|
2008-05-18 06:22:34 +02:00
|
|
|
template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "bar")
|
|
|
|
result = @view.render_template(template)
|
2007-01-22 14:43:50 +01:00
|
|
|
assert_equal "hello two", result
|
|
|
|
end
|
|
|
|
end
|