diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b0f83c..c3949fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,4 @@ -# 1.1.0 (02-09-2021) - -- You can now set your own application name for startup message [#606](https://github.com/kemalcr/kemal/pull/606). Thanks @aravindavk :pray: -- Add array of paths support for before/after filters [#605](https://github.com/kemalcr/kemal/pull/605). Thanks @sdogruyol :pray: -- Fixed executing filters when before and after is defined at the same time [#612](https://github.com/kemalcr/kemal/pull/612). Thanks @mamantoha :pray: -- Set content type to text/html for 500 exceptions [#616](https://github.com/kemalcr/kemal/pull/616). Thanks @sdogruyol :pray: - -# 1.0.0 (22-03-2021) +# 1.0.0 (??-03-2021) - Crystal 1.0.0 support :tada: - Update Radix to use latest 0.4.0 [#596](https://github.com/kemalcr/kemal/pull/596). Thanks @luislavena :pray: diff --git a/README.md b/README.md index aba67b4..9f9ff64 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ See also [Getting Started](http://kemalcr.com/guide/). - Middleware support - Built-in JSON support - Built-in static file serving -- Built-in view templating via [ECR](https://crystal-lang.org/api/ECR.html) +- Built-in view templating via [Kilt](https://github.com/jeromegn/kilt) # Documentation diff --git a/shard.yml b/shard.yml index 72011fd..e37bdde 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: kemal -version: 1.1.0 +version: 1.0.0 authors: - Serdar Dogruyol @@ -8,6 +8,9 @@ dependencies: radix: github: luislavena/radix version: ~> 0.4.0 + kilt: + github: jeromegn/kilt + version: ~> 0.6.0 exception_page: github: crystal-loot/exception_page version: ~> 0.2.0 diff --git a/spec/exception_handler_spec.cr b/spec/exception_handler_spec.cr index 7064e84..b9519e9 100644 --- a/spec/exception_handler_spec.cr +++ b/spec/exception_handler_spec.cr @@ -59,30 +59,6 @@ describe "Kemal::ExceptionHandler" do response.body.should eq "Something happened" end - it "overrides the content type for filters" do - before_get do |env| - env.response.content_type = "application/json" - end - error 500 do |_, err| - err.message - end - get "/" do |env| - env.response.status_code = 500 - end - request = HTTP::Request.new("GET", "/") - io = IO::Memory.new - response = HTTP::Server::Response.new(io) - context = HTTP::Server::Context.new(request, response) - Kemal::ExceptionHandler::INSTANCE.next = Kemal::RouteHandler::INSTANCE - Kemal::ExceptionHandler::INSTANCE.call(context) - response.close - io.rewind - response = HTTP::Client::Response.from_io(io, decompress: false) - response.status_code.should eq 500 - response.headers["Content-Type"].should eq "text/html" - response.body.should eq "Rendered error with 500" - end - it "keeps the specified error Content-Type" do error 500 do "Something happened" diff --git a/spec/middleware/filters_spec.cr b/spec/middleware/filters_spec.cr index 5c3b477..9bc2564 100644 --- a/spec/middleware/filters_spec.cr +++ b/spec/middleware/filters_spec.cr @@ -183,30 +183,6 @@ describe "Kemal::FilterHandler" do client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false) client_response.body.should eq("true") end - - it "executes code before and after request" do - before_filter = FilterTest.new - before_filter.modified = "false" - - after_filter = FilterTest.new - after_filter.modified = "false" - - filter_middleware = Kemal::FilterHandler.new - filter_middleware._add_route_filter("ALL", "*", :before) { before_filter.modified = "true" } - filter_middleware._add_route_filter("ALL", "*", :after) { after_filter.modified = "true" } - - kemal = Kemal::RouteHandler::INSTANCE - kemal.add_route "GET", "/" { "#{before_filter.modified}-#{after_filter.modified}" } - - before_filter.modified.should eq("false") - after_filter.modified.should eq("false") - - request = HTTP::Request.new("GET", "/") - create_request_and_return_io_and_context(filter_middleware, request) - io_with_context = create_request_and_return_io_and_context(kemal, request)[0] - client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false) - client_response.body.should eq("true-true") - end end class FilterTest diff --git a/src/kemal/filter_handler.cr b/src/kemal/filter_handler.cr index 298ce26..6d28680 100644 --- a/src/kemal/filter_handler.cr +++ b/src/kemal/filter_handler.cr @@ -71,7 +71,7 @@ module Kemal end private def radix_path(verb : String?, path : String, type : Symbol) - "/#{type}/#{verb}/#{path}" + "#{type}/#{verb}/#{path}" end # :nodoc: diff --git a/src/kemal/helpers/macros.cr b/src/kemal/helpers/macros.cr index 41c8793..4b5e309 100644 --- a/src/kemal/helpers/macros.cr +++ b/src/kemal/helpers/macros.cr @@ -1,3 +1,5 @@ +require "kilt" + CONTENT_FOR_BLOCKS = Hash(String, Tuple(String, Proc(String))).new # `content_for` is a set of helpers that allows you to capture @@ -35,9 +37,9 @@ CONTENT_FOR_BLOCKS = Hash(String, Tuple(String, Proc(String))).new # setting the appropriate set of tags that should be added to the layout. macro content_for(key, file = __FILE__) %proc = ->() { - __view_io__ = IO::Memory.new + __kilt_io__ = IO::Memory.new {{ yield }} - __view_io__.to_s + __kilt_io__.to_s } CONTENT_FOR_BLOCKS[{{key}}] = Tuple.new {{file}}, %proc @@ -60,15 +62,13 @@ end # ``` macro render(filename, layout) __content_filename__ = {{filename}} - io = IO::Memory.new - content = ECR.embed {{filename}}, io - ECR.embed {{layout}}, io - io.to_s + content = render {{filename}} + render {{layout}} end # Render view with the given filename. macro render(filename) - ECR.render({{filename}}) + Kilt.render({{filename}}) end # Halt execution with the current context. diff --git a/src/kemal/helpers/templates.cr b/src/kemal/helpers/templates.cr index 0468d38..b343fc8 100644 --- a/src/kemal/helpers/templates.cr +++ b/src/kemal/helpers/templates.cr @@ -22,7 +22,6 @@ def render_404 end def render_500(context, exception, verbosity) - context.response.content_type = "text/html" context.response.status_code = 500 template = if verbosity