Add layout support for render macro. It should be improved in the future.

This commit is contained in:
Fatih Kadir Akın 2015-12-09 17:52:56 +02:00
parent a67a8508cf
commit 9ade49ae20
3 changed files with 17 additions and 1 deletions

1
spec/asset/layout.ecr Normal file
View File

@ -0,0 +1 @@
<html><%= content %></html>

View File

@ -10,4 +10,14 @@ describe "Views" do
response = kemal.call(request)
response.body.should contain("Hello world")
end
it "renders layout" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/view/:name" do |env|
render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
response = kemal.call(request)
response.body.should contain("<html>Hello world")
end
end

View File

@ -9,6 +9,11 @@ require "ecr/macros"
macro render(filename)
String.build do |__view__|
embed_ecr {{filename}}, "__view__"
embed_ecr({{filename}}, "__view__")
end
end
macro render(filename, layout)
content = render {{filename}}
render {{layout}}
end