mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add more documentation
This commit is contained in:
parent
8522fd2f56
commit
5c97942707
4 changed files with 11 additions and 9 deletions
|
@ -26,6 +26,10 @@ module Kemal
|
|||
HANDLERS << handler
|
||||
end
|
||||
|
||||
# Reads configuration from config.yml. Currently it only supports the public_folder
|
||||
# option.
|
||||
# config.yml
|
||||
# public_folder = "root/to/folder"
|
||||
def read_file
|
||||
path = File.expand_path("config.yml", Dir.working_directory)
|
||||
if File.exists?(path)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Route is the main building block of Kemal.
|
||||
# It takes 3 parameters method, path and a block to specify
|
||||
# It takes 3 parameters: Method, path and a block to specify
|
||||
# what action to be done if the route is matched.
|
||||
class Kemal::Route
|
||||
getter handler
|
||||
|
@ -22,7 +22,7 @@ class Kemal::Route
|
|||
true
|
||||
end
|
||||
|
||||
# checks if request params contain _method param to override request incoming method
|
||||
# Checks if request params contain _method param to override request incoming method
|
||||
def check_for_method_override!(request)
|
||||
request.override_method = request.method
|
||||
if request.method == "POST"
|
||||
|
@ -33,7 +33,7 @@ class Kemal::Route
|
|||
end
|
||||
end
|
||||
|
||||
# checks if method contained in _method param is valid one
|
||||
# Checks if method contained in _method param is valid one
|
||||
def override_method_valid?(override_method)
|
||||
return false unless override_method.is_a?(String)
|
||||
override_method = override_method.upcase
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require "http/server"
|
||||
|
||||
class Kemal::StaticFileHandler < HTTP::StaticFileHandler
|
||||
def call(request)
|
||||
request_path = request.path.not_nil!
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
# Kemal render uses built-in ECR to render methods.
|
||||
require "ecr/macros"
|
||||
|
||||
# Uses built-in ECR to render views.
|
||||
# # Usage
|
||||
# get '/' do
|
||||
# render 'hello.ecr'
|
||||
# end
|
||||
|
||||
require "ecr/macros"
|
||||
|
||||
macro render(filename)
|
||||
String.build do |__view__|
|
||||
embed_ecr({{filename}}, "__view__")
|
||||
|
@ -18,6 +16,7 @@ macro render(filename, layout)
|
|||
render {{layout}}
|
||||
end
|
||||
|
||||
# Template for 404 Not Found
|
||||
def render_404
|
||||
template = <<-HTML
|
||||
<!DOCTYPE html>
|
||||
|
@ -38,6 +37,7 @@ def render_404
|
|||
HTTP::Response.new(404, template)
|
||||
end
|
||||
|
||||
# Template for 500 Internal Server Error
|
||||
def render_500(ex)
|
||||
template = <<-HTML
|
||||
<!DOCTYPE html>
|
||||
|
|
Loading…
Reference in a new issue