public
Description: rails plugin that enables inheritance of views along a controller class heirachy
Homepage: http://ianwhite.github.com/inherit_views
Clone URL: git://github.com/ianwhite/inherit_views.git
Removed render_parent for now.  Vastly simplified internals.  All specs pass on 
edge
ianwhite (author)
Sat Sep 20 22:04:39 -0700 2008
commit  fef6180fa01d55a291c5d5be0b1ff85a3879101f
tree    af87d43a023b9b6e6a7a3650b66dc7e14391eaec
parent  4ab74c4f152b85c6f8093cb5ae9e89009b1ddc6a
...
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
0
@@ -1,3 +1,9 @@
0
+* Removed render_parent for now (in edge rails version)
0
+
0
+* inherit_views allows inherited templates to be rendered where there is no action method
0
+
0
+* Vastly simplified internals, making use of the _pick_template single point of entry
0
+
0
 * branched fro rails 2.0 and 2.1 in rails-2.0-2.1, edge rails follows master branch
0
 
0
 * Now using garlic for CI
...
27
28
29
30
31
32
33
34
35
...
27
28
29
 
 
 
30
31
32
0
@@ -27,9 +27,6 @@ Example:
0
   class BarController < FooController
0
     # will look for views in 'views/bar', then 'views/foo', then 'view/application'
0
   end
0
-
0
-You can also render the parent view in your views with
0
-  <%= render_parent %>
0
   
0
 See Ardes::InheritViews for more details
0
 
...
9
10
11
12
13
14
15
16
...
23
24
25
26
27
28
29
 
30
31
32
...
40
41
42
43
44
45
 
46
47
48
...
55
56
57
58
59
60
61
 
62
63
64
65
66
67
68
69
70
71
 
...
9
10
11
 
 
12
13
14
...
21
22
23
 
 
24
25
26
27
28
29
...
37
38
39
 
40
41
42
43
44
45
...
52
53
54
 
 
 
 
55
56
 
 
 
 
 
 
 
 
 
57
0
@@ -9,8 +9,6 @@ AController < TestController; inherit_views (an instance)
0
 - GET :in_abc should render a/in_abc
0
 - GET :in_a should render a/in_a
0
 - GET :in_ab should render a/in_ab
0
-- GET :render_parent should render a/render_parent
0
-- GET :inherited_template_path should render its contents
0
 
0
 BController < TestController; inherit_views 'a' (the class)
0
 - should be inherit views
0
@@ -23,10 +21,9 @@ BController < TestController; inherit_views 'a' (an instance)
0
 - GET :in_ab should render b/in_ab
0
 - GET :in_b should render b/in_b
0
 - GET :in_abc should render b/in_abc
0
-- GET :render_parent should render a/render_parent inside b/render_parent
0
-- GET :bad_render_parent should raise ActionView::TemplateError as there is no parent to render
0
 - GET :partial_in_bc should render b/partial_in_bc & b/_partial_in_bc
0
 - GET :partial_in_b should render b/partial_in_b & b/_partial_in_b
0
+- GET :collection_in_bc should render b/collection_in_bc then b/_partial_in_bc
0
 
0
 CController < BController (the class)
0
 - should be inherit views
0
@@ -40,9 +37,9 @@ CController < BController (an instance)
0
 - GET :in_b should render b/in_b
0
 - GET :in_abc should render c/in_abc
0
 - GET :in_c should render c/in_c
0
-- GET :render_parent should render a/render_parent inside b/render_parent inside c/render_parent
0
 - GET :partial_in_bc should render b/partial_in_bc then c/_partial_in_bc
0
 - GET :partial_in_b should render b/partial_in_b & b/_partial_in_b
0
+- GET :collection_in_bc should render b/collection_in_bc then c/_partial_in_bc
0
 
0
 DController < AController; inherit_views 'other' (the class)
0
 - should be inherit views
0
@@ -55,17 +52,6 @@ DController < AController; inherit_views 'other' (an instance)
0
 NormalController
0
 - GET :partial_from_c should render normal/partial_from_c, then c/_partial_in_bc
0
 
0
-InheritViews controllers in production mode
0
-- should have inherited_template_paths_cache
0
-- should cache calls to find_inherited_template_path
0
-- should maintain different caches in different classes
0
+Finished in 0.348816 seconds
0
 
0
-NoTemplateFinderController
0
-- .file_exists_in_template? should call template.file_exists?
0
-
0
-WithTemplateFinderController
0
-- .file_exists_in_template? should call template.finder.file_exists?
0
-
0
-Finished in 0.296507 seconds
0
-
0
-43 examples, 0 failures
0
+35 examples, 0 failures
...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
107
108
109
110
111
112
113
114
115
116
117
118
 
 
 
 
 
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
167
168
169
 
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
12
13
14
 
 
 
 
 
 
 
 
 
 
 
