aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-03-05 02:03:24 +0000
committerPratik Naik <pratiknaik@gmail.com>2008-03-05 02:03:24 +0000
commita96272a0c59b75a6838936af1eb7568b6136945a (patch)
tree12b69a7d678e513f0a43037dfe3f407906fb8415 /actionpack
parent89ee5d63d039af6770014a3bfdc4a743be9a429c (diff)
downloadrails-a96272a0c59b75a6838936af1eb7568b6136945a.tar.gz
rails-a96272a0c59b75a6838936af1eb7568b6136945a.tar.bz2
rails-a96272a0c59b75a6838936af1eb7568b6136945a.zip
Moved template handlers related code from ActionView::Base to ActionView::Template
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8981 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/base.rb3
-rw-r--r--actionpack/lib/action_view/base.rb38
-rw-r--r--actionpack/lib/action_view/helpers/cache_helper.rb2
-rw-r--r--actionpack/lib/action_view/template.rb40
-rw-r--r--actionpack/lib/action_view/template_finder.rb2
-rw-r--r--actionpack/test/controller/custom_handler_test.rb4
-rw-r--r--actionpack/test/controller/layout_test.rb2
-rw-r--r--actionpack/test/template/compiled_templates_test.rb2
-rw-r--r--actionpack/test/template/template_finder_test.rb4
10 files changed, 50 insertions, 49 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 3bf04b5eba..37aa537b9f 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Moved template handlers related code from ActionView::Base to ActionView::Template. [Pratik]
+
* Tests for div_for and content_tag_for helpers. Closes #11223 [thechrisoshow]
* Allow file uploads in Integration Tests. Closes #11091 [RubyRedRick]
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 7dd449d8a5..0651a08cb9 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -5,8 +5,7 @@ require 'action_controller/routing'
require 'action_controller/resources'
require 'action_controller/url_rewriter'
require 'action_controller/status_codes'
-require 'action_view/template'
-require 'action_view/template_finder'
+require 'action_view'
require 'drb'
require 'set'
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 143428c6d9..e83c8b6bd3 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -183,8 +183,6 @@ module ActionView #:nodoc:
cattr_accessor :erb_variable
delegate :request_forgery_protection_token, :to => :controller
-
- @@template_handlers = HashWithIndifferentAccess.new
module CompiledTemplates #:nodoc:
# holds compiled template code
@@ -201,9 +199,6 @@ module ActionView #:nodoc:
cattr_reader :computed_public_paths
@@computed_public_paths = {}
- @@template_handlers = {}
- @@default_template_handlers = nil
-
class ObjectWrapper < Struct.new(:value) #:nodoc:
end
@@ -218,39 +213,6 @@ module ActionView #:nodoc:
end
end
- # Register a class that knows how to handle template files with the given
- # extension. This can be used to implement new template types.
- # The constructor for the class must take the ActiveView::Base instance
- # as a parameter, and the class must implement a #render method that
- # takes the contents of the template to render as well as the Hash of
- # local assigns available to the template. The #render method ought to
- # return the rendered template as a string.
- def self.register_template_handler(extension, klass)
- @@template_handlers[extension.to_sym] = klass
- TemplateFinder.update_extension_cache_for(extension.to_s)
- end
-
- def self.template_handler_extensions
- @@template_handlers.keys.map(&:to_s).sort
- end
-
- def self.register_default_template_handler(extension, klass)
- register_template_handler(extension, klass)
- @@default_template_handlers = klass
- end
-
- def self.handler_class_for_extension(extension)
- (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers
- end
-
- register_default_template_handler :erb, TemplateHandlers::ERB
- register_template_handler :rjs, TemplateHandlers::RJS
- register_template_handler :builder, TemplateHandlers::Builder
-
- # TODO: Depreciate old template extensions
- register_template_handler :rhtml, TemplateHandlers::ERB
- register_template_handler :rxml, TemplateHandlers::Builder
-
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
@assigns = assigns_for_first_render
@assigns_added = nil
diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb
index c2aab5aa72..930c397785 100644
--- a/actionpack/lib/action_view/helpers/cache_helper.rb
+++ b/actionpack/lib/action_view/helpers/cache_helper.rb
@@ -32,7 +32,7 @@ module ActionView
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
- handler = Base.handler_class_for_extension(current_render_extension.to_sym)
+ handler = Template.handler_class_for_extension(current_render_extension.to_sym)
handler.new(@controller).cache_fragment(block, name, options)
end
end
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 9f979e2e5d..0cd6784fd8 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -19,7 +19,7 @@ module ActionView #:nodoc:
@extension = inline_type
end
@locals = locals || {}
- @handler = @view.class.handler_class_for_extension(@extension).new(@view)
+ @handler = self.class.handler_class_for_extension(@extension).new(@view)
end
def render
@@ -73,5 +73,43 @@ module ActionView #:nodoc:
end
end
+ # Template Handlers
+
+ @@template_handlers = HashWithIndifferentAccess.new
+ @@default_template_handlers = nil
+
+ # Register a class that knows how to handle template files with the given
+ # extension. This can be used to implement new template types.
+ # The constructor for the class must take the ActiveView::Base instance
+ # as a parameter, and the class must implement a #render method that
+ # takes the contents of the template to render as well as the Hash of
+ # local assigns available to the template. The #render method ought to
+ # return the rendered template as a string.
+ def self.register_template_handler(extension, klass)
+ @@template_handlers[extension.to_sym] = klass
+ TemplateFinder.update_extension_cache_for(extension.to_s)
+ end
+
+ def self.template_handler_extensions
+ @@template_handlers.keys.map(&:to_s).sort
+ end
+
+ def self.register_default_template_handler(extension, klass)
+ register_template_handler(extension, klass)
+ @@default_template_handlers = klass
+ end
+
+ def self.handler_class_for_extension(extension)
+ (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers
+ end
+
+ register_default_template_handler :erb, TemplateHandlers::ERB
+ register_template_handler :rjs, TemplateHandlers::RJS
+ register_template_handler :builder, TemplateHandlers::Builder
+
+ # TODO: Depreciate old template extensions
+ register_template_handler :rhtml, TemplateHandlers::ERB
+ register_template_handler :rxml, TemplateHandlers::Builder
+
end
end
diff --git a/actionpack/lib/action_view/template_finder.rb b/actionpack/lib/action_view/template_finder.rb
index 648fdf43e8..f483d24a2f 100644
--- a/actionpack/lib/action_view/template_finder.rb
+++ b/actionpack/lib/action_view/template_finder.rb
@@ -50,7 +50,7 @@ module ActionView #:nodoc:
end
def template_handler_extensions
- ActionView::Base.template_handler_extensions
+ ActionView::Template.template_handler_extensions
end
def reload!
diff --git a/actionpack/test/controller/custom_handler_test.rb b/actionpack/test/controller/custom_handler_test.rb
index cdde00cccc..cf1e2361bd 100644
--- a/actionpack/test/controller/custom_handler_test.rb
+++ b/actionpack/test/controller/custom_handler_test.rb
@@ -14,8 +14,8 @@ end
class CustomHandlerTest < Test::Unit::TestCase
def setup
- ActionView::Base.register_template_handler "foo", CustomHandler
- ActionView::Base.register_template_handler :foo2, CustomHandler
+ ActionView::Template.register_template_handler "foo", CustomHandler
+ ActionView::Template.register_template_handler :foo2, CustomHandler
@view = ActionView::Base.new
end
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 56d7f69774..c8507af532 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -40,7 +40,7 @@ class MabView < ActionView::TemplateHandler
end
end
-ActionView::Base::register_template_handler :mab, MabView
+ActionView::Template::register_template_handler :mab, MabView
class LayoutAutoDiscoveryTest < Test::Unit::TestCase
def setup
diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb
index b969575235..73e7ec1d76 100644
--- a/actionpack/test/template/compiled_templates_test.rb
+++ b/actionpack/test/template/compiled_templates_test.rb
@@ -91,7 +91,7 @@ class CompiledTemplateTests < Test::Unit::TestCase
tb = ActionView::Template.new(v, @b, false, {})
ts = ActionView::Template.new(v, @s, false, {})
- @handler_class = ActionView::Base.handler_class_for_extension(:rhtml)
+ @handler_class = ActionView::Template.handler_class_for_extension(:rhtml)
@handler = @handler_class.new(v)
# All templates were created at t+1
diff --git a/actionpack/test/template/template_finder_test.rb b/actionpack/test/template/template_finder_test.rb
index 6cd6957a0b..2b9569f099 100644
--- a/actionpack/test/template/template_finder_test.rb
+++ b/actionpack/test/template/template_finder_test.rb
@@ -6,7 +6,7 @@ class TemplateFinderTest < Test::Unit::TestCase
def setup
ActionView::TemplateFinder.process_view_paths(LOAD_PATH_ROOT)
- ActionView::Base::register_template_handler :mab, Class.new(ActionView::TemplateHandler)
+ ActionView::Template::register_template_handler :mab, Class.new(ActionView::TemplateHandler)
@template = ActionView::Base.new
@finder = ActionView::TemplateFinder.new(@template, LOAD_PATH_ROOT)
end
@@ -35,7 +35,7 @@ class TemplateFinderTest < Test::Unit::TestCase
def test_should_update_extension_cache_when_template_handler_is_registered
ActionView::TemplateFinder.expects(:update_extension_cache_for).with("funky")
- ActionView::Base::register_template_handler :funky, Class.new(ActionView::TemplateHandler)
+ ActionView::Template::register_template_handler :funky, Class.new(ActionView::TemplateHandler)
end
end