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
inherit_views no longer requires the exitsnce of an action method (ie. it will 
render inherited templates if they exist, when there is no action defined)
ianwhite (author)
Sat Sep 20 21:10:13 -0700 2008
commit  4ab74c4f152b85c6f8093cb5ae9e89009b1ddc6a
tree    d978804feb60c1a6de14c47d2fe49b87d5d58bc2
parent  19e89116da925afdddeb8383dca53a2de932d471
...
95
96
97
98
99
100
101
 
 
 
 
 
102
103
104
...
95
96
97
 
 
 
 
98
99
100
101
102
103
104
105
0
@@ -95,10 +95,11 @@ module Ardes#:nodoc:
0
 
0
         # Set the inherit view paths, in order of self to ancestor.
0
         #
0
-        # The controller_path for self is always prepended to the front, no matter what the arguments
0
-        def inherit_view_paths=(paths)
0
-          inherited = inherit_view_paths - paths - [controller_path]
0
-          instance_variable_set('@inherit_view_paths', [controller_path] + ((paths - [controller_path]) + inherited))
0
+        # The controller_path for self is always prepended to the front, no matter what the arguments.
0
+        def inherit_view_paths=(new_paths)
0
+          new_paths -= [controller_path]
0
+          old_paths = inherit_view_paths - [controller_path] - new_paths
0
+          instance_variable_set('@inherit_view_paths', [controller_path] + new_paths + old_paths)
0
         end
0
       end
0
     end
...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
6
7
8
 
 
 
 
 
 
9
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
15
16
17
18
 
 
 
19
20
21
...
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
0
@@ -6,35 +6,16 @@ end
0
 # its subclasses will inherit its views
0
 class AController < InheritViewsTestController
0
   inherit_views
0
-
0
-  def in_a; end
0
-  def in_ab; end
0
-  def in_abc; end
0
-  def render_parent; end
0
-  def inherited_template_path; end
0
 end
0
 
0
 # :b controller is a normal controller with inherit_views 'a'
0
 # It will inherit a's views, and its sublcasses will inherit its views ('b', then 'a')
0
 class BController < InheritViewsTestController
0
   inherit_views 'a'
0
-
0
-  def in_a; end
0
-  def in_ab; end
0
-  def in_b; end
0
-  def in_abc; end
0
-  def render_parent; end
0
-  def bad_render_parent; end
0
-  def partial_in_bc; end
0
-  def partial_in_b; end
0
-  def collection_in_bc; end
0
 end
0
 
0
 # :c cotroller is a subclass of :b controller, so it inheirt's b's views ('c', 'b', then 'a')
0
 class CController < BController
0
-
0
-  def in_c; end
0
-  def render_parent; end
0
 end
0
 
0
 # :d controller is a subclass of :a controller, with inherit_views 'other', so its views == ('d', 'other', then 'a')
0
@@ -44,45 +25,4 @@ end
0
 
0
 # used to test that inherit_views doesn't muck anything else up
0
 class NormalController < InheritViewsTestController
0
-  def partial_from_c; end
0
-end
0
-
0
-
0
-#####
0
-# These are created in production mode to test caching
0
-ENV["RAILS_ENV"] = 'production'
0
-
0
-class ProductionModeController < InheritViewsTestController
0
-  inherit_views
0
-end
0
-
0
-class OtherProductionModeController < ProductionModeController
0
-end
0
-
0
-# back to test mode
0
-ENV['RAILS_ENV'] = 'test'
0
-#####
0
-
0
-
0
-#####
0
-# BC: This is created without ActionView::TemplateFinder existing
0
-orig_template_finder = (ActionView::TemplateFinder rescue nil)
0
-orig_template_finder && ActionView.send(:remove_const, :TemplateFinder)
0
-
0
-class NoTemplateFinderController < InheritViewsTestController
0
-  inherit_views
0
-end
0
-
0
-# And this with a TemplateFinder
0
-ActionView::TemplateFinder = :defined
0
-
0
-class WithTemplateFinderController < InheritViewsTestController
0
-  inherit_views
0
-end
0
-
0
-# revert back to whatever ActionView::TemplateFinder is
0
-if orig_template_finder
0
-  ActionView.send :remove_const, :TemplateFinder
0
-  ActionView::TemplateFinder = orig_template_finder
0
 end
0
-#####
0
\ No newline at end of file
...
45
46
47
48
49
50
 
51
52
53
...
64
65
66
 
 
 
 
 
67
68
69
...
45
46
47
 
 
 
48
49
50
51
...
62
63
64
65
66
67
68
69
70
71
72
0
@@ -45,9 +45,7 @@ describe BController, " < TestController; inherit_views 'a'" do
0
     end
0
   
0
     it "GET :bad_render_parent should raise ActionView::TemplateError as there is no parent to render" do
0
-      pending do
0
-        lambda { get :bad_render_parent }.should raise_error(ActionView::TemplateError, "no parent for b/bad_render_parent found")
0
-      end
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
@@ -64,5 +62,10 @@ 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
...
65
66
67
 
 
 
 
 
68
69
70
...
65
66
67
68
69
70
71
72
73
74
75
0
@@ -65,5 +65,10 @@ 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