public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
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
lifo (author)
Tue Mar 04 18:03:24 -0800 2008
commit  a96272a0c59b75a6838936af1eb7568b6136945a
tree    12b69a7d678e513f0a43037dfe3f407906fb8415
parent  89ee5d63d039af6770014a3bfdc4a743be9a429c
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Moved template handlers related code from ActionView::Base to ActionView::Template. [Pratik]
0
+
0
 * Tests for div_for and content_tag_for helpers. Closes #11223 [thechrisoshow]
0
 
0
 * Allow file uploads in Integration Tests. Closes #11091 [RubyRedRick]
...
5
6
7
8
9
 
10
11
12
...
5
6
7
 
 
8
9
10
11
0
@@ -5,8 +5,7 @@ require 'action_controller/routing'
0
 require 'action_controller/resources'
0
 require 'action_controller/url_rewriter'
0
 require 'action_controller/status_codes'
0
-require 'action_view/template'
0
-require 'action_view/template_finder'
0
+require 'action_view'
0
 require 'drb'
0
 require 'set'
0
 
...
183
184
185
186
187
188
189
190
...
201
202
203
204
205
206
207
208
209
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
...
183
184
185
 
 
186
187
188
...
199
200
201
 
 
 
202
203
204
...
213
214
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
217
218
0
@@ -183,8 +183,6 @@ module ActionView #:nodoc:
0
     cattr_accessor :erb_variable
0
     
0
     delegate :request_forgery_protection_token, :to => :controller
0
-
0
- @@template_handlers = HashWithIndifferentAccess.new
0
  
0
     module CompiledTemplates #:nodoc:
0
       # holds compiled template code
0
@@ -201,9 +199,6 @@ module ActionView #:nodoc:
0
     cattr_reader :computed_public_paths
0
     @@computed_public_paths = {}
0
 
0
- @@template_handlers = {}
0
- @@default_template_handlers = nil
0
-
0
     class ObjectWrapper < Struct.new(:value) #:nodoc:
0
     end
0
 
0
@@ -218,39 +213,6 @@ module ActionView #:nodoc:
0
       end
0
     end
0
 
