public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Append the content_type to the given :template option for render()

With this change doing render :template => 'shared/foo' will try to 
locate
shared/foo.<content_type> first, and if that didn't return any 
results it
falls back to the old behaviour. As usual _template_location is called, 
but
in opts[:template] is given as the template context. The method signature
has been changed to fit the terminology better: an action name or 
:template
option can set the context for constructing a template location path. In 
the
latter case the controller argument is nil, to distinguish between the 
two.
fabien (author)
Thu May 01 14:54:49 -0700 2008
commit  65dc024eb6551bec259c9b971fb1a083b999e298
tree    5e7a8debdaf060ad5ddac55500bc32273dc5b288
parent  4047cd57f2ff7dfaf9ea0f88b7ff9744262fd071
...
90
91
92
93
 
94
95
96
...
99
100
101
102
 
103
104
105
...
115
116
117
118
119
 
 
120
121
122
...
90
91
92
 
93
94
95
96
...
99
100
101
 
102
103
104
105
...
115
116
117
 
 
118
119
120
121
122
0
@@ -90,7 +90,7 @@
0
   # structure for your app.
0
   #
0
   # ==== Parameters
0
- # action<~to_s>:: The controller action.
0
+ # context<~to_s>:: The controller context (the action or template name).
0
   # type<~to_s>:: The content type. Defaults to nil.
0
   # controller<~to_s>::
0
   # The name of the controller. Defaults to controller_name.
0
@@ -99,7 +99,7 @@
0
   # ==== Returns
0
   # String::
0
   # Indicating where to look for the template for the current controller,
0
- # action, and content-type.
0
+ # context, and content-type.
0
   #
0
   # ==== Notes
0
   # The type is irrelevant for controller-types that don't support
0
@@ -115,8 +115,8 @@
0
   # of controller/action.mime.type
0
   #---
0
   # @public
0
- def _template_location(action, type = nil, controller = controller_name)
0
- "#{controller}/#{action}"
0
+ def _template_location(context, type = nil, controller = controller_name)
0
+ controller ? "#{controller}/#{context}" : context
0
   end
0
 
0
   # ==== Returns
...
58
59
60
61
 
62
63
64
...
100
101
102
 
 
 
 
 
103
104
105
...
58
59
60
 
61
62
63
64
...
100
101
102
103
104
105
106
107
108
109
110
0
@@ -58,7 +58,7 @@
0
   # "team@cowboys.com",
0
   # "Exception occured at #{Time.now}",
0
   # params[:exception])
0
- # render :inline => 'Something is wrong, but the team are on it!'
0
+ # render 'Something is wrong, but the team are on it!'
0
   # end
0
   #
0
   # Note: The special param[:exception] is available in all Exception actions
0
@@ -100,6 +100,11 @@
0
       # ==== Returns
0
       # String:: The snake cased name of the error without the namespace.
0
       def name; self.class.name; end
0
+
0
+ # === Returns
0
+ # Integer:: The status-code of the error.
0
+ def status; self.class.status; end
0
+ alias :to_i :status
0
 
0
       class << self
0
 
...
128
129
130
131
 
132
133
134
135
136
 
137
138
139
...
146
147
148
149
150
 
 
151
152
153
...
128
129
130
 
131
132
133
134
135
 
136
137
138
139
...
146
147
148
 
 
149
150
151
152
153
0
@@ -128,12 +128,12 @@
0
 
0
   end # class << self
0
 
0
- # The location to look for a template for a particular controller, action,
0
+ # The location to look for a template for a particular controller, context,
0
   # and mime-type. This is overridden from AbstractController, which defines a
0
   # version of this that does not involve mime-types.
0
   #
0
   # ==== Parameters
0
- # action<~to_s>:: The name of the action that will be rendered.
0
+ # context<~to_s>:: The name of the action or template basename that will be rendered.
0
   # type<~to_s>::
0
   # The mime-type of the template that will be rendered. Defaults to nil.
0
   # controller<~to_s>::
0
@@ -146,8 +146,8 @@
0
   #
0
   #---
0
   # @public
0
- def _template_location(action, type = nil, controller = controller_name)
0
- "#{controller}/#{action}.#{type}"
0
+ def _template_location(context, type = nil, controller = controller_name)
0
+ controller ? "#{controller}/#{context}.#{type}" : "#{context}.#{type}"
0
   end
0
 
0
   # Build a new controller.
...
336
337
338
339
 
340
341
342
343
344
345
346
 
347
348
349
350
351
 
352
353
354
355
356
 
 
 
 
 
 
 
