From e12abb6e8a454775c31ec9e282d5abf9246a9e4a Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 30 Aug 2008 20:18:54 +0100 Subject: Dont pass controller partial layout option to view --- actionpack/lib/action_controller/layout.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 8b6febe254..fd743ced38 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -245,7 +245,7 @@ module ActionController #:nodoc: template_with_options = options.is_a?(Hash) if (layout = pick_layout(template_with_options, options)) && apply_layout?(template_with_options, options) - options = options.merge :layout => false if template_with_options + options.delete(:layout) if template_with_options logger.info("Rendering template within #{layout}") if logger content_for_layout = render_with_no_layout(options, extra_options, &block) -- cgit v1.2.3 From a59a3db1f3ae8c6aadaa8e1ce08b05f9ad677932 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 31 Aug 2008 03:44:00 +0100 Subject: Move copying ivar logic from ActionController::Base to ActionView::Base --- actionpack/lib/action_controller/layout.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index fd743ced38..585bd03797 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -250,7 +250,6 @@ module ActionController #:nodoc: content_for_layout = render_with_no_layout(options, extra_options, &block) erase_render_results - add_variables_to_assigns @template.instance_variable_set("@content_for_layout", content_for_layout) response.layout = layout status = template_with_options ? options[:status] : nil -- cgit v1.2.3 From a13d335461c6b177f0365ad07625c15f10ace271 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 31 Aug 2008 15:23:13 +0100 Subject: Move layout rendering logic to ActionView::Base --- actionpack/lib/action_controller/layout.rb | 53 +++++++----------------------- 1 file changed, 11 insertions(+), 42 deletions(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 585bd03797..ef59c7d63e 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -3,11 +3,6 @@ module ActionController #:nodoc: def self.included(base) base.extend(ClassMethods) base.class_eval do - # NOTE: Can't use alias_method_chain here because +render_without_layout+ is already - # defined as a publicly exposed method - alias_method :render_with_no_layout, :render - alias_method :render, :render_with_a_layout - class << self alias_method_chain :inherited, :layout end @@ -240,50 +235,24 @@ module ActionController #:nodoc: end end - protected - def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc: - template_with_options = options.is_a?(Hash) - - if (layout = pick_layout(template_with_options, options)) && apply_layout?(template_with_options, options) - options.delete(:layout) if template_with_options - logger.info("Rendering template within #{layout}") if logger - - content_for_layout = render_with_no_layout(options, extra_options, &block) - erase_render_results - @template.instance_variable_set("@content_for_layout", content_for_layout) - response.layout = layout - status = template_with_options ? options[:status] : nil - render_for_text(@template.render(layout), status) - else - render_with_no_layout(options, extra_options, &block) - end - end - - private - def apply_layout?(template_with_options, options) - return false if options == :update - template_with_options ? candidate_for_layout?(options) : !template_exempt_from_layout? - end - def candidate_for_layout?(options) - (options.has_key?(:layout) && options[:layout] != false) || - options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing).compact.empty? && + options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty? && !template_exempt_from_layout?(options[:template] || default_template_name(options[:action])) end - def pick_layout(template_with_options, options) - if template_with_options - case layout = options[:layout] - when FalseClass - nil - when NilClass, TrueClass - active_layout if action_has_layout? - else - active_layout(layout) + def pick_layout(options) + if options.has_key?(:layout) + case layout = options.delete(:layout) + when FalseClass + nil + when NilClass, TrueClass + active_layout if action_has_layout? && !template_exempt_from_layout?(default_template_name) + else + active_layout(layout) end else - active_layout if action_has_layout? + active_layout if action_has_layout? && candidate_for_layout?(options) end end -- cgit v1.2.3 From 086c3520c47c6c001b3ddbba8881b4175c433ed1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 31 Aug 2008 11:34:46 -0500 Subject: Moved layout exemption logic into the view --- actionpack/lib/action_controller/layout.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index ef59c7d63e..66e9997ae0 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -238,7 +238,7 @@ module ActionController #:nodoc: private def candidate_for_layout?(options) options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty? && - !template_exempt_from_layout?(options[:template] || default_template_name(options[:action])) + !@template.send(:_exempt_from_layout?, options[:template] || default_template_name(options[:action])) end def pick_layout(options) @@ -247,7 +247,7 @@ module ActionController #:nodoc: when FalseClass nil when NilClass, TrueClass - active_layout if action_has_layout? && !template_exempt_from_layout?(default_template_name) + active_layout if action_has_layout? && !@template.send(:_exempt_from_layout?, default_template_name) else active_layout(layout) end @@ -272,7 +272,9 @@ module ActionController #:nodoc: end def layout_directory?(layout_name) - @template.file_exists?("#{File.join('layouts', layout_name)}.#{@template.template_format}") + @template.send(:_pick_template, "#{File.join('layouts', layout_name)}.#{@template.template_format}") ? true : false + rescue ActionView::MissingTemplate + false end end end -- cgit v1.2.3 From e9a8e0053be3b293ab89fb584f1d660063f107aa Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 31 Aug 2008 19:11:15 +0100 Subject: Add layout functionality to mailers. Mailer layouts behaves just like controller layouts, except layout names need to have '_mailer' postfix for them to be automatically picked up. --- actionpack/lib/action_controller/layout.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 66e9997ae0..cf066eba64 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -216,7 +216,7 @@ module ActionController #:nodoc: # object). If the layout was defined without a directory, layouts is assumed. So layout "weblog/standard" will return # weblog/standard, but layout "standard" will return layouts/standard. def active_layout(passed_layout = nil) - layout = passed_layout || self.class.default_layout(response.template.template_format) + layout = passed_layout || self.class.default_layout(default_template_format) active_layout = case layout when String then layout when Symbol then send!(layout) @@ -276,5 +276,9 @@ module ActionController #:nodoc: rescue ActionView::MissingTemplate false end + + def default_template_format + response.template.template_format + end end end -- cgit v1.2.3 From a1eb4e11c2cccb91483fa15f1a1a0b2ae518d2cf Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 31 Aug 2008 13:15:26 -0700 Subject: Get rid of 'Object#send!'. It was originally added because it's in Ruby 1.9, but it has since been removed from 1.9. Signed-off-by: Jeremy Kemper Conflicts: actionpack/test/controller/layout_test.rb --- actionpack/lib/action_controller/layout.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index cf066eba64..8432a008eb 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -219,7 +219,7 @@ module ActionController #:nodoc: layout = passed_layout || self.class.default_layout(default_template_format) active_layout = case layout when String then layout - when Symbol then send!(layout) + when Symbol then __send__(layout) when Proc then layout.call(self) end @@ -238,7 +238,7 @@ module ActionController #:nodoc: private def candidate_for_layout?(options) options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty? && - !@template.send(:_exempt_from_layout?, options[:template] || default_template_name(options[:action])) + !@template.__send__(:_exempt_from_layout?, options[:template] || default_template_name(options[:action])) end def pick_layout(options) @@ -247,7 +247,7 @@ module ActionController #:nodoc: when FalseClass nil when NilClass, TrueClass - active_layout if action_has_layout? && !@template.send(:_exempt_from_layout?, default_template_name) + active_layout if action_has_layout? && !@template.__send__(:_exempt_from_layout?, default_template_name) else active_layout(layout) end @@ -272,7 +272,7 @@ module ActionController #:nodoc: end def layout_directory?(layout_name) - @template.send(:_pick_template, "#{File.join('layouts', layout_name)}.#{@template.template_format}") ? true : false + @template.__send__(:_pick_template, "#{File.join('layouts', layout_name)}.#{@template.template_format}") ? true : false rescue ActionView::MissingTemplate false end -- cgit v1.2.3 From 288e947ae1737645985fde76f5382baaff700505 Mon Sep 17 00:00:00 2001 From: Clemens Kofler Date: Tue, 2 Sep 2008 15:33:49 +0200 Subject: Some performance goodness for inheritable attributes. Signed-off-by: Jeremy Kemper --- actionpack/lib/action_controller/layout.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 8432a008eb..3631ce86af 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -164,17 +164,17 @@ module ActionController #:nodoc: # performance and have access to them as any normal template would. def layout(template_name, conditions = {}, auto = false) add_layout_conditions(conditions) - write_inheritable_attribute "layout", template_name - write_inheritable_attribute "auto_layout", auto + write_inheritable_attribute(:layout, template_name) + write_inheritable_attribute(:auto_layout, auto) end def layout_conditions #:nodoc: - @layout_conditions ||= read_inheritable_attribute("layout_conditions") + @layout_conditions ||= read_inheritable_attribute(:layout_conditions) end def default_layout(format) #:nodoc: - layout = read_inheritable_attribute("layout") - return layout unless read_inheritable_attribute("auto_layout") + 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] @@ -194,7 +194,7 @@ module ActionController #:nodoc: end def add_layout_conditions(conditions) - write_inheritable_hash "layout_conditions", normalize_conditions(conditions) + write_inheritable_hash(:layout_conditions, normalize_conditions(conditions)) end def normalize_conditions(conditions) -- cgit v1.2.3 From 36c6aa01ee0a7aee5b0510a8e649c44de318b060 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 9 Sep 2008 17:20:55 -0500 Subject: Revert "Add layout functionality to mailers." This reverts commit e9a8e0053be3b293ab89fb584f1d660063f107aa. --- actionpack/lib/action_controller/layout.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 3631ce86af..455e242c22 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -216,7 +216,7 @@ module ActionController #:nodoc: # object). If the layout was defined without a directory, layouts is assumed. So layout "weblog/standard" will return # weblog/standard, but layout "standard" will return layouts/standard. def active_layout(passed_layout = nil) - layout = passed_layout || self.class.default_layout(default_template_format) + layout = passed_layout || self.class.default_layout(response.template.template_format) active_layout = case layout when String then layout when Symbol then __send__(layout) @@ -276,9 +276,5 @@ module ActionController #:nodoc: rescue ActionView::MissingTemplate false end - - def default_template_format - response.template.template_format - end end end -- cgit v1.2.3 From 6228220c9b8a3bb32f8617ad2d963dabc965376e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 9 Sep 2008 17:25:09 -0500 Subject: Revert "Revert "Add layout functionality to mailers."" This reverts commit 36c6aa01ee0a7aee5b0510a8e649c44de318b060. --- actionpack/lib/action_controller/layout.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/layout.rb') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 455e242c22..3631ce86af 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -216,7 +216,7 @@ module ActionController #:nodoc: # object). If the layout was defined without a directory, layouts is assumed. So layout "weblog/standard" will return # weblog/standard, but layout "standard" will return layouts/standard. def active_layout(passed_layout = nil) - layout = passed_layout || self.class.default_layout(response.template.template_format) + layout = passed_layout || self.class.default_layout(default_template_format) active_layout = case layout when String then layout when Symbol then __send__(layout) @@ -276,5 +276,9 @@ module ActionController #:nodoc: rescue ActionView::MissingTemplate false end + + def default_template_format + response.template.template_format + end end end -- cgit v1.2.3