class Resulang::Server
Public Class Methods
app()
click to toggle source
# File lib/resulang/server.rb, line 19 def self.app Resulang::App.new(path: File.expand_path('.')) end
call(env)
click to toggle source
# File lib/resulang/server.rb, line 44 def self.call(env) if env['PATH_INFO'] == '/' serve_html else serve_file(env['PATH_INFO']) end end
escape(html)
click to toggle source
# File lib/resulang/server.rb, line 7 def self.escape(html) html.gsub(/\</, '<').gsub(/\>/, '>').gsub(/\"/, '"') end
mime_type(filename)
click to toggle source
# File lib/resulang/server.rb, line 11 def self.mime_type(filename) if (types = MIME::Types.type_for(filename)).empty? 'text/plain' else types.first.content_type end end
serve_file(path)
click to toggle source
# File lib/resulang/server.rb, line 31 def self.serve_file(path) fullpath = File.expand_path("./#{path}") if File.file?(fullpath) data = File.read(fullpath) headers = { 'Content-Type' => mime_type(File.basename(path)) } [200, headers, [data]] else [404, { 'Content-Type' => 'text/html' }, ['Not Found']] end end
serve_html()
click to toggle source
# File lib/resulang/server.rb, line 23 def self.serve_html html = app.processor(output: nil, format: :html).process headers = { 'Content-Type' => 'text/html' } [200, headers, [html]] end