0
@@ -66,9 +66,9 @@ module Ardes#:nodoc:
0
# or the current controller's default path if no argument is given
0
def inherit_views(*paths)
0
- unless
included_modules.include? ::Ardes::InheritViews::ActionController::InstanceMethods0
+ unless
respond_to?(:inherit_views?)0
-
include InstanceMethods0
+
delegate :inherit_views?, :inherit_view_paths, :to => 'self.class'0
self.inherit_views = true
0
self.inherit_view_paths = paths if paths.size > 0
0
@@ -101,35 +101,16 @@ module Ardes#:nodoc:
0
instance_variable_set('@inherit_view_paths', [controller_path] + ((paths - [controller_path]) + inherited))
0
- module InstanceMethods
0
- # Return true if the controller is inheriting views
0
- self.class.inherit_views?
0
- # Return the inherit view paths, in order of self to ancestor
0
- def inherit_view_paths
0
- self.class.inherit_view_paths
0
# Mixin for ActionView to enable inherit views functionality. This module is
0
# included into ActionView::Base
0
- # Those familiar with the internals of ActionView will know that the <tt>@first_render</tt>
0
- # instance var is used to keep track of what is the 'root' template being rendered. A similar
0
- # variable <tt>@current_render</tt> is introduced to keep track of the filename of the currently rendered
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
alias_method :_orig_pick_template, :_pick_template
0
def _pick_template(template_path)
0
@@ -165,18 +146,18 @@ module Ardes#:nodoc:
0
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
+ 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
- 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
+ # 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
- inherit_paths_above_starting_path.each do |path|
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