diff options
author | Yehuda Katz and Carl Lerche <wycats@gmail.com> | 2009-04-06 12:35:44 -0700 |
---|---|---|
committer | Yehuda Katz and Carl Lerche <wycats@gmail.com> | 2009-04-06 12:35:44 -0700 |
commit | 9c8eaf8e254cf8ccaa6ecae3fdf1f468fbb60db8 (patch) | |
tree | 9f5a7e72bcd1fecc54499e21f3e4ebb2ea62da1a /actionpack/lib | |
parent | 4d3cd9b43f6b7425ca3eee303773d2221e8af38f (diff) | |
parent | 1d3e2c2b7333c90f2ef26fd0a3c6184aeaeb7e8a (diff) | |
download | rails-9c8eaf8e254cf8ccaa6ecae3fdf1f468fbb60db8.tar.gz rails-9c8eaf8e254cf8ccaa6ecae3fdf1f468fbb60db8.tar.bz2 rails-9c8eaf8e254cf8ccaa6ecae3fdf1f468fbb60db8.zip |
Merge branch 'abstract_controller' of git@github.com:wycats/rails into abstract_controller
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/abstract/layouts.rb | 42 | ||||
-rw-r--r-- | actionpack/lib/action_view/paths.rb | 9 |
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) |