Replace global macros with methods. Thanks @asterite

This commit is contained in:
Sdogruyol 2016-02-14 18:52:49 +02:00
parent 092f5a2e49
commit 8c87a3fa67
2 changed files with 13 additions and 14 deletions

View file

@ -16,34 +16,33 @@ macro render(filename, layout)
render {{layout}} render {{layout}}
end end
macro add_handler(handler) def add_handler(handler)
Kemal.config.add_handler {{handler}} Kemal.config.add_handler handler
end end
# Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support. # Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support.
macro basic_auth(username, password) def basic_auth(username, password)
auth_handler = Kemal::Middleware::HTTPBasicAuth.new({{username}}, {{password}}) auth_handler = Kemal::Middleware::HTTPBasicAuth.new(username, password)
add_handler auth_handler add_handler auth_handler
end end
macro public_folder(path) def public_folder(path)
Kemal.config.public_folder = {{path}} Kemal.config.public_folder = path
end end
# Logs to output stream. # Logs to output stream.
# development: STDOUT in # development: STDOUT in
# production: kemal.log # production: kemal.log
macro log(message) def log(message)
Kemal.config.logger.write "#{{{message}}}\n" Kemal.config.logger.write "#{message}\n"
end end
# Enables / Disables logging # Enables / Disables logging
macro logging(status) def logging(status)
Kemal.config.logging = {{status}} Kemal.config.logging = status
end end
macro logger(logger) def logger(logger)
Kemal.config.logger = logger
Kemal.config.logger = {{logger}} Kemal.config.add_handler logger
Kemal.config.add_handler {{logger}}
end end