提交 e274eb1d 编写于 作者: J José Valim

Bring layouts with proc back alive.

上级 48a3985d
......@@ -270,6 +270,9 @@ def _layout(details)
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
......
......@@ -67,7 +67,15 @@ class WithStringImpliedChild < WithString
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 @@ class TestBase < ActiveSupport::TestCase
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册