Compare commits

...

6 commits

Author SHA1 Message Date
00e5c98fdd Merge remote-tracking branch 'upstream/master' 2021-05-12 11:57:15 -03:00
Serdar Dogruyol - Sedo セド
218be24221
Update Kilt version dependency to ~> 0.6.0 2021-04-11 16:37:10 +03:00
Oleh Prypin
926206a46c
Allow running specs from any directory (#609) 2021-04-11 12:17:50 +03:00
Sijawusz Pur Rahnama
d237d3ef7d
Bump exception_page shard to ~> 0.2.0 (#608) 2021-04-09 21:09:15 +03:00
Serdar Dogruyol - Sedo セド
6e72ebb447
Add array of paths support for before/after filters (#605) 2021-04-05 18:24:09 +03:00
Aravinda Vishwanathapura
de5e022222
New option to set application name (#606) 2021-04-05 18:05:06 +03:00
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 %}