15
16
17
...
96
97
98
 
 
99
100
 
101
102
103
 
104
105
106
107
108
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
 
 
 
 
 
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
 
 
126
127
128
129
 
 
 
 
 
 
 
 
130
131
132
133
0
@@ -12,17 +12,6 @@ module Ardes#:nodoc:
0
   #     ... # will look for views in 'views/bar' and 'views/foo' 
0
   #   end
0
   #
0
-  # in views/foo/_my_view.rhtml:
0
-  #
0
-  #   <h1>My View Thing</h1>
0
-  #
0
-  # in views/bar/_my_view.rhtml:
0
-  #
0
-  #   <%= render_parent %>
0
-  #   <p>With some bar action</p>
0
-  # 
0
-  # === In Controllers
0
-  #
0
   # In the example above, If BarController, or any of the views in views/bar, renders 'bar/view'
0
   # and it is not found then 'foo/view' is rendered (if it can be found)
0
   #
0
@@ -107,76 +96,37 @@ module Ardes#:nodoc:
0
     # Mixin for ActionView to enable inherit views functionality.  This module is
0
     # included into ActionView::Base
0
     module ActionView
0
-      extend ActiveSupport::Memoizable
0
-      
0
       def self.included(base)# :nodoc:
0
         base.class_eval do
0
-          alias_method_chain :render, :inherit_views
0
           alias_method :_orig_pick_template, :_pick_template
0
           
0
           def _pick_template(template_path)
0
-            _pick_inherited_template_for_controller(template_path, controller)
0
+            _orig_pick_template(template_path)
0
+          rescue ::ActionView::MissingTemplate
0
+            if controller.respond_to?(:inherit_views?) && controller.inherit_views?
0
+              _pick_template_from_inherit_view_paths(template_path, controller.inherit_view_paths)
0
+            end
0
           end
