mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add layout support for render macro. It should be improved in the future.
This commit is contained in:
parent
a67a8508cf
commit
9ade49ae20
3 changed files with 17 additions and 1 deletions
1
spec/asset/layout.ecr
Normal file
1
spec/asset/layout.ecr
Normal file
|
@ -0,0 +1 @@
|
|||
<html><%= content %></html>
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue