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
Relative :template paths can be extensionless again.
fabien (author)
Fri Jul 25 07:00:17 -0700 2008
commit  8e4f82b0dfd45515df63c49e1da77938b361a720
tree    2857329b0e99e9451a7031931218c6b341ca464c
parent  1c831524de80dec7a52cf6a7fd9631685402c8b7
...
138
139
140
141
 
142
143
144
...
155
156
157
158
 
159
160
161
...
244
245
246
247
248
 
 
 
 
 
 
249
250
251
...
138
139
140
 
141
142
143
144
...
155
156
157
 
158
159
160
161
...
244
245
246
 
 
247
248
249
250
251
252
253
254
255
0
@@ -138,7 +138,7 @@ class Merb::Controller < Merb::AbstractController
0
   #---
0
   # @public
0
   def _template_location(context, type = nil, controller = controller_name)
0
- controller ? "#{controller}/#{context}.#{type}" : "#{context}.#{type}"
0
+ _conditionally_append_extension(controller ? "#{controller}/#{context}" : "#{context}", type)
0
   end
0
   
0
   # The location to look for a template and mime-type. This is overridden
0
@@ -155,7 +155,7 @@ class Merb::Controller < Merb::AbstractController
0
   #
0
   # @public
0
   def _absolute_template_location(template, type)
0
- template.match(/\.#{type.to_s.escape_regexp}$/) ? template : "#{template}.#{type}"
0
+ _conditionally_append_extension(template, type)
0
   end
0
 
0
   # Build a new controller.
0
@@ -244,8 +244,12 @@ class Merb::Controller < Merb::AbstractController
0
   
0
   private
0
 
0
- # Create a default cookie jar, and pre-set a fixation cookie
0
- # if fixation is enabled
0
+ # If not already added, add the proper mime extension to the template path.
0
+ def _conditionally_append_extension(template, type = nil)
0
+ type && !template.match(/\.#{type.to_s.escape_regexp}$/) ? "#{template}.#{type}" : template
0
+ end
0
+
0
+ # Create a default cookie jar, and pre-set a fixation cookie if fixation is enabled.
0
   def _setup_cookies
0
     ::Merb::Cookies.new(request.cookies, @headers)
0
   end
...
372
373
374
375
376
377
378
379
 
380
381
382
383
384
...
372
373
374
 
 
 
 
 
375
376
 
377
378
379
0
@@ -372,13 +372,8 @@ module Merb::RenderMixin
0
 
0
     self.class._template_roots.reverse_each do |root, template_meth|
0
       # :template => "foo/bar.html" where root / "foo/bar.html.*" exists
0
- if template && template.is_a?(String) && template.index("/")
0
- template_location = root / template
0
-
0
- # :template => :tmpl where root / "tmpl.html.*" exists
0
- elsif template
0
+ if template
0
         template_location = root / self.send(template_meth, template, content_type, nil)
0
-
0
       # :layout => "foo" where root / "layouts" / "#{controller}.html.*" exists
0
       else
0
         template_location = root / self.send(template_meth, context, content_type, controller)
...
13
14
15
16
17
 
 
18
 
19
 
 
 
20
21
22
23
24
...
13
14
15
 
 
16
17
18
19
20
21
22
23
24
 
25
26
27
0
@@ -13,12 +13,15 @@ Merb.start :environment => 'test'
0
 module Merb::Test::Behaviors
0
   include Merb::Test::RequestHelper
0
   
0
- def dispatch_should_make_body(klass, body, action = :index, opts = {})
0
- controller = Merb::Test::Fixtures::Abstract.const_get(klass).new
0
+ def dispatch_should_make_body(klass, body, action = :index, opts = {}, env = {}, &blk)
0
+ klass = Merb::Test::Fixtures::Abstract.const_get(klass)
0
     if opts.key?(:presets)
0
+ controller = klass.new
0
       opts[:presets].each { |attr, value| controller.send(attr, value)}
0
+ controller._dispatch(action.to_s)
0
+ else
0
+ controller = dispatch_to(klass, action, opts, env, &blk)
0
     end
0
- controller._dispatch(action.to_s)
0
     controller.body.should == body
0
   end
0
 end
...
63
64
65
 
 
 
 
 
 
 
 
 
66
67
68
...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0
@@ -63,6 +63,15 @@ module Merb::Test::Fixtures::Controllers
0
     def absolute_with_mime
0
       render :template => File.expand_path(self._template_root) / "merb/test/fixtures/controllers/html_default/index.html"
0
     end
0
+
0
+ def relative_without_mime
0
+ render :template => "merb/test/fixtures/controllers/html_default/index"
0
+ end
0
+
0
+ def relative_with_mime
0
+ render :template => "merb/test/fixtures/controllers/html_default/index.html"
0
+ end
0
+
0
   end
0
   
0
   class DisplayWithTemplateArgument < Display
...
35
36
37
 
 
 
 
 
 
 
 
38
39
40
...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
0
@@ -35,6 +35,14 @@ describe Merb::Controller, " displaying objects based on mime type" do
0
   it "should accept an absolute template path argument - without the mimetype extension" do
0
     dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :absolute_without_mime).body.should == "Custom: HTML: Default"
0
   end
0
+
0
+ it "should accept a relative template path argument - with the mimetype extension" do
0
+ dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :relative_with_mime).body.should == "Custom: HTML: Default"
0
+ end
0
+
0
+ it "should accept a relative template path argument - without the mimetype extension" do
0
+ dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :relative_without_mime).body.should == "Custom: HTML: Default"
0
+ end
0
 
0
   it "should accept a layout argument when calling to_*" do
0
     dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithLayout, :index, {},

Comments

    No one has commented yet.