class Shipmonk::Server::RequestResponder
Attributes
request[RW]
Public Class Methods
new(request)
click to toggle source
# File lib/shipmonk/server/request_responder.rb, line 7 def initialize(request) @request = request end
Public Instance Methods
compile_haml(file, haml_options = {})
click to toggle source
# File lib/shipmonk/server/request_responder.rb, line 29 def compile_haml(file, haml_options = {}) content = File.read file engine = Haml::Engine.new(content, haml_options) engine.render Shipmonk::ViewContext.new end
respond()
click to toggle source
# File lib/shipmonk/server/request_responder.rb, line 11 def respond if template_source_file.exist? content = compile_haml template_source_file Rack::Response.new.finish do |response| response['content-type'] = 'text/html' response.status = 200 response.write content end else Rack::Response.new.finish do |response| response['content-type'] = 'text/plain' response.status = 404 response.write "404ed!\n" response.write "file not found: #{request.path_info}\n" end end end
template_source_file()
click to toggle source
# File lib/shipmonk/server/request_responder.rb, line 35 def template_source_file @template_source_file ||= Shipmonk.root.join 'src', case request.path_info when '/' then 'index.html.haml' when /\/(\w+)$/, /\/(.+).html$/ then "#{$1}.html.haml" else request.path_info end end