aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/layout.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-11-28 11:18:28 -0600
committerJoshua Peek <josh@joshpeek.com>2008-11-28 11:18:28 -0600
commit9fc23745f1511d8d97433828d9ca87970994d138 (patch)
tree83b606852608845853fc5a005949812dfa5160d6 /actionpack/lib/action_controller/layout.rb
parent5fa0457542b0ff541d0a80ff8c3561eec8e35959 (diff)
downloadrails-9fc23745f1511d8d97433828d9ca87970994d138.tar.gz
rails-9fc23745f1511d8d97433828d9ca87970994d138.tar.bz2
rails-9fc23745f1511d8d97433828d9ca87970994d138.zip
Reinstate "Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache." as it killed dev mode reloading."
Diffstat (limited to 'actionpack/lib/action_controller/layout.rb')
-rw-r--r--actionpack/lib/action_controller/layout.rb38
1 files changed, 10 insertions, 28 deletions
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index 3631ce86af..54108df06d 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -175,13 +175,12 @@ module ActionController #:nodoc:
def default_layout(format) #:nodoc:
layout = read_inheritable_attribute(:layout)
return layout unless read_inheritable_attribute(:auto_layout)
- @default_layout ||= {}
- @default_layout[format] ||= default_layout_with_format(format, layout)
- @default_layout[format]
+ find_layout(layout, format)
end
- def layout_list #:nodoc:
- Array(view_paths).sum([]) { |path| Dir["#{path}/layouts/**/*"] }
+ def find_layout(layout, *formats) #:nodoc:
+ return layout if layout.respond_to?(:render)
+ view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", *formats)
end
private
@@ -189,7 +188,7 @@ module ActionController #:nodoc:
inherited_without_layout(child)
unless child.name.blank?
layout_match = child.name.underscore.sub(/_controller$/, '').sub(/^controllers\//, '')
- child.layout(layout_match, {}, true) unless child.layout_list.grep(%r{layouts/#{layout_match}(\.[a-z][0-9a-z]*)+$}).empty?
+ child.layout(layout_match, {}, true) if child.find_layout(layout_match, :all)
end
end
@@ -200,15 +199,6 @@ module ActionController #:nodoc:
def normalize_conditions(conditions)
conditions.inject({}) {|hash, (key, value)| hash.merge(key => [value].flatten.map {|action| action.to_s})}
end
-
- def default_layout_with_format(format, layout)
- list = layout_list
- if list.grep(%r{layouts/#{layout}\.#{format}(\.[a-z][0-9a-z]*)+$}).empty?
- (!list.grep(%r{layouts/#{layout}\.([a-z][0-9a-z]*)+$}).empty? && format == :html) ? layout : nil
- else
- layout
- end
- end
end
# Returns the name of the active layout. If the layout was specified as a method reference (through a symbol), this method
@@ -217,20 +207,18 @@ module ActionController #:nodoc:
# weblog/standard, but <tt>layout "standard"</tt> will return layouts/standard.
def active_layout(passed_layout = nil)
layout = passed_layout || self.class.default_layout(default_template_format)
+
active_layout = case layout
- when String then layout
when Symbol then __send__(layout)
when Proc then layout.call(self)
+ else layout
end
- # Explicitly passed layout names with slashes are looked up relative to the template root,
- # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative
- # to the 'layouts' directory so we have to check the file system to infer which case the layout name came from.
if active_layout
- if active_layout.include?('/') && ! layout_directory?(active_layout)
- active_layout
+ if layout = self.class.find_layout(active_layout, @template.template_format)
+ layout
else
- "layouts/#{active_layout}"
+ raise ActionView::MissingTemplate.new(self.class.view_paths, active_layout)
end
end
end
@@ -271,12 +259,6 @@ module ActionController #:nodoc:
end
end
- def layout_directory?(layout_name)
- @template.__send__(:_pick_template, "#{File.join('layouts', layout_name)}.#{@template.template_format}") ? true : false
- rescue ActionView::MissingTemplate
- false
- end
-
def default_template_format
response.template.template_format
end