0
@@ -12,17 +12,6 @@ module Ardes#:nodoc:
0
# ... # will look for views in 'views/bar' and 'views/foo'
0
- # in views/foo/_my_view.rhtml:
0
- # <h1>My View Thing</h1>
0
- # in views/bar/_my_view.rhtml:
0
- # <%= render_parent %>
0
- # <p>With some bar action</p>
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
@@ -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
- extend ActiveSupport::Memoizable
0
def self.included(base)# :nodoc:
0
- alias_method_chain :render, :inherit_views
0
alias_method :_orig_pick_template, :_pick_template
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
- # 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
- 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
- raise InheritedFileNotFound, "no parent for #{@current_render[:file]} found"
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
- # 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
- 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
- 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
- # 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
+ 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
+ # 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
+ return inherited_template if inherited_template
0
- return inherited_template if inherited_template
0
+ memoize :_pick_template_from_inherit_view_paths
0
- memoize :_pick_inherited_template
0
- def _with_current_render_of(options, &block)
0
- orig, @current_render = @current_render, options
0
- @current_render = orig
0
\ No newline at end of file