0
-        end
0
-      end
0
-      
0
-      # Renders the parent template for the current template
0
-      # takes normal rendering options (:layout, :locals, etc)
0
-      def render_parent(options = {})
0
-        raise ArgumentError, 'render_parent requires that controller inherit_views' unless (controller.inherit_views? rescue false)
0
-        
0
-        if @current_render && @current_render[:file] && (file = _pick_inherited_template(@current_render[:file], controller.inherit_view_paths))
0
-          return render(options.merge(:file => file))
0
-        end
0
-        raise InheritedFileNotFound, "no parent for #{@current_render[:file]} found"
0
-      end
0
-
0
-      # Find an inherited template path prior to rendering, if appropriate.
0
-      def render_with_inherit_views(options = {}, local_assigns = {}, &block)
0
-        _with_current_render_of(options.slice(:file, :partial)) do
0
-          render_without_inherit_views(options, local_assigns, &block)
0
-        end
0
-      end
0
-    
0
-      # Find an inherited template path for a controller context
0
-      def inherited_template_path(template_path, controller_class = controller.class)
0
-        _pick_inherited_template_for_controller(template_path, controller).to_s
0
-      end
0
-    
0
-    private
0
-      def _pick_inherited_template_for_controller(template_path, controller)
0
-        _orig_pick_template(template_path)
0
-      rescue ::ActionView::MissingTemplate
0
-        if controller.respond_to?(:inherit_views?) && controller.inherit_views?
0
-          _pick_inherited_template(template_path, controller.inherit_view_paths)
0
-        end
0
-      end  
0
-      
0
-      def _pick_inherited_template(template_path, inherit_view_paths)
0
-        # first, we grab the inherited paths that are 'above' the given template_path
0
-        if starting_path = inherit_view_paths.detect {|path| template_path =~ /^#{path}\//}
0
-          paths_above_template_path = inherit_view_paths.slice(inherit_view_paths.index(starting_path)+1..-1)
0
           
0
-          # then, search through each one, substibuting the inherited path
0
-          paths_above_template_path.each do |path|
0
-            inherited_template = begin
0
-              _orig_pick_template(template_path.sub(/^#{starting_path}/, path))
0
-            rescue ::ActionView::MissingTemplate
0
-              nil
0
+          def _pick_template_from_inherit_view_paths(template_path, inherit_view_paths)
0
+            # first, we grab the inherited paths that are 'above' the given template_path
0
+            if starting_path = inherit_view_paths.detect {|path| template_path =~ /^#{path}\//}
0
+              paths_above_template_path = inherit_view_paths.slice(inherit_view_paths.index(starting_path)+1..-1)
0
+    
0
+              # then, search through each path, substibuting the inherited path, returning the first found
0
+              paths_above_template_path.each do |path|
0
+                inherited_template = begin
0
+                  _orig_pick_template(template_path.sub(/^#{starting_path}/, path))
0
+                rescue ::ActionView::MissingTemplate
0
+                  nil
0
+                end
0
+                return inherited_template if inherited_template
0
+              end
0
             end
0
-            
0
-            return inherited_template if inherited_template
0
           end
0
+          memoize :_pick_template_from_inherit_view_paths
0
         end
0
       end
0
-      memoize :_pick_inherited_template
0
-      
0
-      def _with_current_render_of(options, &block)
0
-        orig, @current_render = @current_render, options
0
-        yield
0
-      ensure
0
-        @current_render = orig
0
-      end
0
     end
0
   end  
0
 end
0
\ No newline at end of file
...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
33
34
35
 
 
 
 
 
 
 
 
 
 
36
37
38
0
@@ -33,15 +33,5 @@ describe AController, " < TestController; inherit_views" do
0
       get :in_ab
0
       response.body.should == 'a:in_ab'
0
     end
0
-  
0
-    it "GET :render_parent should render a/render_parent" do
0
-      get :render_parent
0
-      response.body.should == 'a:render_parent'
0
-    end
0
-  
0
-    it "GET :inherited_template_path should render its contents" do
0
-      get :inherited_template_path
0
-      response.body.should == 'b/in_ab.html.erb'
0
-    end
0
   end
0
 end
0
\ No newline at end of file
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
...
62
63
64
65
66
67
68
69
70
71
72
...
38
39
40
 
 
 
 
 
 
 
 
 
41
42
43
...
53
54
55
 
 
 
 
 
56
57
58
0
@@ -38,15 +38,6 @@ describe BController, " < TestController; inherit_views 'a'" do
0
       get :in_abc
0
       response.body.should == 'b:in_abc'
0
     end
0
-
0
-    it "GET :render_parent should render a/render_parent inside b/render_parent" do
0
-      get :render_parent
0
-      response.body.should == "b:render_parent(a:render_parent)"
0
-    end
0
-  
0
-    it "GET :bad_render_parent should raise ActionView::TemplateError as there is no parent to render" do
0
-      lambda { get :bad_render_parent }.should raise_error(ActionView::TemplateError, "no parent for b/bad_render_parent found")
0
-    end
0
   
0
     it "GET :partial_in_bc should render b/partial_in_bc & b/_partial_in_bc" do
0
       get :partial_in_bc
0
@@ -62,10 +53,5 @@ describe BController, " < TestController; inherit_views 'a'" do
0
       get :collection_in_bc
0
       response.body.should == 'b:collection_in_bc => b:_partial_in_bc'
0
     end
0
-    
0
-    it "GET :partial_render_parent should render b/partial_render_parent & b/_partial_render_parent & a/_partial_render_parent" do
0
-      get :partial_render_parent
0
-      response.body.should == 'b:partial_render_parent => b:_partial_render_parent(a:_partial_render_parent)'
0
-    end
0
   end
0
 end
0
\ No newline at end of file
...
43
44
45
46
47
48
49
50
51
52
53
54
55
...
65
66
67
68
69
70
71
72
73
74
75
...
43
44
45
 
 
 
 
 
 
 
46
47
48
...
58
59
60
 
 
 
 
 
61
62
63
0
@@ -43,13 +43,6 @@ describe CController, " < BController" do
0
       get :in_c
0
       response.body.should == 'c:in_c'
0
     end
0
-
0
-    it "GET :render_parent should render a/render_parent inside b/render_parent inside c/render_parent" do
0
-      pending do
0
-        get :render_parent
0
-        response.body.should == "c:render_parent(b:render_parent(a:render_parent))"
0
-      end
0
-    end
0
   
0
     it "GET :partial_in_bc should render b/partial_in_bc then c/_partial_in_bc" do
0
       get :partial_in_bc
0
@@ -65,10 +58,5 @@ describe CController, " < BController" do
0
       get :collection_in_bc
0
       response.body.should == 'b:collection_in_bc => c:_partial_in_bc'
0
     end
0
-    
0
-    it "GET :partial_render_parent should render b/partial_render_parent & c/_partial_render_parent & b/_partial_render_parent & a/_partial_render_parent" do
0
-      get :partial_render_parent
0
-      response.body.should == 'b:partial_render_parent => c:_partial_render_parent(b:_partial_render_parent(a:_partial_render_parent))'
0
-    end
0
   end
0
 end
0
\ No newline at end of file

Comments