357
358
359
...
336
337
338
 
339
340
341
342
343
344
345
 
346
347
348
349
350
 
351
352
353
354
355
 
356
357
358
359
360
361
362
363
364
365
0
@@ -336,24 +336,30 @@
0
   # and template location of the first match.
0
   #
0
   # ==== Parameters
0
- # thing<Object>:: The controller action.
0
+ # context<Object>:: The controller action or template basename.
0
   # content_type<~to_s>:: The content type. Defaults to nil.
0
   # controller<~to_s>:: The name of the controller. Defaults to nil.
0
   #
0
   # ==== Options (opts)
0
   # :template<String>::
0
   # The location of the template to use. Defaults to whatever matches this
0
- # thing, content_type and controller.
0
+ # context, content_type and controller.
0
   #
0
   # ==== Returns
0
   # Array[Symbol, String]::
0
   # A pair consisting of the template method and location.
0
- def _template_for(thing, content_type, controller=nil, opts={})
0
+ def _template_for(context, content_type, controller=nil, opts={})
0
     template_method = nil
0
     template_location = nil
0
     
0
     self.class._template_roots.reverse_each do |root, template_location|
0
- template_location = root / (opts[:template] || self.send(template_location, thing, content_type, controller))
0
+ if opts[:template] # use the given template as the location context
0
+ template_location = root / self.send(template_location, opts[:template], content_type, nil)
0
+ template_method = Merb::Template.template_for(template_location)
0
+ break if template_method && self.respond_to?(template_method)
0
+ end
0
+
0
+ template_location = root / (opts[:template] || self.send(template_location, context, content_type, controller))
0
       template_method = Merb::Template.template_for(template_location)
0
       break if template_method && self.respond_to?(template_method)
0
     end
...
4
5
6
7
8
 
 
9
10
11
...
4
5
6
 
 
7
8
9
10
11
0
@@ -4,8 +4,8 @@
0
     class HelperTesting < Merb::AbstractController
0
       self._template_root = File.dirname(__FILE__) / "views"
0
       
0
- def _template_location(action, type = nil, controller = controller_name)
0
- "helpers/#{File.basename(controller)}/#{action}"
0
+ def _template_location(context, type = nil, controller = controller_name)
0
+ "helpers/#{File.basename(controller)}/#{context}"
0
       end
0
     end
0
     
...
7
8
9
10
11
 
 
12
13
14
...
7
8
9
 
 
10
11
12
13
14
0
@@ -7,8 +7,8 @@
0
     class RenderIt < Merb::AbstractController
0
       self._template_root = File.dirname(__FILE__) / "views"
0
 
0
- def _template_location(action, type = nil, controller = controller_name)
0
- "partial/#{File.basename(controller)}/#{action}"
0
+ def _template_location(context, type = nil, controller = controller_name)
0
+ "partial/#{File.basename(controller)}/#{context}"
0
       end
0
     end
0
 
...
71
72
73
74
75
 
 
76
77
78
...
87
88
89
90
91
 
 
92
93
94
...
71
72
73
 
 
74
75
76
77
78
...
87
88
89
 
 
90
91
92
93
94
0
@@ -71,8 +71,8 @@
0
     end
0
     
0
     class RenderTemplateCustomLocation < RenderTemplate
0
- def _template_location(action, type = nil, controller = controller_name)
0
- "wonderful/#{action}"
0
+ def _template_location(context, type = nil, controller = controller_name)
0
+ "wonderful/#{context}"
0
       end
0
     end
0
     
0
@@ -87,8 +87,8 @@
0
     class RenderTemplateMultipleRootsAndCustomLocation < RenderTemplate
0
       self._template_roots = [[File.dirname(__FILE__) / "alt_views", :_custom_template_location]]
0
       
0
- def _custom_template_location(action, type = nil, controller = controller_name)
0
- "#{self.class.name.split('::')[-1].to_const_path}/#{action}"
0
+ def _custom_template_location(context, type = nil, controller = controller_name)
0
+ "#{self.class.name.split('::')[-1].to_const_path}/#{context}"
0
       end
0
     end
0
     
...
12
13
14
15
16
 
 
17
18
19
...
12
13
14
 
 
15
16
17
18
19
0
@@ -12,8 +12,8 @@
0
   
0
   private
0
   
0
- def _template_location(action, type = nil, controller = controller_name)
0
- "wonderful/#{action}"
0
+ def _template_location(context, type = nil, controller = controller_name)
0
+ "wonderful/#{context}"
0
   end
0
   
0
 end

Comments

    No one has commented yet.