diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index baaf7f2ddca7b074de45d4bca6f49da691114cee..518d3771b9b39fbb3ea7c7cf0cd20c134229f5d3 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,8 @@ *SVN* +* Declare file extensions exempt from layouts. #6219 [brandon] + Example: ActionController::Base.exempt_from_layout 'rpdf' + * Add chained replace/update support for assert_select_rjs [Rick Olson] Given RJS like... diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index f42686c318f7dd9d506ff042e0b2f9ae96990eda..c9719895824cbb729b3b248527a9d7a411efc32a 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -315,6 +315,9 @@ class Base # Returns the name of the action this controller is processing. attr_accessor :action_name + # Templates that are exempt from layouts + @@exempt_from_layout = Set.new([/\.rjs$/]) + class << self # Factory for the standard create, process loop where the controller is discarded after processing. def process(request, response) #:nodoc: @@ -395,6 +398,14 @@ def filter_parameter_logging(*filter_words, &block) filtered_parameters end end + + # Don't render layouts for templates with the given extensions. + def exempt_from_layout(*extensions) + regexps = extensions.collect do |extension| + extension.is_a?(Regexp) ? extension : /\.#{Regexp.escape(extension.to_s)}$/ + end + @@exempt_from_layout.merge regexps + end end public @@ -1094,7 +1105,10 @@ def template_public?(template_name = default_template_name) end def template_exempt_from_layout?(template_name = default_template_name) - template_name =~ /\.rjs$/ || (@template.pick_template_extension(template_name) == :rjs rescue false) + @@exempt_from_layout.any? { |ext| template_name =~ ext } or + @template.pick_template_extension(template_name) == :rjs + rescue + false end def assert_existence_of_template_file(template_name) diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index bbb13d0320666b6232cf9e4159e3c29706f4c6bc..3e1d3d96446f2dfe380c26911f1f6f49a19eaaa3 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -72,6 +72,39 @@ def test_namespaced_controllers_auto_detect_layouts end end +class ExemptFromLayoutTest < Test::Unit::TestCase + def setup + @controller = LayoutTest.new + end + + def test_rjs_exempt_from_layout + assert @controller.send(:template_exempt_from_layout?, 'test.rjs') + end + + def test_rhtml_and_rxml_not_exempt_from_layout + assert !@controller.send(:template_exempt_from_layout?, 'test.rhtml') + assert !@controller.send(:template_exempt_from_layout?, 'test.rxml') + end + + def test_other_extension_not_exempt_from_layout + assert !@controller.send(:template_exempt_from_layout?, 'test.random') + end + + def test_add_extension_to_exempt_from_layout + ['rpdf', :rpdf].each do |ext| + assert_nothing_raised do + ActionController::Base.exempt_from_layout ext + end + assert @controller.send(:template_exempt_from_layout?, "test.#{ext}") + end + end + + def test_add_regexp_to_exempt_from_layout + ActionController::Base.exempt_from_layout /\.rdoc/ + assert @controller.send(:template_exempt_from_layout?, 'test.rdoc') + end +end + class DefaultLayoutController < LayoutTest end