<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>spec/ramaze/controller/view/bar.xhtml</filename>
    </added>
    <added>
      <filename>spec/ramaze/controller/view/base/another.xhtml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -218,9 +218,15 @@ module Ramaze
           end
           trait &quot;#{this}_template&quot; =&gt; info
         else
-          controller, action, *ignored = argv
-          controller, action = self, controller unless action
-          trait &quot;#{this}_template&quot; =&gt; {:controller =&gt; controller, :action =&gt; action}
+          # Only explicitly set the controller to use, if it was explicitly given.
+          # This helps ensure that template mappings still work in subclasses
+          # of this controller.
+          first, second, *ignored = argv
+          if second
+            trait &quot;#{this}_template&quot; =&gt; {:controller =&gt; first, :action =&gt; second}
+          else
+            trait &quot;#{this}_template&quot; =&gt; {:action =&gt; first}
+          end
         end
       end
 </diff>
      <filename>lib/ramaze/controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -104,10 +104,13 @@ module Ramaze
 
       def resolve_action(path, *parameter)
         path, parameter = path.to_s, parameter.map{|e| e.to_s}
-        if info = trait[&quot;#{path}_template&quot;]
+        # Use ancestral_trait so if template is set in superclass, it is still found.
+        if info = ancestral_trait[&quot;#{path}_template&quot;]
           template = info[:file]
           unless template
             controller, action = info.values_at :controller, :action
+            # Controller may not have been explicitly set, in which case use self.
+            controller ||= self
             template = controller.resolve_template(action)
           end
         end</diff>
      <filename>lib/ramaze/controller/resolve.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,9 @@
 require 'spec/helper'
 
 class BaseController &lt; Ramaze::Controller
+  template :foo, :bar
+  template :one, self, :another
+
   def test() 'test' end
 end
 
@@ -18,4 +21,16 @@ describe 'Controller' do
   it 'should allow sub-classing MainController' do
     get('/test').body.should == 'test'
   end
+
+  it 'should respect template mappings set in superclass, with no explicit controller' do
+    # The template file it should use is view/bar.xhtml, as the template mapping doesn't
+    # specify a controller, so it will be implicitly relative to MainController.
+    get('/foo').body.should == 'bar'
+  end
+
+  it 'should respect template mappings set in superclass, with an explicit controller' do
+    # Note that the template file it should use is view/base/another.xhtml, because
+    # BaseController explicitly specifies the template mapping in relation to self.
+    get('/one').body.should == 'another'
+  end
 end</diff>
      <filename>spec/ramaze/controller/subclass.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>155b9a4fc0c1b3a7b0972ee59f9dc47d8ed0915d</id>
    </parent>
  </parents>
  <author>
    <name>Sam Carr</name>
    <email>samcarr@gmail.com</email>
  </author>
  <url>http://github.com/manveru/ramaze/commit/8ebf919d6042009df8617479d0388b6142dcf092</url>
  <id>8ebf919d6042009df8617479d0388b6142dcf092</id>
  <committed-date>2008-07-21T04:52:54-07:00</committed-date>
  <authored-date>2008-07-21T02:23:30-07:00</authored-date>
  <message>Allow controller subclasses to pick up template mappings defined in superclasses.

I noticed that if I define a template mapping with the template method, subclasses of the defining controller do not respect that mapping. This only really applies to the template :foo, :bar usage, where no explicit controller is specified. With these modifications, template mappings such as that will assume you mean the 'current' controller. Specs have been added to test this new functionality.</message>
  <tree>315f2e878caed5589d48ebcc8a521388cc5a2811</tree>
  <committer>
    <name>Michael Fellinger</name>
    <email>m.fellinger@gmail.com</email>
  </committer>
</commit>
