diff --git a/src/kemal.cr b/src/kemal.cr index 84155f6..088e897 100644 --- a/src/kemal.cr +++ b/src/kemal.cr @@ -2,6 +2,8 @@ require "./kemal/*" require "./kemal/middleware/*" module Kemal + + # The command to run a `Kemal` application. def self.run Kemal::CLI.new 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.not_nil!.ssl = config.ssl + # Test environment doesn't need to have signal trap, built-in images, and logging. unless config.env == "test" Signal::INT.trap { config.logger.write "Kemal is going to take a rest!\n" diff --git a/src/kemal/base_log_handler.cr b/src/kemal/base_log_handler.cr index 040bab2..b2180e3 100644 --- a/src/kemal/base_log_handler.cr +++ b/src/kemal/base_log_handler.cr @@ -1,5 +1,6 @@ require "http" +# All loggers must inherit from `Kemal::BaseLogHandler`. class Kemal::BaseLogHandler < HTTP::Handler def initialize(@env : String) end diff --git a/src/kemal/cli.cr b/src/kemal/cli.cr index c74a9b2..5d235b0 100644 --- a/src/kemal/cli.cr +++ b/src/kemal/cli.cr @@ -1,6 +1,7 @@ require "option_parser" module Kemal + # Handles all the initialization from the command line. class CLI @config : Kemal::Config @key_file : String diff --git a/src/kemal/helpers.cr b/src/kemal/helpers.cr index 9c1a411..6e3f7d1 100644 --- a/src/kemal/helpers.cr +++ b/src/kemal/helpers.cr @@ -5,7 +5,6 @@ require "kilt" # get '/' do # render 'hello.ecr' # end - macro render(filename, layout) content = render {{filename}} render {{layout}} @@ -21,6 +20,7 @@ macro return_with(env, status_code = 200, response = "") next end +# Adds given HTTP::Handler+ to handlers. def add_handler(handler) Kemal.config.add_handler handler end @@ -31,6 +31,8 @@ def basic_auth(username, password) add_handler auth_handler end +# Sets public folder from which the static assets will be served. +# By default this is `/public` not `src/public`. def public_folder(path) Kemal.config.public_folder = path end diff --git a/src/kemal/null_log_handler.cr b/src/kemal/null_log_handler.cr index 07d9665..a69f5a5 100644 --- a/src/kemal/null_log_handler.cr +++ b/src/kemal/null_log_handler.cr @@ -1,2 +1,3 @@ +# This is here to represend the logger corresponding to Null Object Pattern. class Kemal::NullLogHandler < Kemal::BaseLogHandler end diff --git a/src/kemal/websocket_handler.cr b/src/kemal/websocket_handler.cr index 28e39ae..e570834 100644 --- a/src/kemal/websocket_handler.cr +++ b/src/kemal/websocket_handler.cr @@ -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. class Kemal::WebSocketHandler < HTTP::WebSocketHandler def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void)