diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-19 17:22:37 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-19 17:22:37 +0000 |
commit | 9a5d6d6388a20f29c63f85a95d215b0b34ea9cfd (patch) | |
tree | 4f2b0590b43cb33a44baae44d153ef02252da761 /actionpack/test | |
parent | 9be37c9b203994724a1d7e60a99b207442f3fec5 (diff) | |
download | rails-9a5d6d6388a20f29c63f85a95d215b0b34ea9cfd.tar.gz rails-9a5d6d6388a20f29c63f85a95d215b0b34ea9cfd.tar.bz2 rails-9a5d6d6388a20f29c63f85a95d215b0b34ea9cfd.zip |
Added ActionView::Base.register_template_handler for easy integration of an alternative template language to ERb and Builder. See test/controller/custom_handler_test.rb for a usage example #656 [Jamis Buck]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@694 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/custom_handler_test.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/actionpack/test/controller/custom_handler_test.rb b/actionpack/test/controller/custom_handler_test.rb new file mode 100644 index 0000000000..8939d19166 --- /dev/null +++ b/actionpack/test/controller/custom_handler_test.rb @@ -0,0 +1,33 @@ +require File.dirname(__FILE__) + '/../abstract_unit' + +class CustomHandler + def initialize( view ) + @view = view + end + + def render( template, local_assigns ) + [ template, + local_assigns, + @view ] + end +end + +class CustomHandlerTest < Test::Unit::TestCase + def setup + ActionView::Base.register_template_handler "foo", CustomHandler + @view = ActionView::Base.new + end + + def test_custom_render + result = @view.render_template( "foo", "hello <%= one %>", "one" => "two" ) + 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 + result = @view.render_template( "bar", "hello <%= one %>", "one" => "two" ) + assert_equal "hello two", result + end +end |