Class: Cuttlebone::Drivers::Rack::Application
- Inherits:
-
Object
- Object
- Cuttlebone::Drivers::Rack::Application
- Defined in:
- lib/cuttlebone/drivers/rack.rb
Overview
Cuttlebone::Driver::Rack::Application
It’s a fully functional rack-enabled application that serves all other materials for a fully functional Cuttlebone web server.
Constant Summary collapse
- STATIC_FILES =
%w{ /index.html /favicon.png /stylesheets/cuttlebone.css /javascripts/cuttlebone.js /javascripts/jquery.min.js }
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.public_path(path = '') ⇒ Object
80 81 82 |
# File 'lib/cuttlebone/drivers/rack.rb', line 80 def self.public_path path='' File.("../../../../public/#{path}", __FILE__) end |
Instance Method Details
#call(env) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cuttlebone/drivers/rack.rb', line 84 def call(env) request = Rack::Request.new(env) response = Rack::Response.new if request.get? and request.path == '/' response.redirect('/index.html') elsif request.get? and STATIC_FILES.include?(request.path) response['Content-Type'] = 'application/javascript' if request.path =~ /\.js$/ response['Content-Type'] = 'text/css' if request.path =~ /\.css$/ response['Content-Type'] = 'image/png' if request.path =~ /\.png$/ response.write(File.read(File.("../../../../public#{request.path}", __FILE__))) response.status = 200 else response.write(File.read(File.("../../../../public/error.html", __FILE__)).gsub(/Error happens. It always does./, 'Not found.')) response.status = 404 end response.finish end |