Split helpers.cr into helpers/macros.cr and helpers/helpers.cr

This commit is contained in:
Sdogruyol 2016-07-10 13:03:09 +03:00
parent daac09a859
commit f3175bdb72
3 changed files with 42 additions and 42 deletions

View file

@ -1,4 +1,5 @@
require "./kemal/*" require "./kemal/*"
require "./kemal/helpers/*"
require "./kemal/middleware/*" require "./kemal/middleware/*"
module Kemal module Kemal

View file

@ -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

View file

@ -58,45 +58,3 @@ macro return_with(env, status_code = 200, response = "")
{{env}}.response.print {{response}} {{env}}.response.print {{response}}
next next
end 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