Compare commits
6 commits
2fb7d018d5
...
00e5c98fdd
Author | SHA1 | Date | |
---|---|---|---|
00e5c98fdd | |||
|
218be24221 | ||
|
926206a46c | ||
|
d237d3ef7d | ||
|
6e72ebb447 | ||
|
de5e022222 |
7 changed files with 29 additions and 15 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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", "/")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 %}
|
||||
|
|
Loading…
Reference in a new issue