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
|
HANDLERS << handler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Reads configuration from config.yml. Currently it only supports the public_folder
|
||||||
|
# option.
|
||||||
|
# config.yml
|
||||||
|
# public_folder = "root/to/folder"
|
||||||
def read_file
|
def read_file
|
||||||
path = File.expand_path("config.yml", Dir.working_directory)
|
path = File.expand_path("config.yml", Dir.working_directory)
|
||||||
if File.exists?(path)
|
if File.exists?(path)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Route is the main building block of Kemal.
|
# 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.
|
# what action to be done if the route is matched.
|
||||||
class Kemal::Route
|
class Kemal::Route
|
||||||
getter handler
|
getter handler
|
||||||
|
@ -22,7 +22,7 @@ class Kemal::Route
|
||||||
true
|
true
|
||||||
end
|
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)
|
def check_for_method_override!(request)
|
||||||
request.override_method = request.method
|
request.override_method = request.method
|
||||||
if request.method == "POST"
|
if request.method == "POST"
|
||||||
|
@ -33,7 +33,7 @@ class Kemal::Route
|
||||||
end
|
end
|
||||||
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)
|
def override_method_valid?(override_method)
|
||||||
return false unless override_method.is_a?(String)
|
return false unless override_method.is_a?(String)
|
||||||
override_method = override_method.upcase
|
override_method = override_method.upcase
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require "http/server"
|
|
||||||
|
|
||||||
class Kemal::StaticFileHandler < HTTP::StaticFileHandler
|
class Kemal::StaticFileHandler < HTTP::StaticFileHandler
|
||||||
def call(request)
|
def call(request)
|
||||||
request_path = request.path.not_nil!
|
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
|
# # Usage
|
||||||
# get '/' do
|
# get '/' do
|
||||||
# render 'hello.ecr'
|
# render 'hello.ecr'
|
||||||
# end
|
# end
|
||||||
|
|
||||||
require "ecr/macros"
|
|
||||||
|
|
||||||
macro render(filename)
|
macro render(filename)
|
||||||
String.build do |__view__|
|
String.build do |__view__|
|
||||||
embed_ecr({{filename}}, "__view__")
|
embed_ecr({{filename}}, "__view__")
|
||||||
|
@ -18,6 +16,7 @@ macro render(filename, layout)
|
||||||
render {{layout}}
|
render {{layout}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Template for 404 Not Found
|
||||||
def render_404
|
def render_404
|
||||||
template = <<-HTML
|
template = <<-HTML
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -38,6 +37,7 @@ def render_404
|
||||||
HTTP::Response.new(404, template)
|
HTTP::Response.new(404, template)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Template for 500 Internal Server Error
|
||||||
def render_500(ex)
|
def render_500(ex)
|
||||||
template = <<-HTML
|
template = <<-HTML
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
Loading…
Reference in a new issue