mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Fix view rendering for Crystal 0.11.0
This commit is contained in:
parent
72a3bec2aa
commit
c14fb3de96
3 changed files with 47 additions and 44 deletions
|
@ -1 +1 @@
|
|||
Hello <%= env.params["name"] %>
|
||||
Hello <%= name %>
|
||||
|
|
|
@ -1,40 +1,43 @@
|
|||
# require "./spec_helper"
|
||||
#
|
||||
# macro render_with_base_and_layout(filename)
|
||||
# render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
|
||||
# end
|
||||
#
|
||||
# describe "Views" do
|
||||
# it "renders file" do
|
||||
# kemal = Kemal::Handler.new
|
||||
# kemal.add_route "GET", "/view/:name" do |env|
|
||||
# render "spec/asset/hello.ecr"
|
||||
# end
|
||||
# request = HTTP::Request.new("GET", "/view/world")
|
||||
# io_with_context = create_request_and_return_io(kemal, request)
|
||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
# client_response.body.should contain("Hello world")
|
||||
# end
|
||||
#
|
||||
# it "renders file with dynamic variables" do
|
||||
# kemal = Kemal::Handler.new
|
||||
# kemal.add_route "GET", "/view/:name" do |env|
|
||||
# render_with_base_and_layout "hello.ecr"
|
||||
# end
|
||||
# request = HTTP::Request.new("GET", "/view/world")
|
||||
# io_with_context = create_request_and_return_io(kemal, request)
|
||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
# client_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")
|
||||
# io_with_context = create_request_and_return_io(kemal, request)
|
||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
# client_response.body.should contain("<html>Hello world")
|
||||
# end
|
||||
# end
|
||||
require "./spec_helper"
|
||||
|
||||
macro render_with_base_and_layout(filename)
|
||||
render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
|
||||
end
|
||||
|
||||
describe "Views" do
|
||||
it "renders file" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/view/:name" do |env|
|
||||
name = env.params["name"]
|
||||
render "spec/asset/hello.ecr"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/view/world")
|
||||
io_with_context = create_request_and_return_io(kemal, request)
|
||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.body.should contain("Hello world")
|
||||
end
|
||||
|
||||
it "renders file with dynamic variables" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/view/:name" do |env|
|
||||
name = env.params["name"]
|
||||
render_with_base_and_layout "hello.ecr"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/view/world")
|
||||
io_with_context = create_request_and_return_io(kemal, request)
|
||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.body.should contain("Hello world")
|
||||
end
|
||||
|
||||
it "renders layout" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/view/:name" do |env|
|
||||
name = env.params["name"]
|
||||
render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/view/world")
|
||||
io_with_context = create_request_and_return_io(kemal, request)
|
||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.body.should contain("<html>Hello world")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,9 +6,9 @@ require "ecr/macros"
|
|||
# render 'hello.ecr'
|
||||
# end
|
||||
macro render(filename)
|
||||
String.build do |__view__|
|
||||
__view__ = String::Builder.new
|
||||
embed_ecr({{filename}}, "__view__")
|
||||
end
|
||||
__view__.to_s
|
||||
end
|
||||
|
||||
macro render(filename, layout)
|
||||
|
|
Loading…
Reference in a new issue