Browse files

Deprecate old template handler API. Remove old handlers.

  • Loading branch information...
1 parent 64c7f7e commit c7408a0e40545558872efb4129fe4bf097c9ce2f @josevalim josevalim committed Oct 10, 2010
Showing with 64 additions and 59 deletions.
  1. +9 −1 actionpack/lib/action_view/template/handler.rb
  2. +3 −7 actionpack/lib/action_view/template/handlers.rb
  3. +4 −4 actionpack/lib/action_view/template/handlers/builder.rb
  4. +15 −10 actionpack/lib/action_view/template/handlers/erb.rb
  5. +4 −8 actionpack/lib/action_view/template/handlers/rjs.rb
  6. +12 −12 actionpack/test/controller/content_type_test.rb
  7. +9 −9 actionpack/test/controller/layout_test.rb
  8. +1 −0 actionpack/test/fixtures/layout_tests/alt/hello.erb
  9. +0 −1 actionpack/test/fixtures/layout_tests/alt/hello.rhtml
  10. 0 actionpack/test/fixtures/layout_tests/alt/layouts/{alt.rhtml → alt.erb}
  11. +1 −0 actionpack/test/fixtures/layout_tests/layouts/controller_name_space/nested.erb
  12. +0 −1 actionpack/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml
  13. +1 −0 actionpack/test/fixtures/layout_tests/layouts/item.erb
  14. +0 −1 actionpack/test/fixtures/layout_tests/layouts/item.rhtml
  15. +1 −0 actionpack/test/fixtures/layout_tests/layouts/layout_test.erb
  16. +0 −1 actionpack/test/fixtures/layout_tests/layouts/layout_test.rhtml
  17. +1 −0 actionpack/test/fixtures/layout_tests/views/goodbye.erb
  18. +0 −1 actionpack/test/fixtures/layout_tests/views/goodbye.rhtml
  19. +1 −0 actionpack/test/fixtures/layout_tests/views/hello.erb
  20. +0 −1 actionpack/test/fixtures/layout_tests/views/hello.rhtml
  21. 0 ...est/fixtures/old_content_type/{render_default_for_rxml.rxml → render_default_for_builder.builder}
  22. 0 ...pack/test/fixtures/old_content_type/{render_default_for_rhtml.rhtml → render_default_for_erb.erb}
  23. +2 −2 actionpack/test/template/template_test.rb
