1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Bring layouts with proc back alive.

This commit is contained in:
José Valim 2010-01-26 16:34:25 +01:00
parent 48a3985dd7
commit e274eb1df1
2 changed files with 18 additions and 1 deletions

View file

@ -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

View file

@ -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