Merge pull request #63 from f/master

Fix view rendering for Crystal 0.11.0
This commit is contained in:
Serdar Dogruyol 2016-01-24 19:17:18 +02:00
commit fa1c039f4a
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" require "./spec_helper"
#
# macro render_with_base_and_layout(filename) macro render_with_base_and_layout(filename)
# render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr" render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
# end end
#
# describe "Views" do describe "Views" do
# it "renders file" do it "renders file" do
# kemal = Kemal::Handler.new kemal = Kemal::Handler.new
# kemal.add_route "GET", "/view/:name" do |env| kemal.add_route "GET", "/view/:name" do |env|
# render "spec/asset/hello.ecr" name = env.params["name"]
# end render "spec/asset/hello.ecr"
# request = HTTP::Request.new("GET", "/view/world") end
# io_with_context = create_request_and_return_io(kemal, request) request = HTTP::Request.new("GET", "/view/world")
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false) io_with_context = create_request_and_return_io(kemal, request)
# client_response.body.should contain("Hello world") client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
# end client_response.body.should contain("Hello world")
# end
# it "renders file with dynamic variables" do
# kemal = Kemal::Handler.new it "renders file with dynamic variables" do
# kemal.add_route "GET", "/view/:name" do |env| kemal = Kemal::Handler.new
# render_with_base_and_layout "hello.ecr" kemal.add_route "GET", "/view/:name" do |env|
# end name = env.params["name"]
# request = HTTP::Request.new("GET", "/view/world") render_with_base_and_layout "hello.ecr"
# io_with_context = create_request_and_return_io(kemal, request) end
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false) request = HTTP::Request.new("GET", "/view/world")
# client_response.body.should contain("Hello world") io_with_context = create_request_and_return_io(kemal, request)
# end client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
# client_response.body.should contain("Hello world")
# it "renders layout" do end
# kemal = Kemal::Handler.new
# kemal.add_route "GET", "/view/:name" do |env| it "renders layout" do
# render "spec/asset/hello.ecr", "spec/asset/layout.ecr" kemal = Kemal::Handler.new
# end kemal.add_route "GET", "/view/:name" do |env|
# request = HTTP::Request.new("GET", "/view/world") name = env.params["name"]
# io_with_context = create_request_and_return_io(kemal, request) render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false) end
# client_response.body.should contain("<html>Hello world") request = HTTP::Request.new("GET", "/view/world")
# end io_with_context = create_request_and_return_io(kemal, request)
# end 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' # render 'hello.ecr'
# end # end
macro render(filename) macro render(filename)
String.build do |__view__| __view__ = String::Builder.new
embed_ecr({{filename}}, "__view__") embed_ecr({{filename}}, "__view__")
end __view__.to_s
end end
macro render(filename, layout) macro render(filename, layout)