0
@@ -69,7 +69,6 @@ module Ardes#:nodoc:
0
unless included_modules.include? ::Ardes::InheritViews::ActionController::InstanceMethods
0
include InstanceMethods
0
- extend CachedInheritedTemplatePaths if ENV['RAILS_ENV'] == 'production'
0
self.inherit_views = true
0
self.inherit_view_paths = paths if paths.size > 0
0
@@ -77,29 +76,14 @@ module Ardes#:nodoc:
0
- def self.extended(base)
0
- # BC: Rails > 2.0.2 introduces template.finder, so we handle both cases
0
- if defined?(::ActionView::TemplateFinder)
0
- def self.file_exists_in_template?(template, path)
0
- template.finder.file_exists?(path)
0
- def self.file_exists_in_template?(template, path)
0
- template.file_exists?(path)
0
# Return true if the controller is inheriting views
0
-
!!read_inheritable_attribute('inherit_views')0
+
read_inheritable_attribute('inherit_views') ? true : false0
- # Instruct the controller that it is
not inheriting views
0
+ # Instruct the controller that it is
, or is not, inheriting views
0
def inherit_views=(bool)
0
- write_inheritable_attribute('inherit_views',
!!bool)
0
+ write_inheritable_attribute('inherit_views',
bool ? true : false)
0
# Return the inherit view paths, in order of self to ancestor
0
@@ -116,24 +100,9 @@ module Ardes#:nodoc:
0
inherited = inherit_view_paths - paths - [controller_path]
0
instance_variable_set('@inherit_view_paths', [controller_path] + ((paths - [controller_path]) + inherited))
0
- def find_inherited_template_path_in(template, template_path, include_self = true)
0
- if inherit_path = inherit_view_paths.find {|p| template_path =~ /^#{p}\//}
0
- paths = inherit_view_paths.slice(inherit_view_paths.index(inherit_path) + (include_self ? 0 : 1)..-1)
0
- if found_path = paths.find {|p| file_exists_in_template?(template, template_path.sub(/^#{inherit_path}/, p))}
0
- return template_path.sub(/^#{inherit_path}/, found_path)
0
- def self.included(base)#:nodoc:
0
- base.send :hide_action, *public_instance_methods
0
- base.send :alias_method_chain, :render_for_file, :inherit_views
0
# Return true if the controller is inheriting views
0
self.class.inherit_views?
0
@@ -143,55 +112,12 @@ module Ardes#:nodoc:
0
self.class.inherit_view_paths
0
- # intercepts render_file and looks for an inherited template_path, if appropriate
0
- def render_for_file_with_inherit_views(template_path, status = nil, use_full_path = false, locals = {})
0
- if use_full_path and inherit_views? and found_path = find_inherited_template_path(template_path)
0
- template_path = found_path
0
- render_for_file_without_inherit_views(template_path, status, use_full_path, locals)
0
- # given a template_path, returns the first existing template_path in parent inherit paths.
0
- # If +include_self+ is false, the search does not include the passed template_path
0
- # If one cannot be found, then nil is returned
0
- def find_inherited_template_path(template_path, include_self = true)
0
- self.class.find_inherited_template_path_in(@template, template_path, include_self)
0
- # This module is included into inherit_views controllers in production mode. It's purpose is
0
- # to cache the calls to find_inherited_template_path, so that the file system is not relentlessly
0
- # queried to find the inherited template_path.
0
- module CachedInheritedTemplatePaths
0
- def self.extended(base)#:nodoc:
0
- alias_method_chain :find_inherited_template_path_in, :cache
0
- def inherited_template_paths_cache
0
- instance_variable_get('@inherited_template_paths_cache') || instance_variable_set('@inherited_template_paths_cache', {})
0
- def find_inherited_template_path_in_with_cache(template, template_path, include_self = true)
0
- inherited_template_paths_cache[[template_path, include_self]] ||= find_inherited_template_path_in_without_cache(template, template_path, include_self)
0
# Mixin for ActionView to enable inherit views functionality. This module is
0
# included into ActionView::Base
0
- # +render_file+ is modified so that it picks an inherited file to render
0
- # +render_partial+ likewise
0
- # +render_parent+ is introduced
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
@@ -199,51 +125,47 @@ module Ardes#:nodoc:
0
def self.included(base)# :nodoc:
0
- base.send :alias_method_chain, :render_file, :inherit_views
0
- base.send :alias_method_chain, :render_partial, :inherit_views
0
+ alias_method_chain :render, :inherit_views
0
+ alias_method :_orig_pick_template, :_pick_template
0
+ def _pick_template(template_path)
0
+ _orig_pick_template(template_path)
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 template_path = controller.find_inherited_template_path(@current_render, include_self = false)
0
- render(options.merge(:file => template_path, :use_full_path => true))
0
- raise InheritedFileNotFound, "no parent for #{@current_render} found"
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
# Find an inherited template path prior to rendering, if appropriate.
0
- def render_file_with_inherit_views(template_path, use_full_path = true, local_assigns = {})
0
- if use_full_path && (controller.inherit_views? rescue false) && found_path = controller.find_inherited_template_path(template_path)
0
- template_path = found_path
0
- with_current_render_of(template_path) do
0
- render_file_without_inherit_views(template_path, use_full_path, local_assigns)
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 inherited template path for the given path, optionally pass a controller class
0
- # to find the inherited view for the passed controller class
0
- def inherited_template_path(template_path, klass = controller.class)
0
- klass.find_inherited_template_path_in(self, template_path)
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
- # looks for an inherited partial template
0
- def render_partial_with_inherit_views(partial_path, local_assigns = nil, deprecated_local_assigns = nil)
0
- if (controller.inherit_views? rescue false) && found_path = controller.find_inherited_template_path("#{controller.controller_path}/_#{partial_path}")
0
- partial_path = found_path.sub("/_#{partial_path}", "/#{partial_path}")
0
- with_current_render_of(partial_path) do
0
- render_partial_without_inherit_views(partial_path, local_assigns, deprecated_local_assigns)
0
- # sets @current_render to argument for the duration of the passed block
0
- def with_current_render_of(path, &block)
0
- orig, @current_render = @current_render, path
0
+ def _with_current_render_of(options, &block)
0
+ orig, @current_render = @current_render, options