From 5ca84fea4ccd003327d7d73e7aa955f6c10f5cc2 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Fri, 23 Oct 2015 21:33:26 +0300 Subject: [PATCH] Renamed all occurrences to Kemal --- README.md | 2 +- samples/hello_world.cr | 2 +- spec/frank_handler_spec.cr | 26 +++++++++++++------------- spec/spec_helper.cr | 4 ++-- src/frank/dsl.cr | 7 ------- src/{frank.cr => kemal.cr} | 8 ++++---- src/{frank => kemal}/config.cr | 2 +- src/{frank => kemal}/context.cr | 2 +- src/kemal/dsl.cr | 7 +++++++ src/{frank => kemal}/handler.cr | 8 ++++---- src/{frank => kemal}/request.cr | 2 +- src/{frank => kemal}/response.cr | 2 +- src/{frank => kemal}/route.cr | 4 ++-- 13 files changed, 38 insertions(+), 38 deletions(-) delete mode 100644 src/frank/dsl.cr rename src/{frank.cr => kemal.cr} (77%) rename src/{frank => kemal}/config.cr (95%) rename src/{frank => kemal}/context.cr (89%) create mode 100644 src/kemal/dsl.cr rename src/{frank => kemal}/handler.cr (82%) rename src/{frank => kemal}/request.cr (81%) rename src/{frank => kemal}/response.cr (56%) rename src/{frank => kemal}/route.cr (87%) diff --git a/README.md b/README.md index 2729320..cd96b35 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/samples/hello_world.cr b/samples/hello_world.cr index be1ac36..ec6359a 100644 --- a/samples/hello_world.cr +++ b/samples/hello_world.cr @@ -1,4 +1,4 @@ -require "../src/frank" +require "../libs/kemal" get "/" do "Hello World!" diff --git a/spec/frank_handler_spec.cr b/spec/frank_handler_spec.cr index f69a611..37139ef 100644 --- a/spec/frank_handler_spec.cr +++ b/spec/frank_handler_spec.cr @@ -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 diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index f84647b..667d901 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,4 +1,4 @@ require "spec" -require "../src/frank/*" +require "../src/kemal/*" -include Frank +include Kemal diff --git a/src/frank/dsl.cr b/src/frank/dsl.cr deleted file mode 100644 index 2165f7d..0000000 --- a/src/frank/dsl.cr +++ /dev/null @@ -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 diff --git a/src/frank.cr b/src/kemal.cr similarity index 77% rename from src/frank.cr rename to src/kemal.cr index 74b0361..a9f449b 100644 --- a/src/frank.cr +++ b/src/kemal.cr @@ -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) diff --git a/src/frank/config.cr b/src/kemal/config.cr similarity index 95% rename from src/frank/config.cr rename to src/kemal/config.cr index e1711cc..7e3ff70 100644 --- a/src/frank/config.cr +++ b/src/kemal/config.cr @@ -1,4 +1,4 @@ -module Frank +module Kemal class Config INSTANCE = Config.new property ssl diff --git a/src/frank/context.cr b/src/kemal/context.cr similarity index 89% rename from src/frank/context.cr rename to src/kemal/context.cr index 8161f12..521ba5e 100644 --- a/src/frank/context.cr +++ b/src/kemal/context.cr @@ -1,4 +1,4 @@ -class Frank::Context +class Kemal::Context getter request def initialize(@request) diff --git a/src/kemal/dsl.cr b/src/kemal/dsl.cr new file mode 100644 index 0000000..21c59b5 --- /dev/null +++ b/src/kemal/dsl.cr @@ -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 diff --git a/src/frank/handler.cr b/src/kemal/handler.cr similarity index 82% rename from src/frank/handler.cr rename to src/kemal/handler.cr index f2fae00..d13c76a 100644 --- a/src/frank/handler.cr +++ b/src/kemal/handler.cr @@ -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" diff --git a/src/frank/request.cr b/src/kemal/request.cr similarity index 81% rename from src/frank/request.cr rename to src/kemal/request.cr index 55477bb..2e2344a 100644 --- a/src/frank/request.cr +++ b/src/kemal/request.cr @@ -1,4 +1,4 @@ -class Frank::Request +class Kemal::Request getter params def initialize(@request, @params) diff --git a/src/frank/response.cr b/src/kemal/response.cr similarity index 56% rename from src/frank/response.cr rename to src/kemal/response.cr index b2cb1a1..153cec6 100644 --- a/src/frank/response.cr +++ b/src/kemal/response.cr @@ -1,3 +1,3 @@ -class Frank::Response +class Kemal::Response property content_type end diff --git a/src/frank/route.cr b/src/kemal/route.cr similarity index 87% rename from src/frank/route.cr rename to src/kemal/route.cr index e7ee0ab..30f0e82 100644 --- a/src/frank/route.cr +++ b/src/kemal/route.cr @@ -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