aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorYehuda Katz and Carl Lerche <wycats@gmail.com>2009-03-23 18:06:47 -0700
committerYehuda Katz and Carl Lerche <wycats@gmail.com>2009-03-23 18:06:47 -0700
commit1d3e2c2b7333c90f2ef26fd0a3c6184aeaeb7e8a (patch)
tree35ae0a1a2e8cd0ed3a105fbc08ddcc08014cb976 /actionpack/lib
parenta501638e9dcf55e45613637c52e4169b6324f285 (diff)
downloadrails-1d3e2c2b7333c90f2ef26fd0a3c6184aeaeb7e8a.tar.gz
rails-1d3e2c2b7333c90f2ef26fd0a3c6184aeaeb7e8a.tar.bz2
rails-1d3e2c2b7333c90f2ef26fd0a3c6184aeaeb7e8a.zip
In the middle of some refactoring... some fails due to changes in AbstractController not yet reflected in ActionController tests
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/abstract/layouts.rb42
-rw-r--r--actionpack/lib/action_view/paths.rb9
2 files changed, 40 insertions, 11 deletions
diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb
index 29b610610f..20c9abb9e5 100644
--- a/actionpack/lib/action_controller/abstract/layouts.rb
+++ b/actionpack/lib/action_controller/abstract/layouts.rb
@@ -6,7 +6,34 @@ module AbstractController
end
module ClassMethods
- def _layout() end
+ def layout(layout)
+ unless [String, Symbol, FalseClass, NilClass].include?(layout.class)
+ raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil"
+ end
+
+ @layout = layout || false # Converts nil to false
+ end
+
+ def _write_layout_method
+ case @layout
+ when String
+ self.class_eval %{def _layout() #{@layout.inspect} end}
+ when Symbol
+ self.class_eval %{def _layout() #{@layout} end}
+ when false
+ self.class_eval %{def _layout() end}
+ else
+ self.class_eval %{
+ def _layout
+ if view_paths.find_by_parts?("#{controller_path}", formats, "layouts")
+ "#{controller_path}"
+ else
+ super
+ end
+ end
+ }
+ end
+ end
end
def _render_template(template, options)
@@ -14,6 +41,8 @@ module AbstractController
end
private
+
+ def _layout() end # This will be overwritten
def _layout_for_option(name)
case name
@@ -28,16 +57,7 @@ module AbstractController
end
def _default_layout(require_layout = false)
- # begin
- # _layout_for_name(controller_path)
- # rescue ActionView::MissingTemplate
- # begin
- # _layout_for_name("application")
- # rescue ActionView::MissingTemplate => e
- # raise e if require_layout
- # end
- # end
- _layout_for_option(self.class._layout)
+ _layout_for_option(_layout)
end
end
end \ No newline at end of file
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb
index 2a1ba3e895..6c6d2ff979 100644
--- a/actionpack/lib/action_view/paths.rb
+++ b/actionpack/lib/action_view/paths.rb
@@ -46,6 +46,15 @@ module ActionView #:nodoc:
extension ||= []
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path}.{#{extension.join(",")}}")
end
+
+ def find_by_parts?(path, extension = nil, prefix = nil, partial = false)
+ template_path = path.sub(/^\//, '')
+
+ each do |load_path|
+ return true if template = load_path.find_by_parts(template_path, extension, prefix, partial)
+ end
+ false
+ end
def find_template(original_template_path, format = nil)
return original_template_path if original_template_path.respond_to?(:render)