Try this:
#{request.request_method.downcase} "#{request.path_info}" do
.. do something ..
end
)
end
error do
@error = request.env['sinatra.error']
%Q(
Params:
#{params.inspect}
#{Rack::Utils.escape_html(@error.class.name + ' - ' + @error.message)}
#{Rack::Utils.escape_html(@error.backtrace.join("\n"))}
)
end
end
end
end
end
def get(path, options ={}, &b)
Sinatra.application.define_event(:get, path, options, &b)
end
def post(path, options ={}, &b)
Sinatra.application.define_event(:post, path, options, &b)
end
def put(path, options ={}, &b)
Sinatra.application.define_event(:put, path, options, &b)
end
def delete(path, options ={}, &b)
Sinatra.application.define_event(:delete, path, options, &b)
end
def before(&b)
Sinatra.application.define_filter(:before, &b)
end
def helpers(&b)
Sinatra::EventContext.class_eval(&b)
end
def error(type = Sinatra::ServerError, options = {}, &b)
Sinatra.application.define_error(type, options, &b)
end
def not_found(options = {}, &b)
Sinatra.application.define_error(Sinatra::NotFound, options, &b)
end
def layout(name = :layout, &b)
Sinatra.application.define_template(name, &b)
end
def template(name, &b)
Sinatra.application.define_template(name, &b)
end
def use_in_file_templates!
require 'stringio'
templates = IO.read(caller.first.split(':').first).split('__FILE__').last
data = StringIO.new(templates)
current_template = nil
data.each do |line|
if line =~ /^##\s?(.*)/
current_template = $1.to_sym
Sinatra.application.templates[current_template] = ''
elsif current_template
Sinatra.application.templates[current_template] << line
end
end
end
def configures(*envs, &b)
yield if !Sinatra.application.reloading &&
(envs.include?(Sinatra.application.options.env) ||
envs.empty?)
end
alias :configure :configures
def set_options(opts)
Sinatra::Application.default_options.merge!(opts)
Sinatra.application.options = nil
end
def set_option(key, value)
set_options(key => value)
end
def mime(ext, type)
Rack::File::MIME_TYPES[ext.to_s] = type
end
### Misc Core Extensions
module Kernel
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = old_verbose
end
end
class String
# Converts +self+ to an escaped URI parameter value
# 'Foo Bar'.to_param # => 'Foo%20Bar'
def to_param
URI.escape(self)
end
# Converts +self+ from an escaped URI parameter value
# 'Foo%20Bar'.from_param # => 'Foo Bar'
def from_param
URI.unescape(self)
end
end
class Hash
def to_params
map { |k,v| "#{k}=#{URI.escape(v)}" }.join('&')
end
def symbolize_keys
self.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
end
def pass(*keys)
reject { |k,v| !keys.include?(k) }
end
end
class Symbol
def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) }
end
end
class Array
def to_hash
self.inject({}) { |h, (k, v)| h[k] = v; h }
end
def to_proc
Proc.new { |*args| args.shift.__send__(self[0], *(args + self[1..-1])) }
end
end
module Enumerable
def eject(&block)
find { |e| result = block[e] and break result }
end
end
### Core Extension results for throw :halt
class Proc
def to_result(cx, *args)
cx.instance_eval(&self)
args.shift.to_result(cx, *args)
end
end
class String
def to_result(cx, *args)
args.shift.to_result(cx, *args)
self
end
end
class Array
def to_result(cx, *args)
self.shift.to_result(cx, *self)
end
end
class Symbol
def to_result(cx, *args)
cx.send(self, *args)
end
end
class Fixnum
def to_result(cx, *args)
cx.status self
args.shift.to_result(cx, *args)
end
end
class NilClass
def to_result(cx, *args)
''
end
end
at_exit do
raise $! if $!
if Sinatra.application.options.run
Sinatra.run
end
end
mime :xml, 'application/xml'
mime :js, 'application/javascript'