Add render macro to kemal core to have dynamic rendering mechanism. It actually binds built-in ecr parser to the Kemal as a macro.

This commit is contained in:
Fatih Kadir Akın 2015-12-06 16:05:16 +02:00
parent 692939dfe8
commit 945fa59a6c
6 changed files with 73 additions and 1 deletions

1
spec/asset/hello.ecr Normal file
View file

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

13
spec/view_spec.cr Normal file
View file

@ -0,0 +1,13 @@
require "./spec_helper"
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")
response = kemal.call(request)
response.body.should contain("Hello world")
end
end