aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-11-26 20:54:47 -0600
committerJoshua Peek <josh@joshpeek.com>2008-11-26 20:54:47 -0600
commit4d910b033379727e5e7355590c50c72fc75e56db (patch)
treeada3e45bf32d37d8f17f6ea944c8400912da26a8 /actionpack/lib/action_controller
parent9d2002a12a473f5b35c52db82518f4631776414f (diff)
downloadrails-4d910b033379727e5e7355590c50c72fc75e56db.tar.gz
rails-4d910b033379727e5e7355590c50c72fc75e56db.tar.bz2
rails-4d910b033379727e5e7355590c50c72fc75e56db.zip
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.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/base.rb5
-rw-r--r--actionpack/lib/action_controller/dispatcher.rb1
-rw-r--r--actionpack/lib/action_controller/layout.rb38
3 files changed, 13 insertions, 31 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 7e38f95076..dca66ff0a5 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -867,8 +867,9 @@ module ActionController #:nodoc:
end
end
- response.layout = layout = pick_layout(options)
- logger.info("Rendering template within #{layout}") if logger && layout
+ layout = pick_layout(options)
+ response.layout = layout.path_without_format_and_extension if layout
+ logger.info("Rendering template within #{layout.path_without_format_and_extension}") if logger && layout
if content_type = options[:content_type]
response.content_type = content_type.to_s
diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb
index 1c7a4b0545..6e4aba2280 100644
--- a/actionpack/lib/action_controller/dispatcher.rb
+++ b/actionpack/lib/action_controller/dispatcher.rb
@@ -137,7 +137,6 @@ module ActionController
run_callbacks :prepare_dispatch
Routing::Routes.reload
- ActionController::Base.view_paths.reload!
ActionView::Helpers::AssetTagHelper::AssetTag::Cache.clear
end
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