2010-03-08 10:50:10 -05:00
|
|
|
module AbstractController
|
|
|
|
module ViewPaths
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
class_attribute :_view_paths
|
|
|
|
self._view_paths = ActionView::PathSet.new
|
2010-06-10 13:39:09 -04:00
|
|
|
self._view_paths.freeze
|
2010-03-08 10:50:10 -05:00
|
|
|
end
|
|
|
|
|
2010-03-12 08:25:10 -05:00
|
|
|
delegate :find_template, :template_exists?, :view_paths, :formats, :formats=,
|
2010-03-10 16:11:48 -05:00
|
|
|
:locale, :locale=, :to => :lookup_context
|
2010-03-08 10:50:10 -05:00
|
|
|
|
2011-05-04 05:26:02 -04:00
|
|
|
module ClassMethods
|
|
|
|
def parent_prefixes
|
|
|
|
@parent_prefixes ||= begin
|
|
|
|
parent_controller = superclass
|
|
|
|
prefixes = []
|
|
|
|
|
|
|
|
until parent_controller.abstract?
|
|
|
|
prefixes << parent_controller.controller_path
|
|
|
|
parent_controller = parent_controller.superclass
|
|
|
|
end
|
|
|
|
|
|
|
|
prefixes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# The prefixes used in render "foo" shortcuts.
|
|
|
|
def _prefixes
|
|
|
|
@_prefixes ||= begin
|
|
|
|
parent_prefixes = self.class.parent_prefixes
|
|
|
|
parent_prefixes.dup.unshift(controller_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-08 10:50:10 -05:00
|
|
|
# LookupContext is the object responsible to hold all information required to lookup
|
|
|
|
# templates, i.e. view paths and details. Check ActionView::LookupContext for more
|
|
|
|
# information.
|
|
|
|
def lookup_context
|
2011-05-06 08:32:48 -04:00
|
|
|
@_lookup_context ||=
|
2011-05-04 03:07:11 -04:00
|
|
|
ActionView::LookupContext.new(self.class._view_paths, details_for_lookup, _prefixes)
|
2010-03-08 10:50:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def details_for_lookup
|
|
|
|
{ }
|
|
|
|
end
|
|
|
|
|
|
|
|
def append_view_path(path)
|
|
|
|
lookup_context.view_paths.push(*path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def prepend_view_path(path)
|
|
|
|
lookup_context.view_paths.unshift(*path)
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
# Append a path to the list of view paths for this controller.
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
2010-08-25 12:57:27 -04:00
|
|
|
# * <tt>path</tt> - If a String is provided, it gets converted into
|
|
|
|
# the default view path. You may also provide a custom view path
|
2011-03-13 04:14:51 -04:00
|
|
|
# (see ActionView::PathSet for more information)
|
2010-03-08 10:50:10 -05:00
|
|
|
def append_view_path(path)
|
|
|
|
self.view_paths = view_paths.dup + Array(path)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Prepend a path to the list of view paths for this controller.
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
2010-08-25 12:57:27 -04:00
|
|
|
# * <tt>path</tt> - If a String is provided, it gets converted into
|
|
|
|
# the default view path. You may also provide a custom view path
|
2011-03-13 04:14:51 -04:00
|
|
|
# (see ActionView::PathSet for more information)
|
2010-03-08 10:50:10 -05:00
|
|
|
def prepend_view_path(path)
|
|
|
|
self.view_paths = Array(path) + view_paths.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
# A list of all of the default view paths for this controller.
|
|
|
|
def view_paths
|
|
|
|
_view_paths
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set the view paths.
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
2011-03-13 04:14:51 -04:00
|
|
|
# * <tt>paths</tt> - If a PathSet is provided, use that;
|
|
|
|
# otherwise, process the parameter into a PathSet.
|
2010-03-08 10:50:10 -05:00
|
|
|
def view_paths=(paths)
|
2010-06-10 13:39:09 -04:00
|
|
|
self._view_paths = ActionView::Base.process_view_paths(paths)
|
2010-03-08 10:50:10 -05:00
|
|
|
self._view_paths.freeze
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-05-03 17:41:38 -04:00
|
|
|
end
|