Module: Hyde::Util
- Defined in:
- lib/hyde/util/lookup.rb,
lib/hyde/util/html.rb,
lib/hyde/util/query.rb
Overview
Various things that exists for purely logical reasons
Defined Under Namespace
Constant Summary collapse
- HTTP_STATUS =
HTTP status codes and descriptions Taken from WEBrick https://github.com/ruby/webrick/blob/master/lib/webrick/httpstatus.rb
{ 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Request Range Not Satisfiable', 417 => 'Expectation Failed', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 507 => 'Insufficient Storage', 511 => 'Network Authentication Required' }.freeze
Class Method Summary collapse
-
.default_error_page(code, backtrace) ⇒ String
Default error page for Hyde.
-
.escape_html(str) ⇒ String
Return string with escaped HTML entities.
Class Method Details
.default_error_page(code, backtrace) ⇒ String
Default error page for Hyde
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/hyde/util/html.rb', line 78 def self.default_error_page(code, backtrace) backtrace ||= [] errortext = HTTP_STATUS[code] <<~HTMLEOF <!DOCTYPE HTML> <html> <head> <title>#{Util.escape_html(errortext)}</title> <style> .header {padding: 0.5rem; overflow: auto;} .title { font-weight: bolder; font-size: 48px; margin: 10px 10px; text-shadow: 1px 1px 1px #202222, 2px 2px 2px #404444; float: left } body { margin: 0; } .text { font-size 1rem; } .small { color: #7D7D7D; font-size: 12px;} .code { font-family: monospace; font-size: 0.7rem; } </style> </head> <body> <div class="header"> <p class="title">HYDE</p> <p style="float: right"><a href="https://adastra7.net/git/yessiest/hyde">Source code</a></p> </div> <div style="padding: 0.5rem"> <p class="text">#{Util.escape_html(errortext)}</p> <pre><code class="text code"> #{backtrace.map(&Util.method(:escape_html)).join('<br/>')} </code></pre> <hr/> <p class="small">#{Util.escape_html(Hyde::VLINE)}</p> </div> </body> </html> HTMLEOF end |
.escape_html(str) ⇒ String
Return string with escaped HTML entities
64 65 66 67 68 69 70 |
# File 'lib/hyde/util/html.rb', line 64 def self.escape_html(str) str.gsub("&", "&") .gsub("<", "<") .gsub(">", ">") .gsub("\"", """) .gsub("'", "'") end |