Fix view rendering for Crystal 0.11.0

This commit is contained in:
Fatih Kadir Akın 2016-01-24 19:13:10 +02:00
parent 72a3bec2aa
commit c14fb3de96
3 changed files with 47 additions and 44 deletions

View file

@ -1 +1 @@
Hello <%= env.params["name"] %>
Hello <%= name %>

View file

@ -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

View file

@ -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)