Changeset 8981
- Timestamp:
- 03/05/08 02:03:24 (6 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/base.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/helpers/cache_helper.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/template_finder.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/template.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/custom_handler_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/layout_test.rb (modified) (1 diff)
- trunk/actionpack/test/template/compiled_templates_test.rb (modified) (1 diff)
- trunk/actionpack/test/template/template_finder_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8980 r8981 1 1 *SVN* 2 3 * Moved template handlers related code from ActionView::Base to ActionView::Template. [Pratik] 2 4 3 5 * Tests for div_for and content_tag_for helpers. Closes #11223 [thechrisoshow] trunk/actionpack/lib/action_controller/base.rb
r8862 r8981 6 6 require 'action_controller/url_rewriter' 7 7 require 'action_controller/status_codes' 8 require 'action_view/template' 9 require 'action_view/template_finder' 8 require 'action_view' 10 9 require 'drb' 11 10 require 'set' trunk/actionpack/lib/action_view/base.rb
r8976 r8981 184 184 185 185 delegate :request_forgery_protection_token, :to => :controller 186 187 @@template_handlers = HashWithIndifferentAccess.new188 186 189 187 module CompiledTemplates #:nodoc: … … 201 199 cattr_reader :computed_public_paths 202 200 @@computed_public_paths = {} 203 204 @@template_handlers = {}205 @@default_template_handlers = nil206 201 207 202 class ObjectWrapper < Struct.new(:value) #:nodoc: … … 218 213 end 219 214 end 220 221 # Register a class that knows how to handle template files with the given222 # extension. This can be used to implement new template types.223 # The constructor for the class must take the ActiveView::Base instance224 # as a parameter, and the class must implement a #render method that225 # takes the contents of the template to render as well as the Hash of226 # local assigns available to the template. The #render method ought to227 # return the rendered template as a string.228 def self.register_template_handler(extension, klass)229 @@template_handlers[extension.to_sym] = klass230 TemplateFinder.update_extension_cache_for(extension.to_s)231 end232 233 def self.template_handler_extensions234 @@template_handlers.keys.map(&:to_s).sort235 end236 237 def self.register_default_template_handler(extension, klass)238 register_template_handler(extension, klass)239 @@default_template_handlers = klass240 end241 242 def self.handler_class_for_extension(extension)243 (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers244 end245 246 register_default_template_handler :erb, TemplateHandlers::ERB247 register_template_handler :rjs, TemplateHandlers::RJS248 register_template_handler :builder, TemplateHandlers::Builder249 250 # TODO: Depreciate old template extensions251 register_template_handler :rhtml, TemplateHandlers::ERB252 register_template_handler :rxml, TemplateHandlers::Builder253 215 254 216 def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc: trunk/actionpack/lib/action_view/helpers/cache_helper.rb
r8791 r8981 33 33 # <% end %> 34 34 def cache(name = {}, options = nil, &block) 35 handler = Base.handler_class_for_extension(current_render_extension.to_sym)35 handler = Template.handler_class_for_extension(current_render_extension.to_sym) 36 36 handler.new(@controller).cache_fragment(block, name, options) 37 37 end trunk/actionpack/lib/action_view/template_finder.rb
r8809 r8981 51 51 52 52 def template_handler_extensions 53 ActionView:: Base.template_handler_extensions53 ActionView::Template.template_handler_extensions 54 54 end 55 55 trunk/actionpack/lib/action_view/template.rb
r8976 r8981 20 20 end 21 21 @locals = locals || {} 22 @handler = @view.class.handler_class_for_extension(@extension).new(@view)22 @handler = self.class.handler_class_for_extension(@extension).new(@view) 23 23 end 24 24 … … 74 74 end 75 75 76 # Template Handlers 77 78 @@template_handlers = HashWithIndifferentAccess.new 79 @@default_template_handlers = nil 80 81 # Register a class that knows how to handle template files with the given 82 # extension. This can be used to implement new template types. 83 # The constructor for the class must take the ActiveView::Base instance 84 # as a parameter, and the class must implement a #render method that 85 # takes the contents of the template to render as well as the Hash of 86 # local assigns available to the template. The #render method ought to 87 # return the rendered template as a string. 88 def self.register_template_handler(extension, klass) 89 @@template_handlers[extension.to_sym] = klass 90 TemplateFinder.update_extension_cache_for(extension.to_s) 91 end 92 93 def self.template_handler_extensions 94 @@template_handlers.keys.map(&:to_s).sort 95 end 96 97 def self.register_default_template_handler(extension, klass) 98 register_template_handler(extension, klass) 99 @@default_template_handlers = klass 100 end 101 102 def self.handler_class_for_extension(extension) 103 (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers 104 end 105 106 register_default_template_handler :erb, TemplateHandlers::ERB 107 register_template_handler :rjs, TemplateHandlers::RJS 108 register_template_handler :builder, TemplateHandlers::Builder 109 110 # TODO: Depreciate old template extensions 111 register_template_handler :rhtml, TemplateHandlers::ERB 112 register_template_handler :rxml, TemplateHandlers::Builder 113 76 114 end 77 115 end trunk/actionpack/test/controller/custom_handler_test.rb
r8976 r8981 15 15 class CustomHandlerTest < Test::Unit::TestCase 16 16 def setup 17 ActionView:: Base.register_template_handler "foo", CustomHandler18 ActionView:: Base.register_template_handler :foo2, CustomHandler17 ActionView::Template.register_template_handler "foo", CustomHandler 18 ActionView::Template.register_template_handler :foo2, CustomHandler 19 19 @view = ActionView::Base.new 20 20 end trunk/actionpack/test/controller/layout_test.rb
r8976 r8981 41 41 end 42 42 43 ActionView:: Base::register_template_handler :mab, MabView43 ActionView::Template::register_template_handler :mab, MabView 44 44 45 45 class LayoutAutoDiscoveryTest < Test::Unit::TestCase trunk/actionpack/test/template/compiled_templates_test.rb
r8976 r8981 92 92 ts = ActionView::Template.new(v, @s, false, {}) 93 93 94 @handler_class = ActionView:: Base.handler_class_for_extension(:rhtml)94 @handler_class = ActionView::Template.handler_class_for_extension(:rhtml) 95 95 @handler = @handler_class.new(v) 96 96 trunk/actionpack/test/template/template_finder_test.rb
r8959 r8981 7 7 def setup 8 8 ActionView::TemplateFinder.process_view_paths(LOAD_PATH_ROOT) 9 ActionView:: Base::register_template_handler :mab, Class.new(ActionView::TemplateHandler)9 ActionView::Template::register_template_handler :mab, Class.new(ActionView::TemplateHandler) 10 10 @template = ActionView::Base.new 11 11 @finder = ActionView::TemplateFinder.new(@template, LOAD_PATH_ROOT) … … 36 36 def test_should_update_extension_cache_when_template_handler_is_registered 37 37 ActionView::TemplateFinder.expects(:update_extension_cache_for).with("funky") 38 ActionView:: Base::register_template_handler :funky, Class.new(ActionView::TemplateHandler)38 ActionView::Template::register_template_handler :funky, Class.new(ActionView::TemplateHandler) 39 39 end 40 40