diff --git a/doc/classes/InheritViews/ActMethod.html b/doc/classes/InheritViews/ActMethod.html index 52d7e66..39c87b7 100644 --- a/doc/classes/InheritViews/ActMethod.html +++ b/doc/classes/InheritViews/ActMethod.html @@ -331,7 +331,7 @@
class extension which enables specification of inherit_views +href="ActMethod.html#M000009">inherit_views
# File lib/inherit_views.rb, line 49 +# File lib/inherit_views.rb, line 49 49: def inherit_views(*paths) 50: class_eval do 51: extend PathsContainer unless respond_to?(:inherit_views_paths) diff --git a/doc/classes/InheritViews/ActionView.html b/doc/classes/InheritViews/ActionView.html index 96bd35d..a4598f7 100644 --- a/doc/classes/InheritViews/ActionView.html +++ b/doc/classes/InheritViews/ActionView.html @@ -338,6 +338,13 @@ + +render_with_parent
+ + + + + view_paths=
@@ -377,22 +384,51 @@Public Class Methods
-+# File lib/inherit_views.rb, line 128 -128: def self.included(base) -129: base.class_eval do -130: def view_paths=(value) -131: @view_paths = InheritViews::PathSet.new(value) -132: ensure -133: @view_paths.inherit_view_paths = controller.inherit_view_paths if (controller.inherit_views? rescue false) -134: end -135: end -136: end# File lib/inherit_views.rb, line 129 +129: def self.included(base) +130: base.class_eval do +131: # use InheritViews::PathSet, and give it my controller's inherit_view_paths +132: def view_paths=(value) +133: @view_paths = InheritViews::PathSet.new(value) +134: ensure +135: @view_paths.inherit_view_paths = controller.inherit_view_paths if (controller.inherit_views? rescue false) +136: end +137: +138: alias_method_chain :render, :parent +139: end +140: endPublic Instance Methods
+
+++ + + +render_with_parent + +(*args, &block) + + +
++Extension for render which enables <%= render :parent %> (works for +partials and top-level templates) +
+ ++# File lib/inherit_views.rb, line 143 +143: def render_with_parent(*args, &block) +144: if args.first == :parent +145: args.shift +146: args.first[:file] = view_paths.find_parent_template(template.to_s, template.format) +147: end +148: render_without_parent(*args, &block) +149: end
diff --git a/doc/classes/InheritViews/PathSet.html b/doc/classes/InheritViews/PathSet.html index e3f15ab..bab20cd 100644 --- a/doc/classes/InheritViews/PathSet.html +++ b/doc/classes/InheritViews/PathSet.html @@ -335,15 +335,15 @@@@ -404,13 +440,17 @@
+Public Instance Methods
+use InheritViews::PathSet, and give it my +controller‘s inherit_view_paths +
-+# File lib/inherit_views.rb, line 130 -130: def view_paths=(value) -131: @view_paths = InheritViews::PathSet.new(value) -132: ensure -133: @view_paths.inherit_view_paths = controller.inherit_view_paths if (controller.inherit_views? rescue false) -134: end# File lib/inherit_views.rb, line 132 +132: def view_paths=(value) +133: @view_paths = InheritViews::PathSet.new(value) +134: ensure +135: @view_paths.inherit_view_paths = controller.inherit_view_paths if (controller.inherit_views? rescue false) +136: endMethods
- -find_template
+ +find_parent_template
-find_template_from_inherit_view_paths
+find_template
@@ -391,58 +391,61 @@Attributes
Name Read/write? Public Instance Methods
-
+
- -- + -find_template +find_parent_template -(original_template_path, format = nil) +(template_path, format)
++given a template_path and format, returns a parent template, or raise +ActionView::MissingTemplate +
-+# File lib/inherit_views.rb, line 101 -101: def find_template(original_template_path, format = nil) -102: super -103: rescue ::ActionView::MissingTemplate => e -104: (inherit_view_paths && find_template_from_inherit_view_paths(original_template_path, format)) || raise(e) -105: end# File lib/inherit_views.rb, line 109 +109: def find_parent_template(template_path, format) +110: # first, we grab the inherit view paths that are 'above' the given template_path +111: if inherit_view_paths.present? && (starting_path = inherit_view_paths.detect {|path| template_path.starts_with?("#{path}/")}) +112: parent_paths = inherit_view_paths.slice(inherit_view_paths.index(starting_path)+1..-1) +113: # then, search through each path, substituting the inherit view path, returning the first found +114: parent_paths.each do |path| +115: begin +116: return orig_find_template(template_path.sub(/^#{starting_path}/, path), format) +117: rescue ::ActionView::MissingTemplate +118: next +119: end +120: end +121: end +122: raise ::ActionView::MissingTemplate.new(self, template_path, format) +123: endProtected Instance Methods
- -
diff --git a/doc/created.rid b/doc/created.rid index 766efb3..c5840c0 100644 --- a/doc/created.rid +++ b/doc/created.rid @@ -1 +1 @@ -Sun, 08 Feb 2009 11:39:20 +0000 +Mon, 09 Feb 2009 13:08:12 +0000 diff --git a/doc/files/README_rdoc.html b/doc/files/README_rdoc.html index 9fc7f9a..b0adb26 100644 --- a/doc/files/README_rdoc.html +++ b/doc/files/README_rdoc.html @@ -377,6 +377,31 @@-find_template_from_inherit_view_paths +find_template -(template_path, format) +(original_template_path, format = nil)
++look for a parent template if a standard one can‘t be found +
-+# File lib/inherit_views.rb, line 108 -108: def find_template_from_inherit_view_paths(template_path, format) -109: # first, we grab the inherit view paths that are 'above' the given template_path -110: if starting_path = inherit_view_paths.detect {|path| template_path.starts_with?("#{path}/")} -111: paths_above_template_path = inherit_view_paths.slice(inherit_view_paths.index(starting_path)+1..-1) -112: # then, search through each path, substituting the inherit view path, returning the first found -113: paths_above_template_path.each do |path| -114: begin -115: return orig_find_template(template_path.sub(/^#{starting_path}/, path), format) -116: rescue ::ActionView::MissingTemplate -117: next -118: end -119: end -120: end -121: nil -122: end# File lib/inherit_views.rb, line 102 +102: def find_template(original_template_path, format = nil) +103: super +104: rescue ::ActionView::MissingTemplate +105: find_parent_template(original_template_path, format) +106: endwhat does it do?
ActionController::Base for rails 2.0. Rather, within these view paths, you can inherit views from other controller paths. +In templates
++You can render the ‘parent’ template from within a template if +you so choose. This works for partials and top-level templates alike. +
++foo/view.html.erb +
++ <h1>Foo View</h1> +++bar/view.html.erb +
++ <%= render :parent %> + <h2>With some 'bar' action</h2> +++rendering bar/view (with the controller setup described above): +
++ <h1>Foo View</h1> + <h2>With some 'bar' action</h2> +Development mode
Because of recent changes in the way 2.3 finds templates, using diff --git a/doc/fr_method_index.html b/doc/fr_method_index.html index 468b1b2..9c84d69 100644 --- a/doc/fr_method_index.html +++ b/doc/fr_method_index.html @@ -1,11 +1,12 @@ extended (InheritViews::PathsContainer)
-find_template (InheritViews::PathSet)
-find_template_from_inherit_view_paths (InheritViews::PathSet)
+find_parent_template (InheritViews::PathSet)
+find_template (InheritViews::PathSet)
included (InheritViews::ActionView)
inherit_view_paths (InheritViews::PathsContainer)
inherit_view_paths= (InheritViews::PathsContainer)
-inherit_views (InheritViews::ActMethod)
+inherit_views (InheritViews::ActMethod)
inherit_views= (InheritViews::PathsContainer)
inherit_views? (InheritViews::PathsContainer)
+render_with_parent (InheritViews::ActionView)
view_paths= (InheritViews::ActionView)
\ No newline at end of file