aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-26 16:34:25 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-26 16:34:25 +0100
commite274eb1df1dcf526febb7c3a1a8dc2c02325d68c (patch)
tree7f4947805a7ab03cdab0943635f4a3f9aed310fa /actionpack
parent48a3985dd77160b34fc3ac35a75d850d8a2711f0 (diff)
downloadrails-e274eb1df1dcf526febb7c3a1a8dc2c02325d68c.tar.gz
rails-e274eb1df1dcf526febb7c3a1a8dc2c02325d68c.tar.bz2
rails-e274eb1df1dcf526febb7c3a1a8dc2c02325d68c.zip
Bring layouts with proc back alive.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/abstract_controller/layouts.rb3
-rw-r--r--actionpack/test/abstract/layouts_test.rb16
2 files changed, 18 insertions, 1 deletions
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb
index 6fbf6bc392..56ddf9bf01 100644
--- a/actionpack/lib/abstract_controller/layouts.rb
+++ b/actionpack/lib/abstract_controller/layouts.rb
@@ -270,6 +270,9 @@ module AbstractController
end
end
ruby_eval
+ when Proc
+ define_method :_layout_from_proc, &@_layout
+ self.class_eval %{def _layout(details) _layout_from_proc(self) end}
when false
self.class_eval %{def _layout(details) end}
when true
diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb
index df73d948f0..8cbb72dc83 100644
--- a/actionpack/test/abstract/layouts_test.rb
+++ b/actionpack/test/abstract/layouts_test.rb
@@ -67,7 +67,15 @@ module AbstractControllerTests
class WithChildOfImplied < WithStringImpliedChild
end
-
+
+ class WithProc < Base
+ layout proc { |c| "omg" }
+
+ def index
+ render :_template => ActionView::Template::Text.new("Hello proc!")
+ end
+ end
+
class WithSymbol < Base
layout :hello
@@ -198,6 +206,12 @@ module AbstractControllerTests
controller.process(:index)
assert_equal "Hello nil!", controller.response_body
end
+
+ test "when layout is specified as a proc, call it and use the layout returned" do
+ controller = WithProc.new
+ controller.process(:index)
+ assert_equal "OMGHI2U Hello proc!", controller.response_body
+ end
test "when layout is specified as a symbol, call the requested method and use the layout returned" do
controller = WithSymbol.new