1 require File.dirname(__FILE__) + '/context/renderer'
8 attr_reader :request, :response
10 include Sinatra::Renderer
12 def initialize(request) #:nodoc:
14 @response = Rack::Response.new
18 # Sets or returns the status
19 def status(value = nil)
20 @response.status = value if value
21 @response.status || 200
24 # Sets or returns the body
33 def body(value = nil, &block)
34 @response.body = value if value
35 @response.body = block.call if block
39 # Renders an exception to +body+ and sets status to 500
40 def error(value = nil)
44 erb :error, :views_directory => SINATRA_ROOT + '/files/'
49 # Sets or returns response headers
52 # header 'Content-Type' => 'text/html'
53 # header 'Foo' => 'Bar'
55 # headers 'Content-Type' => 'text/html',
58 # Whatever blows your hair back
59 def headers(value = nil)
60 @response.headers.merge!(value) if value
63 alias :header :headers
65 # Returns a Hash of params. Keys are symbolized
67 @params ||= @request.params.symbolize_keys
72 logger.info "Redirecting to: #{path}"
74 header 'Location' => path
77 def log_event #:nodoc:
78 logger.info "#{request.request_method} #{request.path_info} | Status: #{status} | Params: #{params.inspect}"
79 logger.exception(error) if error