Add more documentation

This commit is contained in:
Sdogruyol 2016-04-18 21:40:48 +03:00
parent a8ecbde222
commit 18efc4601f
6 changed files with 10 additions and 2 deletions

View file

@ -2,6 +2,8 @@ require "./kemal/*"
require "./kemal/middleware/*" require "./kemal/middleware/*"
module Kemal module Kemal
# The command to run a `Kemal` application.
def self.run def self.run
Kemal::CLI.new Kemal::CLI.new
config = Kemal.config config = Kemal.config
@ -11,6 +13,7 @@ module Kemal
config.server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers) config.server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers)
config.server.not_nil!.ssl = config.ssl config.server.not_nil!.ssl = config.ssl
# Test environment doesn't need to have signal trap, built-in images, and logging.
unless config.env == "test" unless config.env == "test"
Signal::INT.trap { Signal::INT.trap {
config.logger.write "Kemal is going to take a rest!\n" config.logger.write "Kemal is going to take a rest!\n"

View file

@ -1,5 +1,6 @@
require "http" require "http"
# All loggers must inherit from `Kemal::BaseLogHandler`.
class Kemal::BaseLogHandler < HTTP::Handler class Kemal::BaseLogHandler < HTTP::Handler
def initialize(@env : String) def initialize(@env : String)
end end

View file

@ -1,6 +1,7 @@
require "option_parser" require "option_parser"
module Kemal module Kemal
# Handles all the initialization from the command line.
class CLI class CLI
@config : Kemal::Config @config : Kemal::Config
@key_file : String @key_file : String

View file

@ -5,7 +5,6 @@ require "kilt"
# get '/' do # get '/' do
# render 'hello.ecr' # render 'hello.ecr'
# end # end
macro render(filename, layout) macro render(filename, layout)
content = render {{filename}} content = render {{filename}}
render {{layout}} render {{layout}}
@ -21,6 +20,7 @@ macro return_with(env, status_code = 200, response = "")
next next
end end
# Adds given HTTP::Handler+ to handlers.
def add_handler(handler) def add_handler(handler)
Kemal.config.add_handler handler Kemal.config.add_handler handler
end end
@ -31,6 +31,8 @@ def basic_auth(username, password)
add_handler auth_handler add_handler auth_handler
end end
# Sets public folder from which the static assets will be served.
# By default this is `/public` not `src/public`.
def public_folder(path) def public_folder(path)
Kemal.config.public_folder = path Kemal.config.public_folder = path
end end

View file

@ -1,2 +1,3 @@
# This is here to represend the logger corresponding to Null Object Pattern.
class Kemal::NullLogHandler < Kemal::BaseLogHandler class Kemal::NullLogHandler < Kemal::BaseLogHandler
end end

View file

@ -1,4 +1,4 @@
# Kemal::WebSocketHandler is used for each define WebSocket route. # Kemal::WebSocketHandler is used for building a WebSocket route.
# For each WebSocket route a new handler is created and registered to global handlers. # For each WebSocket route a new handler is created and registered to global handlers.
class Kemal::WebSocketHandler < HTTP::WebSocketHandler class Kemal::WebSocketHandler < HTTP::WebSocketHandler
def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void) def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void)