Changeset 5126
- Timestamp:
- 09/16/06 01:31:17 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (3 diffs)
- trunk/actionpack/test/controller/layout_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r5110 r5126 1 1 *SVN* 2 3 * Declare file extensions exempt from layouts. #6219 [brandon] 4 Example: ActionController::Base.exempt_from_layout 'rpdf' 2 5 3 6 * Add chained replace/update support for assert_select_rjs [Rick Olson] trunk/actionpack/lib/action_controller/base.rb
r4988 r5126 316 316 attr_accessor :action_name 317 317 318 # Templates that are exempt from layouts 319 @@exempt_from_layout = Set.new([/\.rjs$/]) 320 318 321 class << self 319 322 # Factory for the standard create, process loop where the controller is discarded after processing. … … 395 398 filtered_parameters 396 399 end 400 end 401 402 # Don't render layouts for templates with the given extensions. 403 def exempt_from_layout(*extensions) 404 regexps = extensions.collect do |extension| 405 extension.is_a?(Regexp) ? extension : /\.#{Regexp.escape(extension.to_s)}$/ 406 end 407 @@exempt_from_layout.merge regexps 397 408 end 398 409 end … … 1095 1106 1096 1107 def template_exempt_from_layout?(template_name = default_template_name) 1097 template_name =~ /\.rjs$/ || (@template.pick_template_extension(template_name) == :rjs rescue false) 1108 @@exempt_from_layout.any? { |ext| template_name =~ ext } or 1109 @template.pick_template_extension(template_name) == :rjs 1110 rescue 1111 false 1098 1112 end 1099 1113 trunk/actionpack/test/controller/layout_test.rb
r4550 r5126 73 73 end 74 74 75 class ExemptFromLayoutTest < Test::Unit::TestCase 76 def setup 77 @controller = LayoutTest.new 78 end 79 80 def test_rjs_exempt_from_layout 81 assert @controller.send(:template_exempt_from_layout?, 'test.rjs') 82 end 83 84 def test_rhtml_and_rxml_not_exempt_from_layout 85 assert !@controller.send(:template_exempt_from_layout?, 'test.rhtml') 86 assert !@controller.send(:template_exempt_from_layout?, 'test.rxml') 87 end 88 89 def test_other_extension_not_exempt_from_layout 90 assert !@controller.send(:template_exempt_from_layout?, 'test.random') 91 end 92 93 def test_add_extension_to_exempt_from_layout 94 ['rpdf', :rpdf].each do |ext| 95 assert_nothing_raised do 96 ActionController::Base.exempt_from_layout ext 97 end 98 assert @controller.send(:template_exempt_from_layout?, "test.#{ext}") 99 end 100 end 101 102 def test_add_regexp_to_exempt_from_layout 103 ActionController::Base.exempt_from_layout /\.rdoc/ 104 assert @controller.send(:template_exempt_from_layout?, 'test.rdoc') 105 end 106 end 107 75 108 76 109 class DefaultLayoutController < LayoutTest