0
- # Register a class that knows how to handle template files with the given
0
- # extension. This can be used to implement new template types.
0
- # The constructor for the class must take the ActiveView::Base instance
0
- # as a parameter, and the class must implement a #render method that
0
- # takes the contents of the template to render as well as the Hash of
0
- # local assigns available to the template. The #render method ought to
0
- # return the rendered template as a string.
0
- def self.register_template_handler(extension, klass)
0
- @@template_handlers[extension.to_sym] = klass
0
- TemplateFinder.update_extension_cache_for(extension.to_s)
0
- end
0
-
0
- def self.template_handler_extensions
0
- @@template_handlers.keys.map(&:to_s).sort
0
- end
0
-
0
- def self.register_default_template_handler(extension, klass)
0
- register_template_handler(extension, klass)
0
- @@default_template_handlers = klass
0
- end
0
-
0
- def self.handler_class_for_extension(extension)
0
- (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers
0
- end
0
-
0
- register_default_template_handler :erb, TemplateHandlers::ERB
0
- register_template_handler :rjs, TemplateHandlers::RJS
0
- register_template_handler :builder, TemplateHandlers::Builder
0
-
0
- # TODO: Depreciate old template extensions
0
- register_template_handler :rhtml, TemplateHandlers::ERB
0
- register_template_handler :rxml, TemplateHandlers::Builder
0
-
0
     def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
0
       @assigns = assigns_for_first_render
0
       @assigns_added = nil
...
32
33
34
35
 
36
37
38
...
32
33
34
 
35
36
37
38
0
@@ -32,7 +32,7 @@ module ActionView
0
       # <i>Topics listed alphabetically</i>
0
       # <% end %>
0
       def cache(name = {}, options = nil, &block)
0
- handler = Base.handler_class_for_extension(current_render_extension.to_sym)
0
+ handler = Template.handler_class_for_extension(current_render_extension.to_sym)
0
         handler.new(@controller).cache_fragment(block, name, options)
0
       end
0
     end
...
19
20
21
22
 
23
24
25
...
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
77
...
19
20
21
 
22
23
24
25
...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
0
@@ -19,7 +19,7 @@ module ActionView #:nodoc:
0
         @extension = inline_type
0
       end
0
       @locals = locals || {}
0
- @handler = @view.class.handler_class_for_extension(@extension).new(@view)
0
+ @handler = self.class.handler_class_for_extension(@extension).new(@view)
0
     end
0
     
0
     def render
0
@@ -73,5 +73,43 @@ module ActionView #:nodoc:
0
       end
0
     end
0
 
0
+ # Template Handlers
0
+
0
+ @@template_handlers = HashWithIndifferentAccess.new
0
+ @@default_template_handlers = nil
0
+
0
+ # Register a class that knows how to handle template files with the given
0
+ # extension. This can be used to implement new template types.
0
+ # The constructor for the class must take the ActiveView::Base instance
0
+ # as a parameter, and the class must implement a #render method that
0
+ # takes the contents of the template to render as well as the Hash of
0
+ # local assigns available to the template. The #render method ought to
0
+ # return the rendered template as a string.
0
+ def self.register_template_handler(extension, klass)
0
+ @@template_handlers[extension.to_sym] = klass
0
+ TemplateFinder.update_extension_cache_for(extension.to_s)
0
+ end
0
+
0
+ def self.template_handler_extensions
0
+ @@template_handlers.keys.map(&:to_s).sort
0
+ end
0
+
0
+ def self.register_default_template_handler(extension, klass)
0
+ register_template_handler(extension, klass)
0
+ @@default_template_handlers = klass
0
+ end
0
+
0
+ def self.handler_class_for_extension(extension)
0
+ (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers
0
+ end
0
+
0
+ register_default_template_handler :erb, TemplateHandlers::ERB
0
+ register_template_handler :rjs, TemplateHandlers::RJS
0
+ register_template_handler :builder, TemplateHandlers::Builder
0
+
0
+ # TODO: Depreciate old template extensions
0
+ register_template_handler :rhtml, TemplateHandlers::ERB
0
+ register_template_handler :rxml, TemplateHandlers::Builder
0
+
0
   end
0
 end
...
50
51
52
53
 
54
55
56
...
50
51
52
 
53
54
55
56
0
@@ -50,7 +50,7 @@ module ActionView #:nodoc:
0
       end
0
 
0
       def template_handler_extensions
0
- ActionView::Base.template_handler_extensions
0
+ ActionView::Template.template_handler_extensions
0
       end
0
 
0
       def reload!
...
14
15
16
17
18
 
 
19
20
21
...
14
15
16
 
 
17
18
19
20
21
0
@@ -14,8 +14,8 @@ end
0
 
0
 class CustomHandlerTest < Test::Unit::TestCase
0
   def setup
0
- ActionView::Base.register_template_handler "foo", CustomHandler
0
- ActionView::Base.register_template_handler :foo2, CustomHandler
0
+ ActionView::Template.register_template_handler "foo", CustomHandler
0
+ ActionView::Template.register_template_handler :foo2, CustomHandler
0
     @view = ActionView::Base.new
0
   end
0
 
...
40
41
42
43
 
44
45
46
...
40
41
42
 
43
44
45
46
0
@@ -40,7 +40,7 @@ class MabView < ActionView::TemplateHandler
0
   end
0
 end
0
 
0
-ActionView::Base::register_template_handler :mab, MabView
0
+ActionView::Template::register_template_handler :mab, MabView
0
 
0
 class LayoutAutoDiscoveryTest < Test::Unit::TestCase
0
   def setup
...
91
92
93
94
 
95
96
97
...
91
92
93
 
94
95
96
97
0
@@ -91,7 +91,7 @@ class CompiledTemplateTests < Test::Unit::TestCase
0
       tb = ActionView::Template.new(v, @b, false, {})
0
       ts = ActionView::Template.new(v, @s, false, {})
0
 
0
- @handler_class = ActionView::Base.handler_class_for_extension(:rhtml)
0
+ @handler_class = ActionView::Template.handler_class_for_extension(:rhtml)
0
       @handler = @handler_class.new(v)
0
 
0
       # All templates were created at t+1
...
6
7
8
9
 
10
11
12
...
35
36
37
38
 
39
40
41
...
6
7
8
 
9
10
11
12
...
35
36
37
 
38
39
40
41
0
@@ -6,7 +6,7 @@ class TemplateFinderTest < Test::Unit::TestCase
0
 
0
   def setup
0
     ActionView::TemplateFinder.process_view_paths(LOAD_PATH_ROOT)
0
- ActionView::Base::register_template_handler :mab, Class.new(ActionView::TemplateHandler)
0
+ ActionView::Template::register_template_handler :mab, Class.new(ActionView::TemplateHandler)
0
     @template = ActionView::Base.new
0
     @finder = ActionView::TemplateFinder.new(@template, LOAD_PATH_ROOT)
0
   end
0
@@ -35,7 +35,7 @@ class TemplateFinderTest < Test::Unit::TestCase
0
 
0
     def test_should_update_extension_cache_when_template_handler_is_registered
0
       ActionView::TemplateFinder.expects(:update_extension_cache_for).with("funky")
0
- ActionView::Base::register_template_handler :funky, Class.new(ActionView::TemplateHandler)
0
+ ActionView::Template::register_template_handler :funky, Class.new(ActionView::TemplateHandler)
0
     end
0
 
0
   end

Comments

    No one has commented yet.