From f3175bdb72df4a0a96b7c07592c29527b2d6fbeb Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Sun, 10 Jul 2016 13:03:09 +0300 Subject: [PATCH] Split helpers.cr into helpers/macros.cr and helpers/helpers.cr --- src/kemal.cr | 1 + src/kemal/helpers/helpers.cr | 41 ++++++++++++++++++++ src/kemal/{helpers.cr => helpers/macros.cr} | 42 --------------------- 3 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 src/kemal/helpers/helpers.cr rename src/kemal/{helpers.cr => helpers/macros.cr} (63%) diff --git a/src/kemal.cr b/src/kemal.cr index c087bbc..47e082a 100644 --- a/src/kemal.cr +++ b/src/kemal.cr @@ -1,4 +1,5 @@ require "./kemal/*" +require "./kemal/helpers/*" require "./kemal/middleware/*" module Kemal diff --git a/src/kemal/helpers/helpers.cr b/src/kemal/helpers/helpers.cr new file mode 100644 index 0000000..f755b0f --- /dev/null +++ b/src/kemal/helpers/helpers.cr @@ -0,0 +1,41 @@ +# Adds given HTTP::Handler+ to handlers. +def add_handler(handler) + Kemal.config.add_handler handler +end + +# Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support. +def basic_auth(username, password) + auth_handler = Kemal::Middleware::HTTPBasicAuth.new(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 + +# Logs to output stream. +# development: STDOUT in +# production: kemal.log +def log(message) + Kemal.config.logger.write "#{message}\n" +end + +# Enables / Disables logging +def logging(status) + Kemal.config.logging = status +end + +def logger(logger) + Kemal.config.logger = logger + Kemal.config.add_handler logger +end + +def serve_static(status) + Kemal.config.serve_static = status +end + +def headers(env, additional_headers) + env.response.headers.merge!(additional_headers) +end diff --git a/src/kemal/helpers.cr b/src/kemal/helpers/macros.cr similarity index 63% rename from src/kemal/helpers.cr rename to src/kemal/helpers/macros.cr index fcc4414..b785993 100644 --- a/src/kemal/helpers.cr +++ b/src/kemal/helpers/macros.cr @@ -58,45 +58,3 @@ macro return_with(env, status_code = 200, response = "") {{env}}.response.print {{response}} next end - -# Adds given HTTP::Handler+ to handlers. -def add_handler(handler) - Kemal.config.add_handler handler -end - -# Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support. -def basic_auth(username, password) - auth_handler = Kemal::Middleware::HTTPBasicAuth.new(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 - -# Logs to output stream. -# development: STDOUT in -# production: kemal.log -def log(message) - Kemal.config.logger.write "#{message}\n" -end - -# Enables / Disables logging -def logging(status) - Kemal.config.logging = status -end - -def logger(logger) - Kemal.config.logger = logger - Kemal.config.add_handler logger -end - -def serve_static(status) - Kemal.config.serve_static = status -end - -def headers(env, additional_headers) - env.response.headers.merge!(additional_headers) -end