class Guinness::Server
Public Class Methods
new(app)
click to toggle source
# File lib/guinness/server.rb, line 3 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/guinness/server.rb, line 7 def call(env) body = render File.join(@app.settings[:root], env['PATH_INFO']) if body [200, { 'Content-Type' => Rack::Mime.mime_type(File.extname(env['PATH_INFO']), 'text/html') }, [body]] else [404, { 'Content-Type' => 'text/plain' }, 'Not Found'] end end
render(path)
click to toggle source
# File lib/guinness/server.rb, line 16 def render(path) return File.read path if File.file? path # default to index if path to directory path = File.join(path, 'index') if Dir.exists? path # return the first filename that matches file template = Dir[File.join("#{path}*")].first return Guinness::View.new(template).render if template end