Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Luna 2021-05-12 11:57:15 -03:00
commit 00e5c98fdd
7 changed files with 29 additions and 15 deletions

View File

@ -10,10 +10,10 @@ dependencies:
version: ~> 0.4.0
kilt:
github: jeromegn/kilt
version: ~> 0.4.0
version: ~> 0.6.0
exception_page:
github: Sija/exception_page
branch: crystal-1.0
github: crystal-loot/exception_page
version: ~> 0.2.0
development_dependencies:
ameba:

View File

@ -58,4 +58,11 @@ describe "Config" do
it "gets the version from shards.yml" do
Kemal::VERSION.should_not be("")
end
it "sets application name" do
config = Kemal.config
config.app_name.should eq "Kemal"
config.app_name = "testapp"
config.app_name.should eq "testapp"
end
end

View File

@ -100,7 +100,7 @@ describe "Macros" do
describe "#send_file" do
it "sends file with given path and default mime-type" do
get "/" do |env|
send_file env, "./spec/asset/hello.ecr"
send_file env, "#{__DIR__}/asset/hello.ecr"
end
request = HTTP::Request.new("GET", "/")
@ -112,7 +112,7 @@ describe "Macros" do
it "sends file with given path and given mime-type" do
get "/" do |env|
send_file env, "./spec/asset/hello.ecr", "image/jpeg"
send_file env, "#{__DIR__}/asset/hello.ecr", "image/jpeg"
end
request = HTTP::Request.new("GET", "/")
@ -136,7 +136,7 @@ describe "Macros" do
it "sends file with given path and given filename" do
get "/" do |env|
send_file env, "./spec/asset/hello.ecr", filename: "image.jpg"
send_file env, "#{__DIR__}/asset/hello.ecr", filename: "image.jpg"
end
request = HTTP::Request.new("GET", "/")

View File

@ -1,14 +1,14 @@
require "./spec_helper"
macro render_with_base_and_layout(filename)
render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
render "#{__DIR__}/asset/#{{{filename}}}", "#{__DIR__}/asset/layout.ecr"
end
describe "Views" do
it "renders file" do
get "/view/:name" do |env|
name = env.params.url["name"]
render "spec/asset/hello.ecr"
render "#{__DIR__}/asset/hello.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
client_response = call_request_on_app(request)
@ -28,7 +28,7 @@ describe "Views" do
it "renders layout" do
get "/view/:name" do |env|
name = env.params.url["name"]
render "spec/asset/hello.ecr", "spec/asset/layout.ecr"
render "#{__DIR__}/asset/hello.ecr", "#{__DIR__}/asset/layout.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
client_response = call_request_on_app(request)
@ -40,7 +40,7 @@ describe "Views" do
name = env.params.url["name"]
var1 = "serdar"
var2 = "kemal"
render "spec/asset/hello_with_content_for.ecr", "spec/asset/layout_with_yield_and_vars.ecr"
render "#{__DIR__}/asset/hello_with_content_for.ecr", "#{__DIR__}/asset/layout_with_yield_and_vars.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
client_response = call_request_on_app(request)
@ -52,7 +52,7 @@ describe "Views" do
it "renders layout with content_for" do
get "/view/:name" do |env|
name = env.params.url["name"]
render "spec/asset/hello_with_content_for.ecr", "spec/asset/layout_with_yield.ecr"
render "#{__DIR__}/asset/hello_with_content_for.ecr", "#{__DIR__}/asset/layout_with_yield.ecr"
end
request = HTTP::Request.new("GET", "/view/world")
client_response = call_request_on_app(request)

View File

@ -67,11 +67,11 @@ module Kemal
def self.display_startup_message(config, server)
addresses = server.addresses.join ", " { |address| "#{config.scheme}://#{address}" }
log "[#{config.env}] Kemal is ready to lead at #{addresses}"
log "[#{config.env}] #{config.app_name} is ready to lead at #{addresses}"
end
def self.stop
raise "Kemal is already stopped." if !config.running
raise "#{Kemal.config.app_name} is already stopped." if !config.running
if server = config.server
server.close unless server.closed?
config.running = false
@ -90,7 +90,7 @@ module Kemal
private def self.setup_trap_signal
Signal::INT.trap do
log "Kemal is going to take a rest!" if Kemal.config.shutdown_message
log "#{Kemal.config.app_name} is going to take a rest!" if Kemal.config.shutdown_message
Kemal.stop
exit
end

View File

@ -24,9 +24,10 @@ module Kemal
property always_rescue, server : HTTP::Server?, extra_options, shutdown_message
property serve_static : (Bool | Hash(String, Bool))
property static_headers : (HTTP::Server::Response, String, File::Info -> Void)?
property powered_by_header : Bool = true
property powered_by_header : Bool = true, app_name
def initialize
@app_name = "Kemal"
@host_binding = "0.0.0.0"
@port = 3000
@env = ENV["KEMAL_ENV"]? || "development"

View File

@ -33,5 +33,11 @@ end
def {{type.id}}_{{method.id}}(path : String = "*", &block : HTTP::Server::Context -> _)
Kemal::FilterHandler::INSTANCE.{{type.id}}({{method}}.upcase, path, &block)
end
def {{type.id}}_{{method.id}}(paths : Array(String), &block : HTTP::Server::Context -> _)
paths.each do |path|
Kemal::FilterHandler::INSTANCE.{{type.id}}({{method}}.upcase, path, &block)
end
end
{% end %}
{% end %}