fix content_for failing to capture the correct block input (#639)
This commit is contained in:
parent
d53d253620
commit
317d086b4c
5 changed files with 20 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
||||||
Hello <%= name %>
|
Hello <%= name %>
|
||||||
|
|
||||||
<% content_for "custom" do %>
|
<% content_for "meta" do %>
|
||||||
<h1>Hello from otherside</h1>
|
<title>Kemal Spec</title>
|
||||||
<% end %>
|
<% end %>
|
|
@ -1,6 +1,8 @@
|
||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<%= yield_content "meta" %>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%= content %>
|
<%= content %>
|
||||||
<%= yield_content "custom" %>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,8 +1,10 @@
|
||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<%= yield_content "meta" %>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%= content %>
|
<%= content %>
|
||||||
<%= yield_content "custom" %>
|
<%= var1 %>
|
||||||
<%= var1 %>
|
<%= var2 %>
|
||||||
<%= var2 %>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -56,8 +56,8 @@ describe "Views" do
|
||||||
end
|
end
|
||||||
request = HTTP::Request.new("GET", "/view/world")
|
request = HTTP::Request.new("GET", "/view/world")
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
client_response.body.should contain("Hello world")
|
client_response.body.scan("Hello world").size.should eq(1)
|
||||||
client_response.body.should contain("<h1>Hello from otherside</h1>")
|
client_response.body.should contain("<title>Kemal Spec</title>")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render content_for that was not yielded" do
|
it "does not render content_for that was not yielded" do
|
||||||
|
|
|
@ -43,7 +43,14 @@ macro yield_content(key)
|
||||||
if CONTENT_FOR_BLOCKS.has_key?({{key}})
|
if CONTENT_FOR_BLOCKS.has_key?({{key}})
|
||||||
__caller_filename__ = CONTENT_FOR_BLOCKS[{{key}}][0]
|
__caller_filename__ = CONTENT_FOR_BLOCKS[{{key}}][0]
|
||||||
%proc = CONTENT_FOR_BLOCKS[{{key}}][1]
|
%proc = CONTENT_FOR_BLOCKS[{{key}}][1]
|
||||||
%proc.call if __content_filename__ == __caller_filename__
|
|
||||||
|
if __content_filename__ == __caller_filename__
|
||||||
|
%old_content_io, content_io = content_io, IO::Memory.new
|
||||||
|
%proc.call
|
||||||
|
%result = content_io.to_s
|
||||||
|
content_io = %old_content_io
|
||||||
|
%result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue