Renamed all occurrences to Kemal

This commit is contained in:
Sdogruyol 2015-10-23 21:33:26 +03:00
parent 289ad42d4e
commit 5ca84fea4c
13 changed files with 38 additions and 38 deletions

View file

@ -1,4 +1,4 @@
# frank
# Kemal
This is a proof-of-concept [Sinatra](http://www.sinatrarb.com/) clone for [Crystal](http://www.crystal-lang.org).

View file

@ -1,4 +1,4 @@
require "../src/frank"
require "../libs/kemal"
get "/" do
"Hello World!"

View file

@ -1,43 +1,43 @@
require "./spec_helper"
describe "Frank::Handler" do
describe "Kemal::Handler" do
it "routes" do
frank = Frank::Handler.new
frank.add_route "GET", "/" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do
"hello"
end
request = HTTP::Request.new("GET", "/")
response = frank.call(request)
response = kemal.call(request)
response.body.should eq("hello")
end
it "routes request with query string" do
frank = Frank::Handler.new
frank.add_route "GET", "/" do |ctx|
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |ctx|
"hello #{ctx.params["message"]}"
end
request = HTTP::Request.new("GET", "/?message=world")
response = frank.call(request)
response = kemal.call(request)
response.body.should eq("hello world")
end
it "route parameter has more precedence than query string arguments" do
frank = Frank::Handler.new
frank.add_route "GET", "/:message" do |ctx|
kemal = Kemal::Handler.new
kemal.add_route "GET", "/:message" do |ctx|
"hello #{ctx.params["message"]}"
end
request = HTTP::Request.new("GET", "/world?message=coco")
response = frank.call(request)
response = kemal.call(request)
response.body.should eq("hello world")
end
it "sets content type" do
frank = Frank::Handler.new
frank.add_route "GET", "/" do |env|
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |env|
env.response.content_type = "application/json"
end
request = HTTP::Request.new("GET", "/")
response = frank.call(request)
response = kemal.call(request)
response.headers["Content-Type"].should eq("application/json")
end
end

View file

@ -1,4 +1,4 @@
require "spec"
require "../src/frank/*"
require "../src/kemal/*"
include Frank
include Kemal

View file

@ -1,7 +0,0 @@
def get(path, &block : Frank::Context -> _)
Frank::Handler::INSTANCE.add_route("GET", path, &block)
end
def post(path, &block : Frank::Context -> _)
Frank::Handler::INSTANCE.add_route("POST", path, &block)
end

View file

@ -1,17 +1,17 @@
require "option_parser"
require "./frank/*"
require "./Kemal/*"
at_exit do
OptionParser.parse! do |opts|
opts.on("-p ", "--port ", "port") do |opt_port|
Frank.config.port = opt_port.to_i
Kemal.config.port = opt_port.to_i
end
end
config = Frank.config
config = Kemal.config
handlers = [] of HTTP::Handler
handlers << HTTP::LogHandler.new
handlers << Frank::Handler::INSTANCE
handlers << Kemal::Handler::INSTANCE
handlers << HTTP::StaticFileHandler.new("./public")
server = HTTP::Server.new(config.port, handlers)

View file

@ -1,4 +1,4 @@
module Frank
module Kemal
class Config
INSTANCE = Config.new
property ssl

View file

@ -1,4 +1,4 @@
class Frank::Context
class Kemal::Context
getter request
def initialize(@request)

7
src/kemal/dsl.cr Normal file
View file

@ -0,0 +1,7 @@
def get(path, &block : Kemal::Context -> _)
Kemal::Handler::INSTANCE.add_route("GET", path, &block)
end
def post(path, &block : Kemal::Context -> _)
Kemal::Handler::INSTANCE.add_route("POST", path, &block)
end

View file

@ -1,7 +1,7 @@
require "http/server"
require "uri"
class Frank::Handler < HTTP::Handler
class Kemal::Handler < HTTP::Handler
INSTANCE = new
def initialize
@ -13,7 +13,7 @@ class Frank::Handler < HTTP::Handler
response || call_next(request)
end
def add_route(method, path, &handler : Frank::Context -> _)
def add_route(method, path, &handler : Kemal::Context -> _)
@routes << Route.new(method, path, &handler)
end
@ -30,8 +30,8 @@ class Frank::Handler < HTTP::Handler
params[key] ||= value
end
frank_request = Request.new(request, params)
context = Context.new(frank_request)
kemal_request = Request.new(request, params)
context = Context.new(kemal_request)
begin
body = route.handler.call(context).to_s
content_type = context.response?.try(&.content_type) || "text/plain"

View file

@ -1,4 +1,4 @@
class Frank::Request
class Kemal::Request
getter params
def initialize(@request, @params)

View file

@ -1,3 +1,3 @@
class Frank::Response
class Kemal::Response
property content_type
end

View file

@ -1,7 +1,7 @@
class Frank::Route
class Kemal::Route
getter handler
def initialize(@method, path, &@handler : Frank::Context -> _)
def initialize(@method, path, &@handler : Kemal::Context -> _)
@components = path.split "/"
end