sinatra 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/CHANGES +38 -1
- data/Gemfile +17 -9
- data/README.de.rdoc +2 -2
- data/README.es.rdoc +60 -30
- data/README.fr.rdoc +2 -1
- data/README.jp.rdoc +1 -0
- data/README.rdoc +52 -23
- data/README.ru.rdoc +2 -2
- data/README.zh.rdoc +1 -0
- data/Rakefile +4 -0
- data/examples/chat.rb +61 -0
- data/examples/simple.rb +3 -0
- data/examples/stream.ru +26 -0
- data/lib/sinatra/base.rb +55 -42
- data/lib/sinatra/main.rb +5 -5
- data/lib/sinatra/version.rb +1 -1
- data/sinatra.gemspec +2 -2
- data/test/coffee_test.rb +2 -2
- data/test/filter_test.rb +20 -0
- data/test/helper.rb +5 -1
- data/test/helpers_test.rb +10 -0
- data/test/integration/app.rb +6 -0
- data/test/integration_test.rb +65 -0
- data/test/less_test.rb +3 -3
- data/test/rdoc_test.rb +3 -2
- data/test/static_test.rb +0 -1
- data/test/streaming_test.rb +8 -0
- metadata +22 -13
data/CHANGES
CHANGED
@@ -1,8 +1,38 @@
|
|
1
|
-
= 1.3.
|
1
|
+
= 1.3.2 / 2011-12-30
|
2
|
+
|
3
|
+
* Don't automatically add `Rack::CommonLogger` if `Rack::Server` is adding it,
|
4
|
+
too. (Konstantin Haase)
|
5
|
+
|
6
|
+
* Setting `logging` to `nil` will avoid setting up `Rack::NullLogger`.
|
7
|
+
(Konstantin Haase)
|
8
|
+
|
9
|
+
* Route specific params are now available in the block passed to #stream.
|
10
|
+
(Konstantin Haase)
|
11
|
+
|
12
|
+
* Fix bug where rendering a second template in the same request, after the
|
13
|
+
first one raised an exception, skipped the default layout. (Nathan Baum)
|
14
|
+
|
15
|
+
* Fix bug where parameter escaping got enabled when disabling a different
|
16
|
+
protection. (Konstantin Haase)
|
17
|
+
|
18
|
+
* Fix regression: Filters without a pattern may now again manipulate the params
|
19
|
+
hash. (Konstantin Haase)
|
20
|
+
|
21
|
+
* Added examples directory. (Konstantin Haase)
|
22
|
+
|
23
|
+
* Improved documentation. (Gabriel Andretta, Markus Prinz, Erick Zetta, Just
|
24
|
+
Lest, Adam Vaughan, Aleksander Dąbrowski)
|
25
|
+
|
26
|
+
* Improved MagLev support. (Tim Felgentreff)
|
27
|
+
|
28
|
+
= 1.3.1 / 2011-10-05
|
2
29
|
|
3
30
|
* Support adding more than one callback to the stream object. (Konstantin
|
4
31
|
Haase)
|
5
32
|
|
33
|
+
* Fix for infinite loop when streaming on 1.9.2 with Thin from a modular
|
34
|
+
application (Konstantin Haase)
|
35
|
+
|
6
36
|
= 1.3.0 / 2011-09-30
|
7
37
|
|
8
38
|
* Added `stream` helper method for easily creating streaming APIs, Server
|
@@ -130,6 +160,13 @@
|
|
130
160
|
* Fix handling of broken query params when displaying exceptions. (Luke
|
131
161
|
Jahnke)
|
132
162
|
|
163
|
+
= 1.2.8 (backports release) / 2011-12-30
|
164
|
+
|
165
|
+
Backported from 1.3.2:
|
166
|
+
|
167
|
+
* Fix bug where rendering a second template in the same request after the
|
168
|
+
first one raised an exception skipped the default layout (Nathan Baum)
|
169
|
+
|
133
170
|
= 1.2.7 (backports release) / 2011-09-30
|
134
171
|
|
135
172
|
Custom changes:
|
data/Gemfile
CHANGED
@@ -17,11 +17,14 @@ gem 'ci_reporter', :group => :ci
|
|
17
17
|
# Allows stuff like `tilt=1.2.2 bundle install` or `tilt=master ...`.
|
18
18
|
# Used by the CI.
|
19
19
|
github = "git://github.com/%s.git"
|
20
|
-
repos
|
20
|
+
repos = {'tilt' => github % "rtomayko/tilt", 'rack' => github % "rack/rack"}
|
21
|
+
|
21
22
|
%w[tilt rack].each do |lib|
|
22
|
-
dep =
|
23
|
-
|
24
|
-
|
23
|
+
dep = case ENV[lib]
|
24
|
+
when 'stable', nil then nil
|
25
|
+
when /(\d+\.)+\d+/ then "~> " + ENV[lib].sub("#{lib}-", '')
|
26
|
+
else {:git => repos[lib], :branch => dep}
|
27
|
+
end
|
25
28
|
gem lib, dep
|
26
29
|
end
|
27
30
|
|
@@ -29,16 +32,16 @@ gem 'haml', '>= 3.0'
|
|
29
32
|
gem 'sass'
|
30
33
|
gem 'builder'
|
31
34
|
gem 'erubis'
|
32
|
-
gem 'less', '~> 2.0'
|
33
35
|
gem 'liquid'
|
34
36
|
gem 'slim', '~> 1.0'
|
35
37
|
gem 'temple', '!= 0.3.3'
|
36
|
-
gem 'RedCloth' if RUBY_VERSION < "1.9.3" and not RUBY_ENGINE.start_with? 'ma'
|
37
38
|
gem 'coffee-script', '>= 2.0'
|
38
39
|
gem 'rdoc'
|
39
40
|
gem 'kramdown'
|
40
41
|
gem 'maruku'
|
41
42
|
gem 'creole'
|
43
|
+
gem 'markaby'
|
44
|
+
gem 'radius'
|
42
45
|
|
43
46
|
if RUBY_ENGINE == 'jruby'
|
44
47
|
gem 'nokogiri', '!= 1.5.0'
|
@@ -47,10 +50,17 @@ else
|
|
47
50
|
gem 'nokogiri'
|
48
51
|
end
|
49
52
|
|
53
|
+
if RUBY_ENGINE == "ruby"
|
54
|
+
gem 'less', '~> 2.0'
|
55
|
+
else
|
56
|
+
gem 'less', '~> 1.0'
|
57
|
+
end
|
58
|
+
|
50
59
|
unless RUBY_ENGINE == 'jruby' && JRUBY_VERSION < "1.6.1" && !ENV['TRAVIS']
|
51
60
|
# C extensions
|
52
61
|
gem 'rdiscount'
|
53
|
-
gem 'redcarpet'
|
62
|
+
platforms(:ruby_18) { gem 'redcarpet' }
|
63
|
+
gem 'RedCloth' unless RUBY_ENGINE == "macruby"
|
54
64
|
|
55
65
|
## bluecloth is broken
|
56
66
|
#gem 'bluecloth'
|
@@ -58,8 +68,6 @@ end
|
|
58
68
|
|
59
69
|
platforms :ruby_18, :jruby do
|
60
70
|
gem 'json'
|
61
|
-
gem 'markaby'
|
62
|
-
gem 'radius'
|
63
71
|
end
|
64
72
|
|
65
73
|
platforms :mri_18 do
|
data/README.de.rdoc
CHANGED
@@ -1953,9 +1953,9 @@ SemVer und SemVerTag.
|
|
1953
1953
|
* {Mailing-Liste}[http://groups.google.com/group/sinatrarb]
|
1954
1954
|
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] auf http://freenode.net
|
1955
1955
|
* {Sinatra Book}[http://sinatra-book.gittr.com] Kochbuch Tutorial
|
1956
|
-
* {Sinatra
|
1956
|
+
* {Sinatra Recipes}[http://recipes.sinatrarb.com/] Sinatra-Rezepte aus
|
1957
1957
|
der Community
|
1958
1958
|
* API Dokumentation für die {aktuelle Version}[http://rubydoc.info/gems/sinatra]
|
1959
1959
|
oder für {HEAD}[http://rubydoc.info/github/sinatra/sinatra] auf
|
1960
1960
|
http://rubydoc.info
|
1961
|
-
* {CI Server}[http://ci.rkh.im/view/Sinatra/]
|
1961
|
+
* {CI Server}[http://ci.rkh.im/view/Sinatra/]
|
data/README.es.rdoc
CHANGED
@@ -874,7 +874,7 @@ número de peticiones concurrentes, depende del servidor web utilizado para
|
|
874
874
|
servir la aplicación. Puede que algunos servidores, como es el caso de
|
875
875
|
WEBRick, no soporten streaming directamente, así el cuerpo de la respuesta será
|
876
876
|
enviado completamente de una vez cuando el bloque pasado a +stream+ finalice su
|
877
|
-
ejecución.
|
877
|
+
ejecución. Si estás usando Shotgun, el streaming no va a funcionar.
|
878
878
|
|
879
879
|
Cuando se pasa +keep_open+ como parámetro, no se va a enviar el mensaje
|
880
880
|
+close+ al objeto de stream. Queda en vos cerrarlo en el punto de ejecución
|
@@ -916,11 +916,16 @@ para <tt>Sinatra::Application</tt>. Si heredaste de
|
|
916
916
|
<tt>Sinatra::Base</tt>, probablemente quieras habilitarlo manualmente:
|
917
917
|
|
918
918
|
class MiApp < Sinatra::Base
|
919
|
-
configure
|
919
|
+
configure :production, :development do
|
920
920
|
enable :logging
|
921
921
|
end
|
922
922
|
end
|
923
923
|
|
924
|
+
Para evitar que se inicialice cualquier middleware de logging, configurá
|
925
|
+
+logging+ a +nil+. Tené en cuenta que, cuando hagas esto, +logger+ va a
|
926
|
+
devolver +nil+. Un caso común es cuando querés usar tu propio logger. Sinatra
|
927
|
+
va a usar lo que encuentre en <tt>env['rack.logger']</tt>.
|
928
|
+
|
924
929
|
=== Tipos Mime
|
925
930
|
|
926
931
|
Cuando usás <tt>send_file</tt> o archivos estáticos tal vez tengas tipos mime
|
@@ -1300,7 +1305,7 @@ Podés acceder a estas opciones utilizando el método <tt>settings</tt>:
|
|
1300
1305
|
...
|
1301
1306
|
end
|
1302
1307
|
|
1303
|
-
|
1308
|
+
=== Configurando la Protección de Ataques
|
1304
1309
|
|
1305
1310
|
Sinatra usa {Rack::Protection}[https://github.com/rkh/rack-protection#readme]
|
1306
1311
|
para defender a tu aplicación de los ataques más comunes. Tenés que tener en
|
@@ -1316,7 +1321,7 @@ También es posible desactivar una única capa de defensa:
|
|
1316
1321
|
|
1317
1322
|
O varias:
|
1318
1323
|
|
1319
|
-
set :
|
1324
|
+
set :protection, :except => [:path_traversal, :session_hijacking]
|
1320
1325
|
|
1321
1326
|
=== Configuraciones Disponibles
|
1322
1327
|
|
@@ -1340,9 +1345,9 @@ O varias:
|
|
1340
1345
|
|
1341
1346
|
settings.add_charsets << "application/foobar"
|
1342
1347
|
|
1343
|
-
[app_file] archivo principal de la aplicación, se utiliza
|
1344
|
-
detectar la raíz del proyecto, el directorio de las
|
1345
|
-
vistas y el público así como las plantillas inline.
|
1348
|
+
[app_file] path del archivo principal de la aplicación, se utiliza
|
1349
|
+
para detectar la raíz del proyecto, el directorio de las
|
1350
|
+
vistas y el público, así como las plantillas inline.
|
1346
1351
|
|
1347
1352
|
[bind] dirección IP que utilizará el servidor integrado (por
|
1348
1353
|
defecto: 0.0.0.0).
|
@@ -1382,15 +1387,24 @@ O varias:
|
|
1382
1387
|
sección sobre la configuración de protección de ataques
|
1383
1388
|
más arriba.
|
1384
1389
|
|
1385
|
-
[public_folder] directorio desde donde se sirven los archivos
|
1390
|
+
[public_folder] path del directorio desde donde se sirven los archivos
|
1391
|
+
públicos. Solo se utiliza cuando se sirven archivos
|
1392
|
+
estáticos (ver la opción <tt>static</tt>). Si no
|
1393
|
+
está presente, se infiere del valor de la opción
|
1394
|
+
<tt>app_file</tt>.
|
1386
1395
|
|
1387
1396
|
[reload_templates] define si se recargan las plantillas entre peticiones.
|
1388
1397
|
|
1389
1398
|
Se encuentra activado en el entorno de desarrollo.
|
1390
1399
|
|
1391
|
-
[root] directorio raíz del proyecto.
|
1400
|
+
[root] path del directorio raíz del proyecto. Si no está
|
1401
|
+
presente, se infiere del valor de la opción
|
1402
|
+
<tt>app_file</tt>.
|
1392
1403
|
|
1393
|
-
[raise_errors] elevar excepciones (detiene la aplicación).
|
1404
|
+
[raise_errors] elevar excepciones (detiene la aplicación). Se
|
1405
|
+
encuentra activada por defecto cuando el valor de
|
1406
|
+
<tt>environment</tt> es <tt>"test"</tt>. En caso
|
1407
|
+
contrario estará desactivada.
|
1394
1408
|
|
1395
1409
|
[run] cuando está habilitada, Sinatra se va a encargar de
|
1396
1410
|
iniciar el servidor web, no la habilités cuando estés
|
@@ -1403,9 +1417,14 @@ O varias:
|
|
1403
1417
|
integrado. Por defecto: ['thin', 'mongrel', 'webrick'],
|
1404
1418
|
el orden establece la prioridad.
|
1405
1419
|
|
1406
|
-
[sessions] habilita sesiones basadas en cookies
|
1420
|
+
[sessions] habilita el soporte de sesiones basadas en cookies a
|
1421
|
+
través de <tt>Rack::Session::Cookie</tt>. Ver la
|
1422
|
+
sección 'Usando Sesiones' para más información.
|
1407
1423
|
|
1408
|
-
[show_exceptions] muestra un stack trace en el navegador
|
1424
|
+
[show_exceptions] muestra un stack trace en el navegador cuando ocurre una
|
1425
|
+
excepción. Se encuentra activada por defecto cuando el
|
1426
|
+
valor de <tt>environment</tt> es <tt>"development"</tt>.
|
1427
|
+
En caso contrario estará desactivada.
|
1409
1428
|
|
1410
1429
|
[static] define si Sinatra debe encargarse de servir archivos
|
1411
1430
|
estáticos.
|
@@ -1424,7 +1443,9 @@ O varias:
|
|
1424
1443
|
utilizar un array cuando se asignan múltiples valores:
|
1425
1444
|
<tt>set :static_cache_control, [:public, :max_age => 300]</tt>.
|
1426
1445
|
|
1427
|
-
[views] directorio de las vistas.
|
1446
|
+
[views] path del directorio de las vistas. Si no está presente,
|
1447
|
+
se infiere del valor de la opción <tt>app_file</tt>.
|
1448
|
+
|
1428
1449
|
|
1429
1450
|
== Manejo de Errores
|
1430
1451
|
|
@@ -1882,22 +1903,31 @@ Las siguientes versiones de Ruby son soportadas oficialmente:
|
|
1882
1903
|
ya no se corregirán errores por más que se reciban reportes de los mismos.
|
1883
1904
|
|
1884
1905
|
[ Ruby 1.9.2 ]
|
1885
|
-
1.9.2 es soportado y recomendado. Tené en cuenta que Radius y Markaby no
|
1886
|
-
|
1887
|
-
fallos de segmentación cuando se ejecuta Sinatra.
|
1906
|
+
1.9.2 es soportado y recomendado. Tené en cuenta que Radius y Markaby no son
|
1907
|
+
compatibles con 1.9 actualmente. Además, no usés 1.9.2p0, porque se producen
|
1908
|
+
fallos de segmentación cuando se ejecuta Sinatra. El soporte se mantendrá al
|
1909
|
+
menos hasta que se libere la versión 1.9.4/2.0 de Ruby. El soporte para la
|
1910
|
+
última versión de la serie 1.9 se mantendrá mientras lo haga el core team de
|
1911
|
+
Ruby.
|
1912
|
+
|
1913
|
+
[ Ruby 1.9.3 ]
|
1914
|
+
1.9.3 es soportado completamente. De todas maneras, recomendamos esperar a
|
1915
|
+
que se liberen niveles de parche superiores (el actual es p0) antes de usarlo
|
1916
|
+
en producción. Es importante notar que el cambio desde una versión anterior a
|
1917
|
+
1.9.3 va a invalidar todas las sesiones.
|
1888
1918
|
|
1889
1919
|
[ Rubinius ]
|
1890
|
-
Rubinius es soportado oficialmente (Rubinius >= 1.2.4). Todo
|
1891
|
-
|
1920
|
+
Rubinius es soportado oficialmente (Rubinius >= 1.2.4). Todo funciona
|
1921
|
+
correctamente, incluyendo los lenguajes de plantillas. La próxima versión,
|
1922
|
+
2.0, también es soportada.
|
1892
1923
|
|
1893
1924
|
[ JRuby ]
|
1894
|
-
JRuby es soportado oficialmente (JRuby >= 1.6.
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
se ven afectadas.
|
1925
|
+
JRuby es soportado oficialmente (JRuby >= 1.6.5). No se conocen problemas
|
1926
|
+
con librerías de plantillas de terceras partes. Sin embargo, si elegís usar
|
1927
|
+
JRuby, deberías examinar sus Rack handlers porque el servidor web Thin no es
|
1928
|
+
soportado completamente. El soporte de JRuby para extensiones C se encuentra
|
1929
|
+
en una etapa experimental, sin embargo, de momento solamente RDiscount,
|
1930
|
+
Redcarpet y RedCloth se ven afectadas.
|
1901
1931
|
|
1902
1932
|
Siempre le prestamos atención a las nuevas versiones de Ruby.
|
1903
1933
|
|
@@ -1913,10 +1943,10 @@ No estar soportada oficialmente, significa que si las cosas solamente se rompen
|
|
1913
1943
|
ahí y no en una plataforma soportada, asumimos que no es nuestro problema sino
|
1914
1944
|
el suyo.
|
1915
1945
|
|
1916
|
-
Nuestro servidor CI también se ejecuta sobre ruby-head (que será la
|
1917
|
-
|
1918
|
-
garantizar nada. De todas formas, podés contar con que 1.9.4-p0
|
1919
|
-
|
1946
|
+
Nuestro servidor CI también se ejecuta sobre ruby-head (que será la próxima
|
1947
|
+
versión 2.0.0) y la rama 1.9.4. Como están en movimiento constante, no podemos
|
1948
|
+
garantizar nada. De todas formas, podés contar con que tanto 1.9.4-p0 como
|
1949
|
+
2.0.0-p0 sea soportadas.
|
1920
1950
|
|
1921
1951
|
Sinatra debería funcionar en cualquier sistema operativo soportado por la
|
1922
1952
|
implementación de Ruby elegida.
|
@@ -2004,7 +2034,7 @@ siguiendo las especificaciones SemVer y SemVerTag.
|
|
2004
2034
|
* {Lista de Correo}[http://groups.google.com/group/sinatrarb/topics]
|
2005
2035
|
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] en http://freenode.net
|
2006
2036
|
* {Sinatra Book}[http://sinatra-book.gittr.com] Tutorial (en inglés).
|
2007
|
-
* {Sinatra
|
2037
|
+
* {Sinatra Recipes}[http://recipes.sinatrarb.com/] Recetas contribuidas
|
2008
2038
|
por la comunidad (en inglés).
|
2009
2039
|
* Documentación de la API para la
|
2010
2040
|
{última versión liberada}[http://rubydoc.info/gems/sinatra] o para la
|
data/README.fr.rdoc
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
= Sinatra
|
2
|
+
|
2
3
|
<i>Attention : Ce document correspond à la traduction de la version anglaise et
|
3
4
|
il n'est peut être plus à jour.</i>
|
4
5
|
|
@@ -1974,7 +1975,7 @@ SemVer que SemVerTag.
|
|
1974
1975
|
* {IRC : #sinatra}[irc://chat.freenode.net/#sinatra] sur http://freenode.net
|
1975
1976
|
* {IRC : #sinatra}[irc://chat.freenode.net/#sinatra] on http://freenode.net
|
1976
1977
|
* {Sinatra Book}[http://sinatra-book.gittr.com] Tutoriels et recettes
|
1977
|
-
* {Sinatra
|
1978
|
+
* {Sinatra Recipes}[http://recipes.sinatrarb.com/] Recettes contribuées
|
1978
1979
|
par la communauté
|
1979
1980
|
* Documentation API de la {dernière version}[http://rubydoc.info/gems/sinatra]
|
1980
1981
|
ou du {HEAD courant}[http://rubydoc.info/github/sinatra/sinatra] sur
|
data/README.jp.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -264,7 +264,7 @@ Instead of a template name, you can also just pass in the template content
|
|
264
264
|
directly:
|
265
265
|
|
266
266
|
get '/' do
|
267
|
-
code = "<%= Time.now
|
267
|
+
code = "<%= Time.now %>"
|
268
268
|
erb code
|
269
269
|
end
|
270
270
|
|
@@ -846,7 +846,7 @@ Note that the streaming behavior, especially the number of concurrent request,
|
|
846
846
|
highly depends on the web server used to serve the application. Some servers,
|
847
847
|
like WEBRick, might not even support streaming at all. If the server does not
|
848
848
|
support streaming, the body will be sent all at once after the block passed to
|
849
|
-
+stream+ finished executing.
|
849
|
+
+stream+ finished executing. Streaming does not work at all with Shotgun.
|
850
850
|
|
851
851
|
If the optional parameter is set to +keep_open+, it will not call +close+ on
|
852
852
|
the stream object, allowing you to close it at any later point in the
|
@@ -885,11 +885,16 @@ default, so if you inherit from <tt>Sinatra::Base</tt>, you probably want to
|
|
885
885
|
enable it yourself:
|
886
886
|
|
887
887
|
class MyApp < Sinatra::Base
|
888
|
-
configure
|
888
|
+
configure :production, :development do
|
889
889
|
enable :logging
|
890
890
|
end
|
891
891
|
end
|
892
892
|
|
893
|
+
To avoid any logging middleware to be set up, set the +logging+ setting to
|
894
|
+
+nil+. However, keep in mind that +logger+ will in that case return +nil+. A
|
895
|
+
common use case is when you want to set your own logger. Sinatra will use
|
896
|
+
whatever it will find in <tt>env['rack.logger']</tt>.
|
897
|
+
|
893
898
|
=== Mime Types
|
894
899
|
|
895
900
|
When using <tt>send_file</tt> or static files you may have mime types Sinatra
|
@@ -1273,7 +1278,7 @@ To skip a single defense layer, set +protection+ to an options hash:
|
|
1273
1278
|
|
1274
1279
|
You can also hand in an array in order to disable a list of protections:
|
1275
1280
|
|
1276
|
-
set :
|
1281
|
+
set :protection, :except => [:path_traversal, :session_hijacking]
|
1277
1282
|
|
1278
1283
|
=== Available Settings
|
1279
1284
|
|
@@ -1295,7 +1300,7 @@ You can also hand in an array in order to disable a list of protections:
|
|
1295
1300
|
|
1296
1301
|
settings.add_charsets << "application/foobar"
|
1297
1302
|
|
1298
|
-
[app_file] main application file, used to detect project root,
|
1303
|
+
[app_file] Path to the main application file, used to detect project root,
|
1299
1304
|
views and public folder and inline templates.
|
1300
1305
|
|
1301
1306
|
[bind] IP address to bind to (default: 0.0.0.0).
|
@@ -1322,7 +1327,7 @@ You can also hand in an array in order to disable a list of protections:
|
|
1322
1327
|
|
1323
1328
|
[port] Port to listen on. Only used for built-in server.
|
1324
1329
|
|
1325
|
-
[prefixed_redirects] Whether or not to insert <tt>request.script_name</tt>
|
1330
|
+
[prefixed_redirects] Whether or not to insert <tt>request.script_name</tt>
|
1326
1331
|
into redirects if no absolute path is given. That way
|
1327
1332
|
<tt>redirect '/foo'</tt> would behave like
|
1328
1333
|
<tt>redirect to('/foo')</tt>. Disabled per default.
|
@@ -1330,14 +1335,20 @@ You can also hand in an array in order to disable a list of protections:
|
|
1330
1335
|
[protection] Whether or not to enable web attack protections. See
|
1331
1336
|
protection section above.
|
1332
1337
|
|
1333
|
-
[public_folder] folder public files are served from
|
1338
|
+
[public_folder] Path to the folder public files are served from. Only
|
1339
|
+
used if static file serving is enabled (see
|
1340
|
+
<tt>static</tt> setting below). Inferred from
|
1341
|
+
<tt>app_file</tt> setting if not set.
|
1334
1342
|
|
1335
1343
|
[reload_templates] whether or not to reload templates between requests.
|
1336
1344
|
Enabled in development mode.
|
1337
1345
|
|
1338
|
-
[root] project root folder.
|
1346
|
+
[root] Path to project root folder. Inferred from +app_file+
|
1347
|
+
setting if not set.
|
1339
1348
|
|
1340
|
-
[raise_errors] raise exceptions (will stop application).
|
1349
|
+
[raise_errors] raise exceptions (will stop application). Enabled
|
1350
|
+
by default when <tt>environment</tt> is set to <tt>"test"</tt>,
|
1351
|
+
disabled otherwise.
|
1341
1352
|
|
1342
1353
|
[run] if enabled, Sinatra will handle starting the web server,
|
1343
1354
|
do not enable if using rackup or other means.
|
@@ -1346,12 +1357,16 @@ You can also hand in an array in order to disable a list of protections:
|
|
1346
1357
|
do not change this setting!
|
1347
1358
|
|
1348
1359
|
[server] server or list of servers to use for built-in server.
|
1349
|
-
defaults to ['thin', 'mongrel', 'webrick'], order
|
1360
|
+
defaults to ['thin', 'mongrel', 'webrick'], order
|
1350
1361
|
indicates priority.
|
1351
1362
|
|
1352
|
-
[sessions] enable cookie based sessions
|
1363
|
+
[sessions] enable cookie based sessions support using
|
1364
|
+
<tt>Rack::Session::Cookie</tt>. See 'Using Sessions'
|
1365
|
+
section for more information.
|
1353
1366
|
|
1354
|
-
[show_exceptions] show a stack trace in the browser
|
1367
|
+
[show_exceptions] show a stack trace in the browser when an exception
|
1368
|
+
happens. Enabled by default when <tt>environment</tt>
|
1369
|
+
is set to <tt>"development"</tt>, disabled otherwise.
|
1355
1370
|
|
1356
1371
|
[static] Whether Sinatra should handle serving static files.
|
1357
1372
|
Disable when using a Server able to do this on its own.
|
@@ -1368,7 +1383,20 @@ You can also hand in an array in order to disable a list of protections:
|
|
1368
1383
|
[threaded] If set to +true+, will tell Thin to use
|
1369
1384
|
<tt>EventMachine.defer</tt> for processing the request.
|
1370
1385
|
|
1371
|
-
[views] views folder.
|
1386
|
+
[views] Path to the views folder. Inferred from <tt>app_file</tt>
|
1387
|
+
setting if not set.
|
1388
|
+
|
1389
|
+
== Environments
|
1390
|
+
|
1391
|
+
There are three predefined +environments+: <tt>development</tt>, <tt>production</tt> and <tt>test</tt>. Environment can be set by RACK_ENV environment variable, and default value is <tt>development</tt>.
|
1392
|
+
|
1393
|
+
You can also run different environemnt using <tt>-e</tt> option:
|
1394
|
+
|
1395
|
+
ruby my_app.rb -e [ENVIRONMENT]
|
1396
|
+
|
1397
|
+
You can use predefinied methods: +development?+, +test?+ and +production?+, to check which enviroment is set.
|
1398
|
+
|
1399
|
+
+Developemnt+ is default setting. In this mode, all templates are being reloaded between requests. Special <tt>not_found</tt> and <tt>error</tt> handlers are installed for this enviroment, so you will see nice error page. In +production+ and +test+ templates are being cached.
|
1372
1400
|
|
1373
1401
|
== Error Handling
|
1374
1402
|
|
@@ -1824,20 +1852,21 @@ The following Ruby versions are officially supported:
|
|
1824
1852
|
will continue as long as it is still supported by the Ruby core team.
|
1825
1853
|
|
1826
1854
|
[ Ruby 1.9.3 ]
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1855
|
+
1.9.3 is fully supported. We recommend waiting for higher patch levels to be
|
1856
|
+
released (current one is p0) before using it in production. Please note that
|
1857
|
+
switching to 1.9.3 from an earlier version will invalidate all sessions.
|
1830
1858
|
|
1831
1859
|
[ Rubinius ]
|
1832
1860
|
Rubinius is officially supported (Rubinius >= 1.2.4), everything, including
|
1833
|
-
all template languages, works.
|
1861
|
+
all template languages, works. The upcoming 2.0 release is supported as
|
1862
|
+
well.
|
1834
1863
|
|
1835
1864
|
[ JRuby ]
|
1836
|
-
JRuby is officially supported (JRuby >= 1.6.
|
1865
|
+
JRuby is officially supported (JRuby >= 1.6.5). No issues with third party
|
1837
1866
|
template libraries are known, however, if you choose to use JRuby, please
|
1838
1867
|
look into JRuby rack handlers, as the Thin web server is not fully supported
|
1839
1868
|
on JRuby. JRuby's support for C extensions is still experimental, which only
|
1840
|
-
affects RDiscount and
|
1869
|
+
affects RDiscount, Redcarpet and RedCloth at the moment.
|
1841
1870
|
|
1842
1871
|
We also keep an eye on upcoming Ruby versions.
|
1843
1872
|
|
@@ -1852,9 +1881,9 @@ known to run Sinatra:
|
|
1852
1881
|
Not being officially supported means if things only break there and not on a
|
1853
1882
|
supported platform, we assume it's not our issue but theirs.
|
1854
1883
|
|
1855
|
-
We also run our CI against ruby-head (the upcoming
|
1856
|
-
guarantee anything, since it is constantly moving. Expect
|
1857
|
-
supported.
|
1884
|
+
We also run our CI against ruby-head (the upcoming 2.0.0) and the 1.9.4
|
1885
|
+
branch, but we can't guarantee anything, since it is constantly moving. Expect
|
1886
|
+
both 1.9.4p0 and 2.0.0p0 to be supported.
|
1858
1887
|
|
1859
1888
|
Sinatra should work on any operating system supported by the chosen Ruby
|
1860
1889
|
implementation.
|
@@ -1942,7 +1971,7 @@ SemVerTag.
|
|
1942
1971
|
* {Mailing List}[http://groups.google.com/group/sinatrarb/topics]
|
1943
1972
|
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] on http://freenode.net
|
1944
1973
|
* {Sinatra Book}[http://sinatra-book.gittr.com] Cookbook Tutorial
|
1945
|
-
* {Sinatra
|
1974
|
+
* {Sinatra Recipes}[http://recipes.sinatrarb.com/] Community
|
1946
1975
|
contributed recipes
|
1947
1976
|
* API documentation for the {latest release}[http://rubydoc.info/gems/sinatra]
|
1948
1977
|
or the {current HEAD}[http://rubydoc.info/github/sinatra/sinatra] on
|
data/README.ru.rdoc
CHANGED
@@ -232,7 +232,7 @@ Thin - это более производительный и функциона
|
|
232
232
|
содержимое шаблона
|
233
233
|
|
234
234
|
get '/' do
|
235
|
-
code = "<%= Time.now
|
235
|
+
code = "<%= Time.now %>"
|
236
236
|
erb code
|
237
237
|
end
|
238
238
|
|
@@ -1779,7 +1779,7 @@ SemVerTag.
|
|
1779
1779
|
* {Группы рассылки}[http://groups.google.com/group/sinatrarb/topics]
|
1780
1780
|
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] на http://freenode.net
|
1781
1781
|
* {Sinatra Book}[http://sinatra-book.gittr.com] учебник и сборник рецептов
|
1782
|
-
* {Sinatra
|
1782
|
+
* {Sinatra Recipes}[http://recipes.sinatrarb.com/] сборник рецептов
|
1783
1783
|
* API документация к {последнему релизу}[http://rubydoc.info/gems/sinatra]
|
1784
1784
|
или {текущему HEAD}[http://rubydoc.info/github/sinatra/sinatra] на
|
1785
1785
|
http://rubydoc.info
|
data/README.zh.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -164,6 +164,10 @@ if defined?(Gem)
|
|
164
164
|
end
|
165
165
|
|
166
166
|
task 'release' => ['test', package('.gem')] do
|
167
|
+
if File.read("CHANGES") =~ /= \d\.\d\.\d . not yet released$/i
|
168
|
+
fail 'please update changes first'
|
169
|
+
end
|
170
|
+
|
167
171
|
sh <<-SH
|
168
172
|
gem install #{package('.gem')} --local &&
|
169
173
|
gem push #{package('.gem')} &&
|
data/examples/chat.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby -I ../lib -I lib
|
2
|
+
# coding: utf-8
|
3
|
+
require 'sinatra'
|
4
|
+
set :server, 'thin'
|
5
|
+
connections = []
|
6
|
+
|
7
|
+
get '/' do
|
8
|
+
halt erb(:login) unless params[:user]
|
9
|
+
erb :chat, :locals => { :user => params[:user].gsub(/\W/, '') }
|
10
|
+
end
|
11
|
+
|
12
|
+
get '/stream', :provides => 'text/event-stream' do
|
13
|
+
stream :keep_open do |out|
|
14
|
+
connections << out
|
15
|
+
out.callback { connections.delete(out) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
post '/' do
|
20
|
+
connections.each { |out| out << "data: #{params[:msg]}\n\n" }
|
21
|
+
204 # response without entity body
|
22
|
+
end
|
23
|
+
|
24
|
+
__END__
|
25
|
+
|
26
|
+
@@ layout
|
27
|
+
<html>
|
28
|
+
<head>
|
29
|
+
<title>Super Simple Chat with Sinatra</title>
|
30
|
+
<meta charset="utf-8" />
|
31
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
|
32
|
+
</head>
|
33
|
+
<body><%= yield %></body>
|
34
|
+
</html>
|
35
|
+
|
36
|
+
@@ login
|
37
|
+
<form action='/'>
|
38
|
+
<label for='user'>User Name:</label>
|
39
|
+
<input name='user' value='' />
|
40
|
+
<input type='submit' value="GO!" />
|
41
|
+
</form>
|
42
|
+
|
43
|
+
@@ chat
|
44
|
+
<pre id='chat'></pre>
|
45
|
+
|
46
|
+
<script>
|
47
|
+
// reading
|
48
|
+
var es = new EventSource('/stream');
|
49
|
+
es.onmessage = function(e) { $('#chat').append(e.data + "\n") };
|
50
|
+
|
51
|
+
// writing
|
52
|
+
$("form").live("submit", function(e) {
|
53
|
+
$.post('/', {msg: "<%= user %>: " + $('#msg').val()});
|
54
|
+
$('#msg').val(''); $('#msg').focus();
|
55
|
+
e.preventDefault();
|
56
|
+
});
|
57
|
+
</script>
|
58
|
+
|
59
|
+
<form>
|
60
|
+
<input id='msg' placeholder='type message here...' />
|
61
|
+
</form>
|
data/examples/simple.rb
ADDED
data/examples/stream.ru
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# this example does *not* work properly with WEBrick
|
2
|
+
#
|
3
|
+
# run *one* of these:
|
4
|
+
#
|
5
|
+
# rackup -s mongrel stream.ru # gem install mongrel
|
6
|
+
# thin -R stream.ru start # gem install thin
|
7
|
+
# unicorn stream.ru # gem install unicorn
|
8
|
+
# puma stream.ru # gem install puma
|
9
|
+
|
10
|
+
require 'sinatra/base'
|
11
|
+
|
12
|
+
class Stream < Sinatra::Base
|
13
|
+
get '/' do
|
14
|
+
content_type :txt
|
15
|
+
|
16
|
+
stream do |out|
|
17
|
+
out << "It's gonna be legen -\n"
|
18
|
+
sleep 0.5
|
19
|
+
out << " (wait for it) \n"
|
20
|
+
sleep 1
|
21
|
+
out << "- dary!\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
run Stream
|
data/lib/sinatra/base.rb
CHANGED
@@ -51,8 +51,8 @@ module Sinatra
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def accept_entry(entry)
|
54
|
-
type, *options = entry.
|
55
|
-
quality = 0 # we sort
|
54
|
+
type, *options = entry.delete(' ').split(';')
|
55
|
+
quality = 0 # we sort smallest first
|
56
56
|
options.delete_if { |e| quality = 1 - e[2..-1].to_f if e.start_with? 'q=' }
|
57
57
|
[type, [quality, type.count('*'), 1 - options.size]]
|
58
58
|
end
|
@@ -287,8 +287,18 @@ module Sinatra
|
|
287
287
|
# The close parameter specifies whether Stream#close should be called
|
288
288
|
# after the block has been executed. This is only relevant for evented
|
289
289
|
# servers like Thin or Rainbows.
|
290
|
-
def stream(keep_open = false
|
290
|
+
def stream(keep_open = false)
|
291
291
|
scheduler = env['async.callback'] ? EventMachine : Stream
|
292
|
+
current = @params.dup
|
293
|
+
block = proc do |out|
|
294
|
+
begin
|
295
|
+
original, @params = @params, current
|
296
|
+
yield(out)
|
297
|
+
ensure
|
298
|
+
@params = original if original
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
292
302
|
body Stream.new(scheduler, keep_open, &block)
|
293
303
|
end
|
294
304
|
|
@@ -311,7 +321,7 @@ module Sinatra
|
|
311
321
|
hash = {}
|
312
322
|
end
|
313
323
|
|
314
|
-
values
|
324
|
+
values.map! { |value| value.to_s.tr('_','-') }
|
315
325
|
hash.each do |key, value|
|
316
326
|
key = key.to_s.tr('_', '-')
|
317
327
|
value = value.to_i if key == "max-age"
|
@@ -619,11 +629,14 @@ module Sinatra
|
|
619
629
|
scope = options.delete(:scope) || self
|
620
630
|
|
621
631
|
# compile and render template
|
622
|
-
|
623
|
-
@default_layout
|
624
|
-
|
625
|
-
|
626
|
-
|
632
|
+
begin
|
633
|
+
layout_was = @default_layout
|
634
|
+
@default_layout = false
|
635
|
+
template = compile_template(engine, data, options, views)
|
636
|
+
output = template.render(scope, locals, &block)
|
637
|
+
ensure
|
638
|
+
@default_layout = layout_was
|
639
|
+
end
|
627
640
|
|
628
641
|
# render layout
|
629
642
|
if layout
|
@@ -794,35 +807,22 @@ module Sinatra
|
|
794
807
|
#
|
795
808
|
# Returns pass block.
|
796
809
|
def process_route(pattern, keys, conditions, block = nil, values = [])
|
797
|
-
@original_params ||= @params
|
798
810
|
route = @request.path_info
|
799
811
|
route = '/' if route.empty? and not settings.empty_path_info?
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
end
|
812
|
-
elsif values.any?
|
813
|
-
{'captures' => values}
|
814
|
-
else
|
815
|
-
{}
|
816
|
-
end
|
817
|
-
@params = @original_params.merge(params)
|
818
|
-
@block_params = values
|
819
|
-
catch(:pass) do
|
820
|
-
conditions.each { |c| throw :pass if c.bind(self).call == false }
|
821
|
-
block ? block[self, @block_params] : yield(self, @block_params)
|
822
|
-
end
|
812
|
+
return unless match = pattern.match(route)
|
813
|
+
values += match.captures.to_a.map { |v| force_encoding URI.decode(v) if v }
|
814
|
+
|
815
|
+
if values.any?
|
816
|
+
original, @params = params, params.merge('splat' => [], 'captures' => values)
|
817
|
+
keys.zip(values) { |k,v| (@params[k] ||= '') << v if v }
|
818
|
+
end
|
819
|
+
|
820
|
+
catch(:pass) do
|
821
|
+
conditions.each { |c| throw :pass if c.bind(self).call == false }
|
822
|
+
block ? block[self, values] : yield(self, values)
|
823
823
|
end
|
824
824
|
ensure
|
825
|
-
@params =
|
825
|
+
@params = original if original
|
826
826
|
end
|
827
827
|
|
828
828
|
# No matching route was found or all routes passed. The default
|
@@ -1350,21 +1350,34 @@ module Sinatra
|
|
1350
1350
|
|
1351
1351
|
def setup_logging(builder)
|
1352
1352
|
if logging?
|
1353
|
-
builder
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1353
|
+
setup_common_logger(builder)
|
1354
|
+
setup_custom_logger(builder)
|
1355
|
+
elsif logging == false
|
1356
|
+
setup_null_logger(builder)
|
1357
|
+
end
|
1358
|
+
end
|
1359
|
+
|
1360
|
+
def setup_null_logger(builder)
|
1361
|
+
builder.use Rack::NullLogger
|
1362
|
+
end
|
1363
|
+
|
1364
|
+
def setup_common_logger(builder)
|
1365
|
+
return if ["development", "deployment", nil].include? ENV["RACK_ENV"]
|
1366
|
+
builder.use Rack::CommonLogger
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
def setup_custom_logger(builder)
|
1370
|
+
if logging.respond_to? :to_int
|
1371
|
+
builder.use Rack::Logger, logging
|
1359
1372
|
else
|
1360
|
-
builder.use Rack::
|
1373
|
+
builder.use Rack::Logger
|
1361
1374
|
end
|
1362
1375
|
end
|
1363
1376
|
|
1364
1377
|
def setup_protection(builder)
|
1365
1378
|
return unless protection?
|
1366
1379
|
options = Hash === protection ? protection.dup : {}
|
1367
|
-
options[:except] = Array
|
1380
|
+
options[:except] = Array options[:except]
|
1368
1381
|
options[:except] += [:session_hijacking, :remote_token] unless sessions?
|
1369
1382
|
builder.use Rack::Protection, options
|
1370
1383
|
end
|
data/lib/sinatra/main.rb
CHANGED
@@ -13,11 +13,11 @@ module Sinatra
|
|
13
13
|
if run? && ARGV.any?
|
14
14
|
require 'optparse'
|
15
15
|
OptionParser.new { |op|
|
16
|
-
op.on('-
|
17
|
-
op.on('-
|
18
|
-
op.on('-
|
19
|
-
op.on('-
|
20
|
-
op.on('-
|
16
|
+
op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
|
17
|
+
op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :bind, val }
|
18
|
+
op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
|
19
|
+
op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
|
20
|
+
op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
|
21
21
|
}.parse!(ARGV.dup)
|
22
22
|
end
|
23
23
|
end
|
data/lib/sinatra/version.rb
CHANGED
data/sinatra.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new 'sinatra', Sinatra::VERSION do |s|
|
|
12
12
|
s.extra_rdoc_files = s.files.select { |p| p =~ /^README/ } << 'LICENSE'
|
13
13
|
s.rdoc_options = %w[--line-numbers --inline-source --title Sinatra --main README.rdoc]
|
14
14
|
|
15
|
-
s.add_dependency 'rack', '~> 1.3', '>= 1.3.
|
16
|
-
s.add_dependency 'rack-protection', '~> 1.
|
15
|
+
s.add_dependency 'rack', '~> 1.3', '>= 1.3.6'
|
16
|
+
s.add_dependency 'rack-protection', '~> 1.2'
|
17
17
|
s.add_dependency 'tilt', '~> 1.3', '>= 1.3.3'
|
18
18
|
end
|
data/test/coffee_test.rb
CHANGED
@@ -71,7 +71,7 @@ class CoffeeTest < Test::Unit::TestCase
|
|
71
71
|
it "passes coffee options to the coffee engine" do
|
72
72
|
coffee_app { coffee "alert 'Aye!'\n", :no_wrap => true }
|
73
73
|
assert ok?
|
74
|
-
|
74
|
+
assert_body "alert('Aye!');"
|
75
75
|
end
|
76
76
|
|
77
77
|
it "passes default coffee options to the coffee engine" do
|
@@ -83,7 +83,7 @@ class CoffeeTest < Test::Unit::TestCase
|
|
83
83
|
end
|
84
84
|
get '/'
|
85
85
|
assert ok?
|
86
|
-
|
86
|
+
assert_body "alert('Aye!');"
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
data/test/filter_test.rb
CHANGED
@@ -380,6 +380,26 @@ class AfterFilterTest < Test::Unit::TestCase
|
|
380
380
|
assert ran
|
381
381
|
end
|
382
382
|
|
383
|
+
it 'can add params' do
|
384
|
+
mock_app do
|
385
|
+
before { params['foo'] = 'bar' }
|
386
|
+
get('/') { params['foo'] }
|
387
|
+
end
|
388
|
+
|
389
|
+
get '/'
|
390
|
+
assert_body 'bar'
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'can remove params' do
|
394
|
+
mock_app do
|
395
|
+
before { params.delete('foo') }
|
396
|
+
get('/') { params['foo'].to_s }
|
397
|
+
end
|
398
|
+
|
399
|
+
get '/?foo=bar'
|
400
|
+
assert_body ''
|
401
|
+
end
|
402
|
+
|
383
403
|
it 'is possible to apply user_agent conditions to after filters with no path' do
|
384
404
|
ran = false
|
385
405
|
mock_app do
|
data/test/helper.rb
CHANGED
@@ -69,7 +69,11 @@ class Test::Unit::TestCase
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def assert_body(value)
|
72
|
-
|
72
|
+
if value.respond_to? :to_str
|
73
|
+
assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "")
|
74
|
+
else
|
75
|
+
assert_match value, body
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
79
|
def assert_status(expected)
|
data/test/helpers_test.rb
CHANGED
@@ -1711,6 +1711,16 @@ class HelpersTest < Test::Unit::TestCase
|
|
1711
1711
|
assert !io.string.include?("INFO -- : Program started")
|
1712
1712
|
assert !io.string.include?("WARN -- : Nothing to do")
|
1713
1713
|
end
|
1714
|
+
|
1715
|
+
it 'does not create a logger when logging is set to nil' do
|
1716
|
+
mock_app do
|
1717
|
+
set :logging, nil
|
1718
|
+
get('/') { logger.inspect }
|
1719
|
+
end
|
1720
|
+
|
1721
|
+
get '/'
|
1722
|
+
assert_body 'nil'
|
1723
|
+
end
|
1714
1724
|
end
|
1715
1725
|
|
1716
1726
|
module ::HelperOne; def one; '1'; end; end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
require 'rbconfig'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
class IntegrationTest < Test::Unit::TestCase
|
7
|
+
def app_file
|
8
|
+
File.expand_path('../integration/app.rb', __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def port
|
12
|
+
5000 + (Process.pid % 1000)
|
13
|
+
end
|
14
|
+
|
15
|
+
def command
|
16
|
+
cmd = ['exec']
|
17
|
+
if RbConfig.respond_to? :ruby
|
18
|
+
cmd << RbConfig.ruby.inspect
|
19
|
+
else
|
20
|
+
file, dir = RbConfig::CONFIG.values_at('ruby_install_name', 'bindir')
|
21
|
+
cmd << File.expand_path(file, dir).inspect
|
22
|
+
end
|
23
|
+
cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect
|
24
|
+
cmd << app_file.inspect << '-p' << port << '2>&1'
|
25
|
+
cmd.join(" ")
|
26
|
+
end
|
27
|
+
|
28
|
+
def display_output(pipe)
|
29
|
+
out = ""
|
30
|
+
loop { out << pipe.read_nonblock(1) }
|
31
|
+
rescue
|
32
|
+
$stderr.puts command, out unless out.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def kill(pid, signal = "TERM")
|
36
|
+
Process.kill(signal, pid)
|
37
|
+
rescue NotImplementedError
|
38
|
+
system "kill -s #{signal} #{pid}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def with_server
|
42
|
+
pipe = IO.popen(command)
|
43
|
+
error = nil
|
44
|
+
Timeout.timeout(120) do
|
45
|
+
begin
|
46
|
+
yield
|
47
|
+
rescue Errno::ECONNREFUSED => e
|
48
|
+
error = e
|
49
|
+
sleep 0.1
|
50
|
+
retry
|
51
|
+
end
|
52
|
+
end
|
53
|
+
kill(pipe.pid) if pipe
|
54
|
+
rescue Timeout::Error => e
|
55
|
+
display_output pipe
|
56
|
+
kill(pipe.pid, "KILL") if pipe
|
57
|
+
raise error || e
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'starts a top level application' do
|
61
|
+
with_server do
|
62
|
+
assert_equal open("http://127.0.0.1:#{port}/app_file").read, app_file
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/test/less_test.rb
CHANGED
@@ -16,7 +16,7 @@ class LessTest < Test::Unit::TestCase
|
|
16
16
|
it 'renders inline Less strings' do
|
17
17
|
less_app { less "@white_color: #fff; #main { background-color: @white_color }" }
|
18
18
|
assert ok?
|
19
|
-
|
19
|
+
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'defaults content type to css' do
|
@@ -45,13 +45,13 @@ class LessTest < Test::Unit::TestCase
|
|
45
45
|
it 'renders .less files in views path' do
|
46
46
|
less_app { less :hello }
|
47
47
|
assert ok?
|
48
|
-
|
48
|
+
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'ignores the layout option' do
|
52
52
|
less_app { less :hello, :layout => :layout2 }
|
53
53
|
assert ok?
|
54
|
-
|
54
|
+
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
55
55
|
end
|
56
56
|
|
57
57
|
it "raises error if template not found" do
|
data/test/rdoc_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path('../helper', __FILE__)
|
2
2
|
|
3
3
|
begin
|
4
|
+
require 'rdoc'
|
4
5
|
require 'rdoc/markup/to_html'
|
5
6
|
|
6
7
|
class RdocTest < Test::Unit::TestCase
|
@@ -15,13 +16,13 @@ class RdocTest < Test::Unit::TestCase
|
|
15
16
|
it 'renders inline rdoc strings' do
|
16
17
|
rdoc_app { rdoc '= Hiya' }
|
17
18
|
assert ok?
|
18
|
-
assert_body
|
19
|
+
assert_body /<h1[^>]*>Hiya<\/h1>/
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'renders .rdoc files in views path' do
|
22
23
|
rdoc_app { rdoc :hello }
|
23
24
|
assert ok?
|
24
|
-
assert_body
|
25
|
+
assert_body /<h1[^>]*>Hello From RDoc<\/h1>/
|
25
26
|
end
|
26
27
|
|
27
28
|
it "raises error if template not found" do
|
data/test/static_test.rb
CHANGED
data/test/streaming_test.rb
CHANGED
@@ -112,4 +112,12 @@ class StreamingTest < Test::Unit::TestCase
|
|
112
112
|
stream = Stream.new { |out| out.callback { out.close }}
|
113
113
|
stream.each { |str| }
|
114
114
|
end
|
115
|
+
|
116
|
+
it 'gives access to route specific params' do
|
117
|
+
mock_app do
|
118
|
+
get('/:name') { stream { |o| o << params[:name] }}
|
119
|
+
end
|
120
|
+
get '/foo'
|
121
|
+
assert_body 'foo'
|
122
|
+
end
|
115
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,11 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2011-
|
15
|
+
date: 2011-12-30 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rack
|
19
|
-
requirement: &
|
19
|
+
requirement: &2153237200 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
22
|
- - ~>
|
@@ -24,27 +24,24 @@ dependencies:
|
|
24
24
|
version: '1.3'
|
25
25
|
- - ! '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.3.
|
27
|
+
version: 1.3.6
|
28
28
|
type: :runtime
|
29
29
|
prerelease: false
|
30
|
-
version_requirements: *
|
30
|
+
version_requirements: *2153237200
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: rack-protection
|
33
|
-
requirement: &
|
33
|
+
requirement: &2153236060 !ruby/object:Gem::Requirement
|
34
34
|
none: false
|
35
35
|
requirements:
|
36
36
|
- - ~>
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: '1.
|
39
|
-
- - ! '>='
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: 1.1.2
|
38
|
+
version: '1.2'
|
42
39
|
type: :runtime
|
43
40
|
prerelease: false
|
44
|
-
version_requirements: *
|
41
|
+
version_requirements: *2153236060
|
45
42
|
- !ruby/object:Gem::Dependency
|
46
43
|
name: tilt
|
47
|
-
requirement: &
|
44
|
+
requirement: &2153235320 !ruby/object:Gem::Requirement
|
48
45
|
none: false
|
49
46
|
requirements:
|
50
47
|
- - ~>
|
@@ -55,7 +52,7 @@ dependencies:
|
|
55
52
|
version: 1.3.3
|
56
53
|
type: :runtime
|
57
54
|
prerelease: false
|
58
|
-
version_requirements: *
|
55
|
+
version_requirements: *2153235320
|
59
56
|
description: Sinatra is a DSL for quickly creating web applications in Ruby with minimal
|
60
57
|
effort.
|
61
58
|
email: sinatrarb@googlegroups.com
|
@@ -90,6 +87,9 @@ files:
|
|
90
87
|
- README.ru.rdoc
|
91
88
|
- README.zh.rdoc
|
92
89
|
- Rakefile
|
90
|
+
- examples/chat.rb
|
91
|
+
- examples/simple.rb
|
92
|
+
- examples/stream.ru
|
93
93
|
- lib/sinatra.rb
|
94
94
|
- lib/sinatra/base.rb
|
95
95
|
- lib/sinatra/images/404.png
|
@@ -111,6 +111,8 @@ files:
|
|
111
111
|
- test/haml_test.rb
|
112
112
|
- test/helper.rb
|
113
113
|
- test/helpers_test.rb
|
114
|
+
- test/integration/app.rb
|
115
|
+
- test/integration_test.rb
|
114
116
|
- test/less_test.rb
|
115
117
|
- test/liquid_test.rb
|
116
118
|
- test/mapped_error_test.rb
|
@@ -196,12 +198,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
198
|
- - ! '>='
|
197
199
|
- !ruby/object:Gem::Version
|
198
200
|
version: '0'
|
201
|
+
segments:
|
202
|
+
- 0
|
203
|
+
hash: 2805773660361067313
|
199
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
205
|
none: false
|
201
206
|
requirements:
|
202
207
|
- - ! '>='
|
203
208
|
- !ruby/object:Gem::Version
|
204
209
|
version: '0'
|
210
|
+
segments:
|
211
|
+
- 0
|
212
|
+
hash: 2805773660361067313
|
205
213
|
requirements: []
|
206
214
|
rubyforge_project:
|
207
215
|
rubygems_version: 1.8.10
|
@@ -220,6 +228,7 @@ test_files:
|
|
220
228
|
- test/filter_test.rb
|
221
229
|
- test/haml_test.rb
|
222
230
|
- test/helpers_test.rb
|
231
|
+
- test/integration_test.rb
|
223
232
|
- test/less_test.rb
|
224
233
|
- test/liquid_test.rb
|
225
234
|
- test/mapped_error_test.rb
|