View
10 actionpack/lib/action_view/template/handler.rb
@@ -1,4 +1,4 @@
-require "action_dispatch/http/mime_type"
+require 'action_dispatch/http/mime_type'
require 'active_support/core_ext/class/attribute'
# Legacy TemplateHandler stub
@@ -7,6 +7,8 @@ class Template
module Handlers #:nodoc:
module Compilable
def self.included(base)
+ ActiveSupport::Deprecation.warn "Including Compilable in your template handler is deprecated. " <<
+ "All the API your template handler needs to implement is to respond to #call."
base.extend(ClassMethods)
end
@@ -26,6 +28,12 @@ class Template::Handler
class_attribute :default_format
self.default_format = Mime::HTML
+ def self.inherited(base)
+ ActiveSupport::Deprecation.warn "Inheriting from ActionView::Template::Handler is deprecated. " <<
+ "All the API your template handler needs to implement is to respond to #call."
+ super
+ end
+
def self.call(template)
raise "Need to implement #{self.class.name}#call(template)"
end
View
10 actionpack/lib/action_view/template/handlers.rb
@@ -7,13 +7,9 @@ module Handlers #:nodoc:
autoload :Builder, 'action_view/template/handlers/builder'
def self.extended(base)
- base.register_default_template_handler :erb, ERB
- base.register_template_handler :rjs, RJS
- base.register_template_handler :builder, Builder
-
- # TODO: Depreciate old template extensions
- base.register_template_handler :rhtml, ERB
- base.register_template_handler :rxml, Builder
+ base.register_default_template_handler :erb, ERB.new
+ base.register_template_handler :rjs, RJS.new
+ base.register_template_handler :builder, Builder.new
end
@@template_handlers = {}
View
8 actionpack/lib/action_view/template/handlers/builder.rb
@@ -1,11 +1,11 @@
module ActionView
module Template::Handlers
- class Builder < Template::Handler
- include Compilable
-
+ class Builder
+ # Default format used by Builder.
+ class_attribute :default_format
self.default_format = Mime::XML
- def compile(template)
+ def call(template)
require 'builder'
"xml = ::Builder::XmlMarkup.new(:indent => 2);" +
"self.output_buffer = xml.target!;" +
View
25 actionpack/lib/action_view/template/handlers/erb.rb
@@ -1,6 +1,7 @@
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/string/output_safety'
-require "action_view/template"
+require 'action_view/template'
+require 'action_view/template/handler'
require 'erubis'
module ActionView
@@ -47,28 +48,31 @@ def add_postamble(src)
end
end
- class ERB < Handler
- include Compilable
-
- ##
- # :singleton-method:
+ class ERB
# Specify trim mode for the ERB compiler. Defaults to '-'.
# See ERb documentation for suitable values.
- cattr_accessor :erb_trim_mode
+ class_attribute :erb_trim_mode
self.erb_trim_mode = '-'
+ # Default format used by ERB.
+ class_attribute :default_format
self.default_format = Mime::HTML
- cattr_accessor :erb_implementation
+ # Default implemenation used.
+ class_attribute :erb_implementation
self.erb_implementation = Erubis
ENCODING_TAG = Regexp.new("\\A(<%#{ENCODING_FLAG}-?%>)[ \\t]*")
- def self.handles_encoding?
+ def self.call(template)
+ new.call(template)
+ end
+
+ def handles_encoding?
true
end
- def compile(template)
+ def call(template)
if template.source.encoding_aware?
# First, convert to BINARY, so in case the encoding is
# wrong, we can still find an encoding tag
@@ -94,6 +98,7 @@ def compile(template)
end
private
+
def valid_encoding(string, encoding)
# If a magic encoding comment was found, tag the
# String with this encoding. This is for a case
View
12 actionpack/lib/action_view/template/handlers/rjs.rb
@@ -1,17 +1,13 @@
module ActionView
module Template::Handlers
- class RJS < Template::Handler
- include Compilable
-
+ class RJS
+ # Default format used by RJS.
+ class_attribute :default_format
self.default_format = Mime::JS
- def compile(template)
+ def call(template)
"update_page do |page|;#{template.source}\nend"
end
-
- def default_format
- Mime::JS
- end
end
end
end
View
24 actionpack/test/controller/content_type_test.rb
@@ -29,18 +29,18 @@ def render_nil_charset_from_body
render :text => "hello world!"
end
- def render_default_for_rhtml
+ def render_default_for_erb
end
- def render_default_for_rxml
+ def render_default_for_builder
end
def render_default_for_rjs
end
- def render_change_for_rxml
+ def render_change_for_builder
response.content_type = Mime::HTML
- render :action => "render_default_for_rxml"
+ render :action => "render_default_for_builder"
end
def render_default_content_types_for_respond_to
@@ -108,23 +108,23 @@ def test_nil_charset_from_body
assert_equal "utf-8", @response.charset, @response.headers.inspect
end
- def test_nil_default_for_rhtml
+ def test_nil_default_for_erb
OldContentTypeController.default_charset = nil
- get :render_default_for_rhtml
+ get :render_default_for_erb
assert_equal Mime::HTML, @response.content_type
assert_nil @response.charset, @response.headers.inspect
ensure
OldContentTypeController.default_charset = "utf-8"
end
- def test_default_for_rhtml
- get :render_default_for_rhtml
+ def test_default_for_erb
+ get :render_default_for_erb
assert_equal Mime::HTML, @response.content_type
assert_equal "utf-8", @response.charset
end
- def test_default_for_rxml
- get :render_default_for_rxml
+ def test_default_for_builder
+ get :render_default_for_builder
assert_equal Mime::XML, @response.content_type
assert_equal "utf-8", @response.charset
end
@@ -135,8 +135,8 @@ def test_default_for_rjs
assert_equal "utf-8", @response.charset
end
- def test_change_for_rxml
- get :render_change_for_rxml
+ def test_change_for_builder
+ get :render_change_for_builder
assert_equal Mime::HTML, @response.content_type
assert_equal "utf-8", @response.charset
end
View
18 actionpack/test/controller/layout_test.rb
@@ -46,13 +46,13 @@ def setup
def test_application_layout_is_default_when_no_controller_match
@controller = ProductController.new
get :hello
- assert_equal 'layout_test.rhtml hello.rhtml', @response.body
+ assert_equal 'layout_test.erb hello.erb', @response.body
end
def test_controller_name_layout_name_match
@controller = ItemController.new
get :hello
- assert_equal 'item.rhtml hello.rhtml', @response.body
+ assert_equal 'item.erb hello.erb', @response.body
end
def test_third_party_template_library_auto_discovers_layout
@@ -65,21 +65,21 @@ def test_third_party_template_library_auto_discovers_layout
def test_namespaced_controllers_auto_detect_layouts1
@controller = ControllerNameSpace::NestedController.new
get :hello
- assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
+ assert_equal 'controller_name_space/nested.erb hello.erb', @response.body
end
def test_namespaced_controllers_auto_detect_layouts2
@controller = MultipleExtensions.new
get :hello
- assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
+ assert_equal 'multiple_extensions.html.erb hello.erb', @response.body.strip
end
end
class DefaultLayoutController < LayoutTest
end
class AbsolutePathLayoutController < LayoutTest
- layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
+ layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.erb')
end
class HasOwnLayoutController < LayoutTest
@@ -137,7 +137,7 @@ def test_layout_only_exception_when_included
def test_layout_only_exception_when_excepted
@controller = OnlyLayoutController.new
get :goodbye
- assert !@response.body.include?("item.rhtml"), "#{@response.body.inspect} included 'item.rhtml'"
+ assert !@response.body.include?("item.erb"), "#{@response.body.inspect} included 'item.erb'"
end
def test_layout_except_exception_when_included
@@ -149,7 +149,7 @@ def test_layout_except_exception_when_included
def test_layout_except_exception_when_excepted
@controller = ExceptLayoutController.new
get :goodbye
- assert !@response.body.include?("item.rhtml"), "#{@response.body.inspect} included 'item.rhtml'"
+ assert !@response.body.include?("item.erb"), "#{@response.body.inspect} included 'item.erb'"
end
def test_layout_set_when_using_render
@@ -173,7 +173,7 @@ def test_layout_is_picked_from_the_controller_instances_view_path
def test_absolute_pathed_layout
@controller = AbsolutePathLayoutController.new
get :hello
- assert_equal "layout_test.rhtml hello.rhtml", @response.body.strip
+ assert_equal "layout_test.erb hello.erb", @response.body.strip
end
end
@@ -184,7 +184,7 @@ def hello
end
class SetsNonExistentLayoutFile < LayoutTest
- layout "nofile.rhtml"
+ layout "nofile.erb"
end
class LayoutExceptionRaised < ActionController::TestCase
View
1 actionpack/test/fixtures/layout_tests/alt/hello.erb
@@ -0,0 +1 @@
+alt/hello.erb
View
1 actionpack/test/fixtures/layout_tests/alt/hello.rhtml
@@ -1 +0,0 @@
-alt/hello.rhtml
View
0 ...xtures/layout_tests/alt/layouts/alt.rhtml → ...fixtures/layout_tests/alt/layouts/alt.erb
File renamed without changes.
View
1 actionpack/test/fixtures/layout_tests/layouts/controller_name_space/nested.erb
@@ -0,0 +1 @@
+controller_name_space/nested.erb <%= yield %>
View
1 actionpack/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml
@@ -1 +0,0 @@
-controller_name_space/nested.rhtml <%= yield %>
View
1 actionpack/test/fixtures/layout_tests/layouts/item.erb
@@ -0,0 +1 @@
+item.erb <%= yield %>
View
1 actionpack/test/fixtures/layout_tests/layouts/item.rhtml
@@ -1 +0,0 @@
-item.rhtml <%= yield %>
View
1 actionpack/test/fixtures/layout_tests/layouts/layout_test.erb
@@ -0,0 +1 @@
+layout_test.erb <%= yield %>
View
1 actionpack/test/fixtures/layout_tests/layouts/layout_test.rhtml
@@ -1 +0,0 @@
-layout_test.rhtml <%= yield %>
View
1 actionpack/test/fixtures/layout_tests/views/goodbye.erb
@@ -0,0 +1 @@
+hello.erb
View
1 actionpack/test/fixtures/layout_tests/views/goodbye.rhtml
@@ -1 +0,0 @@
-hello.rhtml
View
1 actionpack/test/fixtures/layout_tests/views/hello.erb
@@ -0,0 +1 @@
+hello.erb
View
1 actionpack/test/fixtures/layout_tests/views/hello.rhtml
@@ -1 +0,0 @@
-hello.rhtml
View
0 ...content_type/render_default_for_rxml.rxml → ...t_type/render_default_for_builder.builder
File renamed without changes.
View
0 ...ntent_type/render_default_for_rhtml.rhtml → ...d_content_type/render_default_for_erb.erb
File renamed without changes.
View
4 actionpack/test/template/template_test.rb
@@ -1,7 +1,7 @@
require "abstract_unit"
class TestERBTemplate < ActiveSupport::TestCase
- ERBHandler = ActionView::Template::Handlers::ERB
+ ERBHandler = ActionView::Template::Handlers::ERB.new
class Context
def initialize
@@ -121,7 +121,7 @@ def test_lying_with_magic_comment
def test_encoding_can_be_specified_with_magic_comment_in_erb
with_external_encoding Encoding::UTF_8 do
- @template = new_template("<%# encoding: ISO-8859-1 %>hello \xFCmlat")
+ @template = new_template("<%# encoding: ISO-8859-1 %>hello \xFCmlat", :virtual_path => nil)
result = render
assert_equal Encoding::UTF_8, render.encoding
assert_equal "hello \u{fc}mlat", render

1 comment on commit c7408a0

Please sign in to comment.