aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-02-04 20:47:05 +0000
committerRick Olson <technoweenie@gmail.com>2007-02-04 20:47:05 +0000
commit69b0e5c44a05fddcac996c7aaaca61cb3188da5e (patch)
tree4e5da68ffe3eac5561a9101a451a2f56a701e989 /actionpack/lib/action_controller
parent8f614a80e725228c0cc0c03fd731c6cbad0ffcb7 (diff)
downloadrails-69b0e5c44a05fddcac996c7aaaca61cb3188da5e.tar.gz
rails-69b0e5c44a05fddcac996c7aaaca61cb3188da5e.tar.bz2
rails-69b0e5c44a05fddcac996c7aaaca61cb3188da5e.zip
Allow Controllers to have multiple view_paths instead of a single template_root. Closes #2754 [John Long]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6120 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller')
-rwxr-xr-xactionpack/lib/action_controller/base.rb58
-rw-r--r--actionpack/lib/action_controller/layout.rb19
2 files changed, 56 insertions, 21 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 8a3cb3eec3..62dba3bc43 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -277,11 +277,7 @@ module ActionController #:nodoc:
# Controls the default charset for all renders.
@@default_charset = "utf-8"
cattr_accessor :default_charset
-
- # Template root determines the base from which template references will be made. So a call to render("test/template")
- # will be converted to "#{template_root}/test/template.rhtml".
- class_inheritable_accessor :template_root
-
+
# The logger is used for generating information on the action run-time (including benchmarking) if available.
# Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
cattr_accessor :logger
@@ -357,7 +353,41 @@ module ActionController #:nodoc:
def hide_action(*names)
write_inheritable_attribute(:hidden_actions, hidden_actions | names.collect { |n| n.to_s })
end
-
+
+ # Deprecated. Use view_paths instead.
+ def template_root=(path)
+ view_paths.unshift(path)
+ end
+ deprecate :template_root= => :view_paths
+
+ # Deprecated. Use view_paths instead.
+ def template_root
+ view_paths.first
+ end
+ deprecate :template_root => :view_paths
+
+ @@view_paths = {}
+
+ # View load paths determine the bases from which template references can be made. So a call to
+ # render("test/template") will be looked up in the view load paths array and the closest match will be
+ # returned.
+ def view_paths=(value)
+ @@view_paths[name] = value
+ end
+
+ # View load paths for controller.
+ def view_paths
+ if paths = @@view_paths[name]
+ paths
+ else
+ if superclass.respond_to?(:view_paths)
+ superclass.view_paths.dup.freeze
+ else
+ @@view_paths[name] = []
+ end
+ end
+ end
+
# Replace sensitive paramater data from the request log.
# Filters paramaters that have any of the arguments as a substring.
# Looks in all subhashes of the param hash for keys to filter.
@@ -534,10 +564,15 @@ module ActionController #:nodoc:
def controller_path
self.class.controller_path
end
-
+
def session_enabled?
request.session_options[:disabled] != false
end
+
+ # View load paths for controller.
+ def view_paths
+ self.class.view_paths
+ end
protected
# Renders the content that will be returned to the browser as the response body.
@@ -1030,14 +1065,10 @@ module ActionController #:nodoc:
end
end
- def self.view_root
- @view_root ||= template_root
- end
-
def initialize_template_class(response)
raise "You must assign a template class through ActionController.template_class= before processing a request" unless @@template_class
- response.template = self.class.view_class.new(self.class.view_root, {}, self)
+ response.template = self.class.view_class.new(view_paths, {}, self)
response.redirected_to = nil
@performed_render = @performed_redirect = false
end
@@ -1057,7 +1088,6 @@ module ActionController #:nodoc:
assign_deprecated_shortcuts(request, response)
end
-
# TODO: assigns cookies headers params request response template
DEPRECATED_INSTANCE_VARIABLES = %w(cookies flash headers params request response session)
@@ -1151,7 +1181,7 @@ module ActionController #:nodoc:
end
def add_class_variables_to_assigns
- %w(template_root logger template_class ignore_missing_templates).each do |cvar|
+ %w(view_paths logger template_class ignore_missing_templates).each do |cvar|
@assigns[cvar] = self.send(cvar)
end
end
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index 82c7180a52..6eaf8bb31f 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -179,16 +179,18 @@ module ActionController #:nodoc:
def default_layout #:nodoc:
@default_layout ||= read_inheritable_attribute("layout")
end
-
+
+ def layout_list #:nodoc:
+ view_paths.collect do |path|
+ Dir["#{path}/layouts/**/*"]
+ end.flatten
+ end
+
private
def inherited_with_layout(child)
inherited_without_layout(child)
layout_match = child.name.underscore.sub(/_controller$/, '').sub(/^controllers\//, '')
- child.layout(layout_match) unless layout_list.grep(%r{layouts/#{layout_match}\.[a-z][0-9a-z]*$}).empty?
- end
-
- def layout_list
- Dir.glob("#{template_root}/layouts/**/*")
+ child.layout(layout_match) unless child.layout_list.grep(%r{layouts/#{layout_match}\.[a-z][0-9a-z]*$}).empty?
end
def add_layout_conditions(conditions)
@@ -305,7 +307,10 @@ module ActionController #:nodoc:
# Does a layout directory for this class exist?
# we cache this info in a class level hash
def layout_directory?(layout_name)
- template_path = File.join(self.class.view_root, 'layouts', layout_name)
+ view_paths.find do |path|
+ File.file?(File.join(path, 'layouts', layout_name))
+ end
+ template_path ||= File.join(view_paths.first, 'layouts', layout_name)
dirname = File.dirname(template_path)
self.class.send(:layout_directory_exists_cache)[dirname]
end