0
@@ -124,6 +124,8 @@ module Ardes#:nodoc:
0
# file. This enables +render_parent+ to know which to file render.
0
+ extend ActiveSupport::Memoizable
0
def self.included(base)# :nodoc:
0
alias_method_chain :render, :inherit_views
0
@@ -131,7 +133,7 @@ module Ardes#:nodoc:
0
alias_method :_orig_pick_template, :_pick_template
0
def _pick_template(template_path)
0
- _
orig_pick_template(template_path)
0
+ _
pick_inherited_template_for_controller(template_path, controller)
0
@@ -139,16 +141,12 @@ module Ardes#:nodoc:
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[:file] && (file = _pick_template(@current_render[:file], include_self = false))
0
- # return render(options.merge(:file => file))
0
- # elsif @current_render[:partial] && (partial = _pick_template(_pick_partial_template(@current_render[:partial]), include_self = false))
0
- # return render(options.merge(:partial => partial))
0
- #raise InheritedFileNotFound, "no parent for #{@current_render.inspect} found"
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
@@ -160,10 +158,37 @@ module Ardes#:nodoc:
0
# Find an inherited template path for a controller context
0
def inherited_template_path(template_path, controller_class = controller.class)
0
-
#_pick_template(template_path, true, controller_class.inherit_view_paths)0
+
_pick_inherited_template_for_controller(template_path, controller).to_s0
+ def _pick_inherited_template_for_controller(template_path, controller)
0
+ _orig_pick_template(template_path)
0
+ rescue ::ActionView::MissingTemplate
0
+ if (controller.inherit_views? rescue false)
0
+ _pick_inherited_template(template_path, controller.inherit_view_paths)
0
+ def _pick_inherited_template(template_path, inherit_view_paths)
0
+ starting_path = inherit_view_paths.detect {|p| template_path =~ /^#{p}\//}
0
+ inherit_paths_above_starting_path = inherit_view_paths.slice(inherit_view_paths.index(starting_path)+1..-1)
0
+ inherit_paths_above_starting_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
+ memoize :_pick_inherited_template
0
def _with_current_render_of(options, &block)
0
orig, @current_render = @current_render, options