Fix whitespace errors across all source files and tests

I can't stand this shit anymore.
This commit is contained in:
Ryan Tomayko 2008-08-31 00:39:26 -07:00
parent 7be3682605
commit 60d50062d7
19 changed files with 537 additions and 588 deletions

View File

@ -28,15 +28,16 @@ module Rack #:nodoc:
class Request #:nodoc: class Request #:nodoc:
# Set of request method names allowed via the _method parameter hack. By default, # Set of request method names allowed via the _method parameter hack. By
# all request methods defined in RFC2616 are included, with the exception of # default, all request methods defined in RFC2616 are included, with the
# TRACE and CONNECT. # exception of TRACE and CONNECT.
POST_TUNNEL_METHODS_ALLOWED = %w( PUT DELETE OPTIONS HEAD ) POST_TUNNEL_METHODS_ALLOWED = %w( PUT DELETE OPTIONS HEAD )
# Return the HTTP request method with support for method tunneling using the POST # Return the HTTP request method with support for method tunneling using
# _method parameter hack. If the real request method is POST and a _method param is # the POST _method parameter hack. If the real request method is POST and
# given and the value is one defined in +POST_TUNNEL_METHODS_ALLOWED+, return the value # a _method param is given and the value is one defined in
# of the _method param instead. # +POST_TUNNEL_METHODS_ALLOWED+, return the value of the _method param
# instead.
def request_method def request_method
if post_tunnel_method_hack? if post_tunnel_method_hack?
params['_method'].upcase params['_method'].upcase
@ -51,17 +52,11 @@ module Rack #:nodoc:
private private
# Return truthfully if and only if the following conditions are met: 1.) the # Return truthfully if the request is a valid verb-over-post hack.
# *actual* request method is POST, 2.) the request content-type is one of
# 'application/x-www-form-urlencoded' or 'multipart/form-data', 3.) there is a
# "_method" parameter in the POST body (not in the query string), and 4.) the
# method parameter is one of the verbs listed in the POST_TUNNEL_METHODS_ALLOWED
# list.
def post_tunnel_method_hack? def post_tunnel_method_hack?
@env['REQUEST_METHOD'] == 'POST' && @env['REQUEST_METHOD'] == 'POST' &&
POST_TUNNEL_METHODS_ALLOWED.include?(self.POST.fetch('_method', '').upcase) POST_TUNNEL_METHODS_ALLOWED.include?(self.POST.fetch('_method', '').upcase)
end end
end end
module Utils module Utils
@ -70,17 +65,11 @@ module Rack #:nodoc:
end end
module Sinatra module Sinatra
extend self extend self
module Version VERSION = '0.3.0'
MAJOR = '0'
MINOR = '2'
REVISION = '3'
def self.combined
[MAJOR, MINOR, REVISION].join('.')
end
end
class NotFound < RuntimeError; end class NotFound < RuntimeError; end
class ServerError < RuntimeError; end class ServerError < RuntimeError; end
@ -130,7 +119,6 @@ module Sinatra
def run def run
begin begin
puts "== Sinatra has taken the stage on port #{port} for #{env} with backup by #{server.name}" puts "== Sinatra has taken the stage on port #{port} for #{env} with backup by #{server.name}"
require 'pp'
server.run(application, {:Port => port, :Host => host}) do |server| server.run(application, {:Port => port, :Host => host}) do |server|
trap(:INT) do trap(:INT) do
server.stop server.stop
@ -215,14 +203,13 @@ module Sinatra
def block def block
Proc.new do Proc.new do
send_file Sinatra.application.options.public + request.path_info.http_unescape, send_file Sinatra.application.options.public +
:disposition => nil request.path_info.http_unescape, :disposition => nil
end end
end end
end end
# Adapted from actionpack
# Methods for sending files and streams to the browser instead of rendering. # Methods for sending files and streams to the browser instead of rendering.
module Streaming module Streaming
DEFAULT_SEND_FILE_OPTIONS = { DEFAULT_SEND_FILE_OPTIONS = {
@ -257,6 +244,7 @@ module Sinatra
end end
protected protected
# Sends the file by streaming it 4096 bytes at a time. This way the # Sends the file by streaming it 4096 bytes at a time. This way the
# whole file doesn't need to be read into memory at once. This makes # whole file doesn't need to be read into memory at once. This makes
# it feasible to send even large files. # it feasible to send even large files.
@ -270,19 +258,22 @@ module Sinatra
# Defaults to File.basename(path). # Defaults to File.basename(path).
# * <tt>:type</tt> - specifies an HTTP content type. # * <tt>:type</tt> - specifies an HTTP content type.
# Defaults to 'application/octet-stream'. # Defaults to 'application/octet-stream'.
# * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded. # * <tt>:disposition</tt> - specifies whether the file will be shown
# Valid values are 'inline' and 'attachment' (default). When set to nil, the # inline or downloaded. Valid values are 'inline' and 'attachment'
# Content-Disposition and Content-Transfer-Encoding headers are omitted entirely. # (default). When set to nil, the Content-Disposition and
# * <tt>:stream</tt> - whether to send the file to the user agent as it is read (true) # Content-Transfer-Encoding headers are omitted entirely.
# or to read the entire file before sending (false). Defaults to true. # * <tt>:stream</tt> - whether to send the file to the user agent as it
# * <tt>:buffer_size</tt> - specifies size (in bytes) of the buffer used to stream the file. # is read (true) or to read the entire file before sending (false).
# Defaults to 4096. # Defaults to true.
# * <tt>:status</tt> - specifies the status code to send with the response. Defaults to '200 OK'. # * <tt>:buffer_size</tt> - specifies size (in bytes) of the buffer used
# * <tt>:last_modified</tt> - an optional RFC 2616 formatted date value (See Time#httpdate) # to stream the file. Defaults to 4096.
# indicating the last modified time of the file. If the request includes an # * <tt>:status</tt> - specifies the status code to send with the
# If-Modified-Since header that matches this value exactly, a 304 Not Modified response # response. Defaults to '200 OK'.
# is sent instead of the file. Defaults to the file's last modified # * <tt>:last_modified</tt> - an optional RFC 2616 formatted date value
# time. # (See Time#httpdate) indicating the last modified time of the file.
# If the request includes an If-Modified-Since header that matches this
# value exactly, a 304 Not Modified response is sent instead of the file.
# Defaults to the file's last modified time.
# #
# The default Content-Type and Content-Disposition headers are # The default Content-Type and Content-Disposition headers are
# set to download arbitrary binary files in as many browsers as # set to download arbitrary binary files in as many browsers as
@ -293,10 +284,14 @@ module Sinatra
# send_file '/path/to.zip' # send_file '/path/to.zip'
# #
# Show a JPEG in the browser: # Show a JPEG in the browser:
# send_file '/path/to.jpeg', :type => 'image/jpeg', :disposition => 'inline' # send_file '/path/to.jpeg',
# :type => 'image/jpeg',
# :disposition => 'inline'
# #
# Show a 404 page in the browser: # Show a 404 page in the browser:
# send_file '/path/to/404.html, :type => 'text/html; charset=utf-8', :status => 404 # send_file '/path/to/404.html,
# :type => 'text/html; charset=utf-8',
# :status => 404
# #
# Read about the other Content-* HTTP headers if you'd like to # Read about the other Content-* HTTP headers if you'd like to
# provide the user with more information (such as Content-Description). # provide the user with more information (such as Content-Description).
@ -325,20 +320,22 @@ module Sinatra
end end
end end
# Send binary data to the user as a file download. May set content type, apparent file name, # Send binary data to the user as a file download. May set content type,
# and specify whether to show data inline or download as an attachment. # apparent file name, and specify whether to show data inline or download
# as an attachment.
# #
# Options: # Options:
# * <tt>:filename</tt> - Suggests a filename for the browser to use. # * <tt>:filename</tt> - Suggests a filename for the browser to use.
# * <tt>:type</tt> - specifies an HTTP content type. # * <tt>:type</tt> - specifies an HTTP content type.
# Defaults to 'application/octet-stream'. # Defaults to 'application/octet-stream'.
# * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded. # * <tt>:disposition</tt> - specifies whether the file will be shown inline
# Valid values are 'inline' and 'attachment' (default). # or downloaded. Valid values are 'inline' and 'attachment' (default).
# * <tt>:status</tt> - specifies the status code to send with the response. Defaults to '200 OK'. # * <tt>:status</tt> - specifies the status code to send with the response.
# * <tt>:last_modified</tt> - an optional RFC 2616 formatted date value (See Time#httpdate) # Defaults to '200 OK'.
# indicating the last modified time of the response entity. If the request includes an # * <tt>:last_modified</tt> - an optional RFC 2616 formatted date value (See
# If-Modified-Since header that matches this value exactly, a 304 Not Modified response # Time#httpdate) indicating the last modified time of the response entity.
# is sent instead of the data. # If the request includes an If-Modified-Since header that matches this
# value exactly, a 304 Not Modified response is sent instead of the data.
# #
# Generic data download: # Generic data download:
# send_data buffer # send_data buffer
@ -347,7 +344,9 @@ module Sinatra
# send_data generate_tgz('dir'), :filename => 'dir.tgz' # send_data generate_tgz('dir'), :filename => 'dir.tgz'
# #
# Display an image Active Record in the browser: # Display an image Active Record in the browser:
# send_data image.data, :type => image.content_type, :disposition => 'inline' # send_data image.data,
# :type => image.content_type,
# :disposition => 'inline'
# #
# See +send_file+ for more information on HTTP Content-* headers and caching. # See +send_file+ for more information on HTTP Content-* headers and caching.
def send_data(data, options = {}) #:doc: def send_data(data, options = {}) #:doc:
@ -356,14 +355,15 @@ module Sinatra
end end
private private
def send_file_headers!(options) def send_file_headers!(options)
options = DEFAULT_SEND_FILE_OPTIONS.merge(options) options = DEFAULT_SEND_FILE_OPTIONS.merge(options)
[:length, :type, :disposition].each do |arg| [:length, :type, :disposition].each do |arg|
raise ArgumentError, ":#{arg} option required" unless options.key?(arg) raise ArgumentError, ":#{arg} option required" unless options.key?(arg)
end end
# Send a "304 Not Modified" if the last_modified option is provided and matches # Send a "304 Not Modified" if the last_modified option is provided and
# the If-Modified-Since request header value. # matches the If-Modified-Since request header value.
if last_modified = options[:last_modified] if last_modified = options[:last_modified]
header 'Last-Modified' => last_modified header 'Last-Modified' => last_modified
throw :halt, [ 304, '' ] if last_modified == request.env['HTTP_IF_MODIFIED_SINCE'] throw :halt, [ 304, '' ] if last_modified == request.env['HTTP_IF_MODIFIED_SINCE']
@ -605,21 +605,24 @@ module Sinatra
private private
def render_haml(content, options = {}, &b) def render_haml(content, options = {}, &b)
haml_options = (options[:options] || {}).merge(Sinatra.options.haml || {}) haml_options = (options[:options] || {}).
::Haml::Engine.new(content, haml_options).render(options[:scope] || self, options[:locals] || {}, &b) merge(Sinatra.options.haml || {})
::Haml::Engine.new(content, haml_options).
render(options[:scope] || self, options[:locals] || {}, &b)
end end
end end
# Generate valid CSS using Sass (part of Haml) # Generate valid CSS using Sass (part of Haml)
# #
# Sass templates can be in external files with <tt>.sass</tt> extension or can use Sinatra's # Sass templates can be in external files with <tt>.sass</tt> extension
# in_file_templates. In either case, the file can be rendered by passing the name of # or can use Sinatra's in_file_templates. In either case, the file can
# the template to the +sass+ method as a symbol. # be rendered by passing the name of the template to the +sass+ method
# as a symbol.
# #
# Unlike Haml, Sass does not support a layout file, so the +sass+ method will ignore both # Unlike Haml, Sass does not support a layout file, so the +sass+ method
# the default <tt>layout.sass</tt> file and any parameters passed in as <tt>:layout</tt> in # will ignore both the default <tt>layout.sass</tt> file and any parameters
# the options hash. # passed in as <tt>:layout</tt> in the options hash.
# #
# === Sass Template Files # === Sass Template Files
# #
@ -659,8 +662,6 @@ module Sinatra
# attempt is made to render a Sass template. # attempt is made to render a Sass template.
# #
# See http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html for comprehensive documentation on Sass. # See http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html for comprehensive documentation on Sass.
module Sass module Sass
def sass(content, options = {}) def sass(content, options = {})
@ -677,18 +678,19 @@ module Sinatra
def render_sass(content, options = {}) def render_sass(content, options = {})
::Sass::Engine.new(content).render ::Sass::Engine.new(content).render
end end
end end
# Generating conservative XML content using Builder templates. # Generating conservative XML content using Builder templates.
# #
# Builder templates can be inline by passing a block to the builder method, or in # Builder templates can be inline by passing a block to the builder method,
# external files with +.builder+ extension by passing the name of the template # or in external files with +.builder+ extension by passing the name of the
# to the +builder+ method as a Symbol. # template to the +builder+ method as a Symbol.
# #
# === Inline Rendering # === Inline Rendering
# #
# If the builder method is given a block, the block is called directly with an # If the builder method is given a block, the block is called directly with
# +XmlMarkup+ instance and the result is returned as String: # an +XmlMarkup+ instance and the result is returned as String:
# get '/who.xml' do # get '/who.xml' do
# builder do |xml| # builder do |xml|
# xml.instruct! # xml.instruct!
@ -710,8 +712,8 @@ module Sinatra
# === Builder Template Files # === Builder Template Files
# #
# Builder templates can be stored in separate files with a +.builder+ # Builder templates can be stored in separate files with a +.builder+
# extension under the view path. An +XmlMarkup+ object named +xml+ is automatically # extension under the view path. An +XmlMarkup+ object named +xml+ is
# made available to template. # automatically made available to template.
# #
# Example: # Example:
# get '/bio.xml' do # get '/bio.xml' do
@ -742,10 +744,11 @@ module Sinatra
# <died age='82' /> # <died age='82' />
# </person> # </person>
# #
# NOTE: Builder must be installed or a LoadError will be raised the first time an # NOTE: Builder must be installed or a LoadError will be raised the first
# attempt is made to render a builder template. # time an attempt is made to render a builder template.
# #
# See http://builder.rubyforge.org/ for comprehensive documentation on Builder. # See http://builder.rubyforge.org/ for comprehensive documentation on
# Builder.
module Builder module Builder
def builder(content=nil, options={}, &block) def builder(content=nil, options={}, &block)
@ -1043,7 +1046,6 @@ module Sinatra
errors[NotFound].invoke(request) errors[NotFound].invoke(request)
end end
# Define a named template. The template may be referenced from # Define a named template. The template may be referenced from
# event handlers by passing the name as a Symbol to rendering # event handlers by passing the name as a Symbol to rendering
# methods. The block is executed each time the template is rendered # methods. The block is executed each time the template is rendered
@ -1259,18 +1261,8 @@ module Sinatra
not_found do not_found do
%Q( %Q(
<style> <style>
body { body { text-align:center;color:#888;font-family:arial;font-size:22px;margin:20px; }
text-align: center; #content { margin:0 auto;width:500px;text-align:left}
color: #888;
font-family: Arial;
font-size: 22px;
margin: 20px;
}
#content {
margin: 0 auto;
width: 500px;
text-align: left;
}
</style> </style>
<html> <html>
<body> <body>
@ -1278,9 +1270,7 @@ module Sinatra
<img src='/sinatra_custom_images/404.png'></img> <img src='/sinatra_custom_images/404.png'></img>
<div id="content"> <div id="content">
Try this: Try this:
<pre>#{request.request_method.downcase} "#{request.path_info}" do <pre>#{request.request_method.downcase} "#{request.path_info}" do\n .. do something ..\n end<pre>
.. do something ..
end<pre>
</div> </div>
</body> </body>
</html> </html>
@ -1289,39 +1279,16 @@ end<pre>
error do error do
@error = request.env['sinatra.error'] @error = request.env['sinatra.error']
%Q( (<<-HTML).sub(/ {12}/, '')
<html> <html>
<body> <body>
<style type="text/css" media="screen"> <style type="text/css" media="screen">
body { body {font-family:verdana;color: #333}
font-family: Verdana; #content {width:700px;margin-left:20px}
color: #333; #content h1 {width:99%;color:#1D6B8D;font-weight:bold}
} #stacktrace {margin-top:-20px}
#stacktrace pre {font-size:12px;border-left:2px solid #ddd;padding-left: 10px}
#content { #stacktrace img {margin-top: 10px}
width: 700px;
margin-left: 20px;
}
#content h1 {
width: 99%;
color: #1D6B8D;
font-weight: bold;
}
#stacktrace {
margin-top: -20px;
}
#stacktrace pre {
font-size: 12px;
border-left: 2px solid #ddd;
padding-left: 10px;
}
#stacktrace img {
margin-top: 10px;
}
</style> </style>
<div id="content"> <div id="content">
<img src="/sinatra_custom_images/500.png" /> <img src="/sinatra_custom_images/500.png" />
@ -1334,7 +1301,7 @@ end<pre>
</div> </div>
</body> </body>
</html> </html>
) HTML
end end
end end
end end
@ -1381,14 +1348,12 @@ end
### Misc Core Extensions ### Misc Core Extensions
module Kernel module Kernel
def silence_warnings def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil old_verbose, $VERBOSE = $VERBOSE, nil
yield yield
ensure ensure
$VERBOSE = old_verbose $VERBOSE = old_verbose
end end
end end
class String class String
@ -1410,47 +1375,36 @@ class String
end end
class Hash class Hash
def to_params def to_params
map { |k,v| "#{k}=#{URI.escape(v)}" }.join('&') map { |k,v| "#{k}=#{URI.escape(v)}" }.join('&')
end end
def symbolize_keys def symbolize_keys
self.inject({}) { |h,(k,v)| h[k.to_sym] = v; h } self.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
end end
def pass(*keys) def pass(*keys)
reject { |k,v| !keys.include?(k) } reject { |k,v| !keys.include?(k) }
end end
end end
class Symbol class Symbol
def to_proc def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) } Proc.new { |*args| args.shift.__send__(self, *args) }
end end
end end
class Array class Array
def to_hash def to_hash
self.inject({}) { |h, (k, v)| h[k] = v; h } self.inject({}) { |h, (k, v)| h[k] = v; h }
end end
def to_proc def to_proc
Proc.new { |*args| args.shift.__send__(self[0], *(args + self[1..-1])) } Proc.new { |*args| args.shift.__send__(self[0], *(args + self[1..-1])) }
end end
end end
module Enumerable module Enumerable
def eject(&block) def eject(&block)
find { |e| result = block[e] and break result } find { |e| result = block[e] and break result }
end end
end end
### Core Extension results for throw :halt ### Core Extension results for throw :halt

View File

@ -60,8 +60,3 @@ context "Custom Errors (in general)" do
end end
end end

View File

@ -1,5 +1,6 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
# XXX: How does any of this have anything to do with REST?
context "RESTful tests" do context "RESTful tests" do
specify "should take xml" do specify "should take xml" do

View File

@ -33,7 +33,6 @@ context "Rendering in file templates" do
assert_equal "X\nthis is foo\nX\n", body assert_equal "X\nthis is foo\nX\n", body
end end
end end
__END__ __END__