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

View File

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

View File

@ -1,5 +1,6 @@
require File.dirname(__FILE__) + '/helper'
# XXX: How does any of this have anything to do with REST?
context "RESTful tests" 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
end
end
__END__