sinatra 1.3.0.c → 1.3.0.d
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 +32 -0
- data/Gemfile +7 -1
- data/LICENSE +1 -1
- data/README.de.rdoc +81 -73
- data/README.es.rdoc +26 -6
- data/README.fr.rdoc +17 -3
- data/README.hu.rdoc +1 -1
- data/README.jp.rdoc +14 -1
- data/README.pt-br.rdoc +1 -1
- data/README.pt-pt.rdoc +1 -1
- data/README.rdoc +145 -277
- data/README.ru.rdoc +16 -3
- data/README.zh.rdoc +16 -3
- data/lib/sinatra/base.rb +25 -30
- data/sinatra.gemspec +5 -7
- data/test/creole_test.rb +65 -0
- data/test/delegator_test.rb +27 -1
- data/test/erb_test.rb +24 -1
- data/test/helper.rb +7 -0
- data/test/helpers_test.rb +14 -0
- data/test/markdown_test.rb +54 -9
- data/test/radius_test.rb +0 -1
- data/test/rdoc_test.rb +30 -0
- data/test/routing_test.rb +35 -4
- data/test/settings_test.rb +18 -0
- data/test/textile_test.rb +30 -0
- data/test/views/hello.creole +1 -0
- metadata +8 -15
- data/test/erubis_test.rb +0 -88
- data/test/views/error.erubis +0 -3
- data/test/views/hello.erubis +0 -1
- data/test/views/layout2.erubis +0 -2
data/README.es.rdoc
CHANGED
@@ -597,6 +597,19 @@ La gem/librería <tt>slim</tt> es necesaria para renderizar plantillas Slim:
|
|
597
597
|
|
598
598
|
Renderiza <tt>./views/index.slim</tt>.
|
599
599
|
|
600
|
+
=== Plantillas Creole
|
601
|
+
|
602
|
+
La gem/librería <tt>creole</tt> es necesaria para renderizar plantillas Creole:
|
603
|
+
|
604
|
+
# Vas a necesitar requerir creole en tu app
|
605
|
+
require 'creole'
|
606
|
+
|
607
|
+
get '/' do
|
608
|
+
creole :index
|
609
|
+
end
|
610
|
+
|
611
|
+
Renderiza <tt>./views/index.creole</tt>.
|
612
|
+
|
600
613
|
=== Plantillas CoffeeScript
|
601
614
|
|
602
615
|
La gem/librería <tt>coffee-script</tt> y al menos <b>una</b> de las siguientes
|
@@ -883,8 +896,8 @@ Cuando querés obtener el resultado de la llamada a una ruta, +pass+ no te va a
|
|
883
896
|
servir. Para lograr esto, podés usar +call+:
|
884
897
|
|
885
898
|
get '/foo' do
|
886
|
-
status, headers, body = call
|
887
|
-
[status, body.upcase]
|
899
|
+
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
900
|
+
[status, headers, body.map(&:upcase)]
|
888
901
|
end
|
889
902
|
|
890
903
|
get '/bar' do
|
@@ -1367,9 +1380,11 @@ Podés acceder a estas opciones utilizando el método <tt>settings</tt>:
|
|
1367
1380
|
[static] define si Sinatra debe encargarse de servir archivos
|
1368
1381
|
estáticos.
|
1369
1382
|
|
1370
|
-
Deshabilitala cuando usés un servidor capaz de
|
1371
|
-
por sí solo, porque mejorará el
|
1372
|
-
habilitada por
|
1383
|
+
Deshabilitala cuando usés un servidor capaz de
|
1384
|
+
hacerlo por sí solo, porque mejorará el
|
1385
|
+
rendimiento. Se encuentra habilitada por
|
1386
|
+
defecto en el estilo clásico y desactivado en el
|
1387
|
+
el modular.
|
1373
1388
|
|
1374
1389
|
[views] directorio de las vistas.
|
1375
1390
|
|
@@ -1401,7 +1416,7 @@ obtener de la variable Rack <tt>sinatra.error</tt>:
|
|
1401
1416
|
Errores personalizados:
|
1402
1417
|
|
1403
1418
|
error MiErrorPersonalizado do
|
1404
|
-
'Lo que pasó fue...'
|
1419
|
+
'Lo que pasó fue...' + env['sinatra.error'].message
|
1405
1420
|
end
|
1406
1421
|
|
1407
1422
|
Entonces, si pasa esto:
|
@@ -1570,6 +1585,7 @@ entre sus configuraciones:
|
|
1570
1585
|
logging true false
|
1571
1586
|
method_override true false
|
1572
1587
|
inline_templates true false
|
1588
|
+
static true false
|
1573
1589
|
|
1574
1590
|
=== Sirviendo una Aplicación Modular
|
1575
1591
|
|
@@ -1936,3 +1952,7 @@ siguiendo las especificaciones SemVer y SemVerTag.
|
|
1936
1952
|
* {Twitter}[http://twitter.com/sinatra]
|
1937
1953
|
* {Lista de Correo}[http://groups.google.com/group/sinatrarb/topics]
|
1938
1954
|
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] en http://freenode.net
|
1955
|
+
* Documentación de la API para la
|
1956
|
+
{última versión liberada}[http://rubydoc.info/gems/sinatra] o para la
|
1957
|
+
{rama de desarrollo actual}[http://rubydoc.info/github/sinatra/sinatra]
|
1958
|
+
en http://rubydoc.info/
|
data/README.fr.rdoc
CHANGED
@@ -618,6 +618,20 @@ Le gem slim est nécessaire pour utiliser la fonction de rendu Slim:
|
|
618
618
|
|
619
619
|
Utilisera <tt>./views/index.slim</tt>.
|
620
620
|
|
621
|
+
=== Templates Creole
|
622
|
+
|
623
|
+
Le gem <tt>creole</tt> est nécessaire pour utiliser la fonction de rendu
|
624
|
+
Creole:
|
625
|
+
|
626
|
+
# Chargez la bibliothèque creole dans votre application
|
627
|
+
require 'creole'
|
628
|
+
|
629
|
+
get '/' do
|
630
|
+
creole :index
|
631
|
+
end
|
632
|
+
|
633
|
+
Utilisera <tt>./views/index.creole</tt>.
|
634
|
+
|
621
635
|
=== Templates CoffeeScript
|
622
636
|
|
623
637
|
Le gem <tt>coffee-script</tt> est nécessaire ainsi que l'<b>une</b> des
|
@@ -911,8 +925,8 @@ souhaitez obtenir le résultat d'une autre route. Pour cela, utilisez
|
|
911
925
|
simplement +call+ :
|
912
926
|
|
913
927
|
get '/foo' do
|
914
|
-
status, headers, body = call
|
915
|
-
[status, body.upcase]
|
928
|
+
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
929
|
+
[status, headers, body.map(&:upcase)]
|
916
930
|
end
|
917
931
|
|
918
932
|
get '/bar' do
|
@@ -1443,7 +1457,7 @@ variable Rack <tt>sinatra.error</tt>:
|
|
1443
1457
|
Erreur sur mesure:
|
1444
1458
|
|
1445
1459
|
error MonErreurSurMesure do
|
1446
|
-
'Donc il est arrivé ceci...' +
|
1460
|
+
'Donc il est arrivé ceci...' + env['sinatra.error'].message
|
1447
1461
|
end
|
1448
1462
|
|
1449
1463
|
Donc si ceci arrive:
|
data/README.hu.rdoc
CHANGED
@@ -399,7 +399,7 @@ előszűrő kivételt vált ki. A kivétel objektum lehívható a
|
|
399
399
|
Egyéni hibakezelés:
|
400
400
|
|
401
401
|
error MyCustomError do
|
402
|
-
'Szóval az van, hogy...' +
|
402
|
+
'Szóval az van, hogy...' + env['sinatra.error'].message
|
403
403
|
end
|
404
404
|
|
405
405
|
És amikor fellép:
|
data/README.jp.rdoc
CHANGED
@@ -432,6 +432,19 @@ Slimテンプレートを使うにはslimライブラリが必要です:
|
|
432
432
|
|
433
433
|
<tt>./views/index.slim</tt>を表示します。
|
434
434
|
|
435
|
+
=== Creole テンプレート
|
436
|
+
|
437
|
+
Creoleテンプレートを使うにはcreoleライブラリが必要です:
|
438
|
+
|
439
|
+
# creoleを読み込みます
|
440
|
+
require 'creole'
|
441
|
+
|
442
|
+
get '/' do
|
443
|
+
creole :index
|
444
|
+
end
|
445
|
+
|
446
|
+
<tt>./views/index.creole</tt>を表示します。
|
447
|
+
|
435
448
|
=== CoffeeScript テンプレート
|
436
449
|
|
437
450
|
CoffeeScriptテンプレートを表示するにはcoffee-scriptライブラリと`coffee`バイナリが必要です:
|
@@ -700,7 +713,7 @@ body部を指定することもできます ...
|
|
700
713
|
エラーをカスタマイズする場合は、
|
701
714
|
|
702
715
|
error MyCustomError do
|
703
|
-
'エラーメッセージ...' +
|
716
|
+
'エラーメッセージ...' + env['sinatra.error'].message
|
704
717
|
end
|
705
718
|
|
706
719
|
と書いておいて,下記のように呼び出します。
|
data/README.pt-br.rdoc
CHANGED
@@ -431,7 +431,7 @@ Rack <tt>sinatra.error</tt>:
|
|
431
431
|
Erros customizados:
|
432
432
|
|
433
433
|
error MeuErroCustomizado do
|
434
|
-
'Então que aconteceu foi...' +
|
434
|
+
'Então que aconteceu foi...' + env['sinatra.error'].message
|
435
435
|
end
|
436
436
|
|
437
437
|
Então, se isso acontecer:
|
data/README.pt-pt.rdoc
CHANGED
@@ -430,7 +430,7 @@ Rack <tt>sinatra.error</tt>:
|
|
430
430
|
Erros personalizados:
|
431
431
|
|
432
432
|
error MeuErroPersonalizado do
|
433
|
-
'O que aconteceu foi...' +
|
433
|
+
'O que aconteceu foi...' + env['sinatra.error'].message
|
434
434
|
end
|
435
435
|
|
436
436
|
Então, se isso acontecer:
|
data/README.rdoc
CHANGED
@@ -209,195 +209,163 @@ Note that the public directory name is not included in the URL. A file
|
|
209
209
|
|
210
210
|
== Views / Templates
|
211
211
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
set :views, File.dirname(__FILE__) + '/templates'
|
216
|
-
|
217
|
-
One important thing to remember is that you always have to reference
|
218
|
-
templates with symbols, even if they're in a subdirectory (in this
|
219
|
-
case, use <tt>:'subdir/template'</tt>). You must use a symbol because
|
220
|
-
otherwise rendering methods will render any strings passed to them
|
221
|
-
directly.
|
222
|
-
|
223
|
-
=== Haml Templates
|
224
|
-
|
225
|
-
The <tt>haml</tt> gem/library is required to render HAML templates:
|
226
|
-
|
227
|
-
# You'll need to require haml in your app
|
228
|
-
require 'haml'
|
212
|
+
Each template language is exposed as via its own rendering method. These
|
213
|
+
methods simply return a string:
|
229
214
|
|
230
215
|
get '/' do
|
231
|
-
|
216
|
+
erb :index
|
232
217
|
end
|
233
218
|
|
234
|
-
|
219
|
+
This renders <tt>views/index.erb</tt>.
|
235
220
|
|
236
|
-
|
237
|
-
|
238
|
-
see {Options and Configurations}[http://www.sinatrarb.com/configuration.html],
|
239
|
-
and overridden on an individual basis.
|
240
|
-
|
241
|
-
set :haml, :format => :html5 # default Haml format is :xhtml
|
221
|
+
Instead of a template name, you can also just pass in the template content
|
222
|
+
directly:
|
242
223
|
|
243
224
|
get '/' do
|
244
|
-
|
225
|
+
code = "<%= Time.now >"
|
226
|
+
erb code
|
245
227
|
end
|
246
228
|
|
247
|
-
|
248
|
-
=== Erb Templates
|
249
|
-
|
250
|
-
# You'll need to require erb in your app
|
251
|
-
require 'erb'
|
229
|
+
Templates take a second argument, the options hash:
|
252
230
|
|
253
231
|
get '/' do
|
254
|
-
erb :index
|
232
|
+
erb :index, :layout => :post
|
255
233
|
end
|
256
234
|
|
257
|
-
|
258
|
-
|
259
|
-
=== Erubis Templates
|
260
|
-
|
261
|
-
The <tt>erubis</tt> gem/library is required to render Erubis templates:
|
235
|
+
This will render <tt>views/index.erb</tt> embedded in the
|
236
|
+
<tt>views/post.erb</tt> (default is <tt>views/layout.erb</tt>, if it exists).
|
262
237
|
|
263
|
-
|
264
|
-
|
238
|
+
Any options not understood by Sinatra will be passed on to the template
|
239
|
+
engine:
|
265
240
|
|
266
241
|
get '/' do
|
267
|
-
|
242
|
+
haml :index, :format => :html5
|
268
243
|
end
|
269
244
|
|
270
|
-
|
245
|
+
You can also set options per template language in general:
|
271
246
|
|
272
|
-
|
247
|
+
set :haml, :format => :html5
|
273
248
|
|
274
|
-
require 'erubis'
|
275
|
-
Tilt.register :erb, Tilt[:erubis]
|
276
|
-
|
277
249
|
get '/' do
|
278
|
-
|
250
|
+
haml :index
|
279
251
|
end
|
280
252
|
|
281
|
-
|
253
|
+
Options passed to the render method override options set via +set+.
|
282
254
|
|
283
|
-
|
284
|
-
|
285
|
-
The <tt>builder</tt> gem/library is required to render builder templates:
|
255
|
+
Available Options:
|
286
256
|
|
287
|
-
|
288
|
-
|
257
|
+
[locals]
|
258
|
+
List of locals passed to the document. Handy with partials.
|
259
|
+
Example: <tt>erb "<%= foo %>", :locals => {:foo => "bar"}</tt>
|
289
260
|
|
290
|
-
|
291
|
-
|
292
|
-
|
261
|
+
[default_encoding]
|
262
|
+
String encoding to use if uncertain. Defaults to
|
263
|
+
<tt>settings.default_encoding</tt>.
|
293
264
|
|
294
|
-
|
265
|
+
[views]
|
266
|
+
Views folder to load templates from. Defaults to <tt>settings.views</tt>.
|
295
267
|
|
296
|
-
|
268
|
+
[layout]
|
269
|
+
Whether to use a layout (+true+ or +false+), if it's a Symbol, specifies
|
270
|
+
what template to use. Example: <tt>erb :index, :layout => request.xhr?</tt>
|
297
271
|
|
298
|
-
|
272
|
+
[content_type]
|
273
|
+
Content-Type the template produces, default depends on template language.
|
299
274
|
|
300
|
-
|
301
|
-
|
275
|
+
[scope]
|
276
|
+
Scope to render template under. Defaults to the application instance. If you
|
277
|
+
change this, instance variables and helper methods will not be available.
|
302
278
|
|
303
|
-
|
304
|
-
|
305
|
-
|
279
|
+
[layout_engine]
|
280
|
+
Template engine to use for rendering the layout. Useful for languages that
|
281
|
+
do not support layouts otherwise. Defaults to the engine used for the
|
282
|
+
temple. Example: <tt>set :rdoc, :layout_engine => :erb</tt>
|
306
283
|
|
307
|
-
|
284
|
+
Templates are assumed to be located directly under the <tt>./views</tt>
|
285
|
+
directory. To use a different views directory:
|
308
286
|
|
309
|
-
|
287
|
+
set :views, settings.root + '/templates'
|
310
288
|
|
311
|
-
|
289
|
+
One important thing to remember is that you always have to reference
|
290
|
+
templates with symbols, even if they're in a subdirectory (in this
|
291
|
+
case, use <tt>:'subdir/template'</tt>). You must use a symbol because
|
292
|
+
otherwise rendering methods will render any strings passed to them
|
293
|
+
directly.
|
312
294
|
|
313
|
-
|
314
|
-
require 'sass'
|
295
|
+
=== Available Template Languages
|
315
296
|
|
316
|
-
|
317
|
-
|
318
|
-
end
|
297
|
+
Some languages have multiple implementations. To specify what implementation
|
298
|
+
to use (and to be thread-safe), you should simply require it first:
|
319
299
|
|
320
|
-
|
300
|
+
require 'rdiscount' # or require 'bluecloth'
|
301
|
+
get('/') { markdown :index }
|
321
302
|
|
322
|
-
|
323
|
-
can be set globally through Sinatra's configurations,
|
324
|
-
see {Options and Configurations}[http://www.sinatrarb.com/configuration.html],
|
325
|
-
and overridden on an individual basis.
|
303
|
+
=== Haml Templates
|
326
304
|
|
327
|
-
|
305
|
+
Dependency:: {haml}[http://haml-lang.com/]
|
306
|
+
File Extensions:: <tt>.haml</tt>
|
307
|
+
Example:: <tt>haml :index, :format => :html5</tt>
|
328
308
|
|
329
|
-
|
330
|
-
sass :stylesheet, :style => :expanded # overridden
|
331
|
-
end
|
309
|
+
=== Erb Templates
|
332
310
|
|
333
|
-
|
311
|
+
Dependency:: {erubis}[http://www.kuwata-lab.com/erubis/] or
|
312
|
+
erb (included in Ruby)
|
313
|
+
File Extensions:: <tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubis</tt> (Erubis
|
314
|
+
only)
|
315
|
+
Example:: <tt>erb :index</tt>
|
334
316
|
|
335
|
-
|
317
|
+
=== Builder Templates
|
336
318
|
|
337
|
-
|
338
|
-
|
319
|
+
Dependency:: {builder}[http://builder.rubyforge.org/]
|
320
|
+
File Extensions:: <tt>.builder</tt>
|
321
|
+
Example:: <tt>builder { |xml| xml.em "hi" }</tt>
|
339
322
|
|
340
|
-
|
341
|
-
scss :stylesheet
|
342
|
-
end
|
323
|
+
It also takes a block for inline templates (see example).
|
343
324
|
|
344
|
-
|
325
|
+
=== Nokogiri Templates
|
345
326
|
|
346
|
-
{
|
347
|
-
|
348
|
-
|
349
|
-
and overridden on an individual basis.
|
327
|
+
Dependency:: {nokogiri}[http://nokogiri.org/]
|
328
|
+
File Extensions:: <tt>.nokogiri</tt>
|
329
|
+
Example:: <tt>builder { |xml| xml.em "hi" }</tt>
|
350
330
|
|
351
|
-
|
331
|
+
It also takes a block for inline templates (see example).
|
352
332
|
|
353
|
-
|
354
|
-
scss :stylesheet, :style => :expanded # overridden
|
355
|
-
end
|
333
|
+
=== Sass Templates
|
356
334
|
|
357
|
-
|
335
|
+
Dependency:: {sass}[http://sass-lang.com/]
|
336
|
+
File Extensions:: <tt>.sass</tt>
|
337
|
+
Example:: <tt>sass :stylesheet, :style => :expanded</tt>
|
358
338
|
|
359
|
-
|
339
|
+
=== SCSS Templates
|
360
340
|
|
361
|
-
|
362
|
-
|
341
|
+
Dependency:: {sass}[http://sass-lang.com/]
|
342
|
+
File Extensions:: <tt>.scss</tt>
|
343
|
+
Example:: <tt>scss :stylesheet, :style => :expanded</tt>
|
363
344
|
|
364
|
-
|
365
|
-
less :stylesheet
|
366
|
-
end
|
345
|
+
=== Less Templates
|
367
346
|
|
368
|
-
|
347
|
+
Dependency:: {less}[http://www.lesscss.org/]
|
348
|
+
File Extensions:: <tt>.less</tt>
|
349
|
+
Example:: <tt>less :stylesheet</tt>
|
369
350
|
|
370
351
|
=== Liquid Templates
|
371
352
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
require 'liquid'
|
376
|
-
|
377
|
-
get '/' do
|
378
|
-
liquid :index
|
379
|
-
end
|
380
|
-
|
381
|
-
Renders <tt>./views/index.liquid</tt>.
|
353
|
+
Dependency:: {liquid}[http://www.liquidmarkup.org/]
|
354
|
+
File Extensions:: <tt>.liquid</tt>
|
355
|
+
Example:: <tt>liquid :index, :locals => { :key => 'value' }</tt>
|
382
356
|
|
383
357
|
Since you cannot call Ruby methods (except for +yield+) from a Liquid
|
384
|
-
template, you almost always want to pass locals to it
|
385
|
-
|
386
|
-
liquid :index, :locals => { :key => 'value' }
|
358
|
+
template, you almost always want to pass locals to it.
|
387
359
|
|
388
360
|
=== Markdown Templates
|
389
361
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
end
|
398
|
-
|
399
|
-
Renders <tt>./views/index.markdown</tt> (+md+ and +mkd+ are also valid file
|
400
|
-
extensions).
|
362
|
+
Dependency:: {rdiscount}[https://github.com/rtomayko/rdiscount],
|
363
|
+
{redcarpet}[https://github.com/tanoku/redcarpet],
|
364
|
+
{bluecloth}[http://deveiate.org/projects/BlueCloth],
|
365
|
+
{kramdown}[http://kramdown.rubyforge.org/] *or*
|
366
|
+
{maruku}[http://maruku.rubyforge.org/]
|
367
|
+
File Extensions:: <tt>.markdown</tt>, <tt>.mkd</tt> and <tt>.md</tt>
|
368
|
+
Example:: <tt>markdown :index, :layout_engine => :erb</tt>
|
401
369
|
|
402
370
|
It is not possible to call methods from markdown, nor to pass locals to it.
|
403
371
|
You therefore will usually use it in combination with another rendering
|
@@ -412,52 +380,13 @@ Note that you may also call the +markdown+ method from within other templates:
|
|
412
380
|
|
413
381
|
Since you cannot call Ruby from Markdown, you cannot use layouts written in
|
414
382
|
Markdown. However, it is possible to use another rendering engine for the
|
415
|
-
template than for the layout by passing the <tt>:layout_engine</tt> option
|
416
|
-
|
417
|
-
get '/' do
|
418
|
-
markdown :index, :layout_engine => :erb
|
419
|
-
end
|
420
|
-
|
421
|
-
This will render <tt>./views/index.md</tt> with <tt>./views/layout.erb</tt> as
|
422
|
-
layout.
|
423
|
-
|
424
|
-
Remember that you can set such rendering options globally:
|
425
|
-
|
426
|
-
set :markdown, :layout_engine => :haml, :layout => :post
|
427
|
-
|
428
|
-
get '/' do
|
429
|
-
markdown :index
|
430
|
-
end
|
431
|
-
|
432
|
-
This will render <tt>./views/index.md</tt> (and any other Markdown template)
|
433
|
-
with <tt>./views/post.haml</tt> as layout.
|
434
|
-
|
435
|
-
It is also possible to parse Markdown with BlueCloth rather than RDiscount:
|
436
|
-
|
437
|
-
require 'bluecloth'
|
438
|
-
|
439
|
-
Tilt.register 'markdown', BlueClothTemplate
|
440
|
-
Tilt.register 'mkd', BlueClothTemplate
|
441
|
-
Tilt.register 'md', BlueClothTemplate
|
442
|
-
|
443
|
-
get '/' do
|
444
|
-
markdown :index
|
445
|
-
end
|
446
|
-
|
447
|
-
Renders <tt>./views/index.md</tt> with BlueCloth.
|
383
|
+
template than for the layout by passing the <tt>:layout_engine</tt> option.
|
448
384
|
|
449
385
|
=== Textile Templates
|
450
386
|
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
require "redcloth"
|
455
|
-
|
456
|
-
get '/' do
|
457
|
-
textile :index
|
458
|
-
end
|
459
|
-
|
460
|
-
Renders <tt>./views/index.textile</tt>.
|
387
|
+
Dependency:: {RedCloth}[http://redcloth.org/]
|
388
|
+
File Extensions:: <tt>.textile</tt>
|
389
|
+
Example:: <tt>textile :index, :layout_engine => :erb</tt>
|
461
390
|
|
462
391
|
It is not possible to call methods from textile, nor to pass locals to it. You
|
463
392
|
therefore will usually use it in combination with another rendering engine:
|
@@ -471,38 +400,13 @@ Note that you may also call the +textile+ method from within other templates:
|
|
471
400
|
|
472
401
|
Since you cannot call Ruby from Textile, you cannot use layouts written in
|
473
402
|
Textile. However, it is possible to use another rendering engine for the
|
474
|
-
template than for the layout by passing the <tt>:layout_engine</tt> option
|
475
|
-
|
476
|
-
get '/' do
|
477
|
-
textile :index, :layout_engine => :erb
|
478
|
-
end
|
479
|
-
|
480
|
-
This will render <tt>./views/index.textile</tt> with
|
481
|
-
<tt>./views/layout.erb</tt> as layout.
|
482
|
-
|
483
|
-
Remember that you can set such rendering options globally:
|
484
|
-
|
485
|
-
set :textile, :layout_engine => :haml, :layout => :post
|
486
|
-
|
487
|
-
get '/' do
|
488
|
-
textile :index
|
489
|
-
end
|
490
|
-
|
491
|
-
This will render <tt>./views/index.textile</tt> (and any other Textile
|
492
|
-
template) with <tt>./views/post.haml</tt> as layout.
|
403
|
+
template than for the layout by passing the <tt>:layout_engine</tt> option.
|
493
404
|
|
494
405
|
=== RDoc Templates
|
495
406
|
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
require "rdoc/markup/to_html"
|
500
|
-
|
501
|
-
get '/' do
|
502
|
-
rdoc :index
|
503
|
-
end
|
504
|
-
|
505
|
-
Renders <tt>./views/index.rdoc</tt>.
|
407
|
+
Dependency:: {rdoc}[http://rdoc.rubyforge.org/]
|
408
|
+
File Extensions:: <tt>.rdoc</tt>
|
409
|
+
Example:: <tt>textile :README, :layout_engine => :erb</tt>
|
506
410
|
|
507
411
|
It is not possible to call methods from rdoc, nor to pass locals to it. You
|
508
412
|
therefore will usually use it in combination with another rendering engine:
|
@@ -516,97 +420,57 @@ Note that you may also call the +rdoc+ method from within other templates:
|
|
516
420
|
|
517
421
|
Since you cannot call Ruby from RDoc, you cannot use layouts written in
|
518
422
|
RDoc. However, it is possible to use another rendering engine for the
|
519
|
-
template than for the layout by passing the <tt>:layout_engine</tt> option
|
520
|
-
|
521
|
-
get '/' do
|
522
|
-
rdoc :index, :layout_engine => :erb
|
523
|
-
end
|
524
|
-
|
525
|
-
This will render <tt>./views/index.rdoc</tt> with <tt>./views/layout.erb</tt> as
|
526
|
-
layout.
|
527
|
-
|
528
|
-
Remember that you can set such rendering options globally:
|
529
|
-
|
530
|
-
set :rdoc, :layout_engine => :haml, :layout => :post
|
531
|
-
|
532
|
-
get '/' do
|
533
|
-
rdoc :index
|
534
|
-
end
|
535
|
-
|
536
|
-
This will render <tt>./views/index.rdoc</tt> (and any other RDoc template)
|
537
|
-
with <tt>./views/post.haml</tt> as layout.
|
423
|
+
template than for the layout by passing the <tt>:layout_engine</tt> option.
|
538
424
|
|
539
425
|
=== Radius Templates
|
540
426
|
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
require 'radius'
|
545
|
-
|
546
|
-
get '/' do
|
547
|
-
radius :index
|
548
|
-
end
|
549
|
-
|
550
|
-
Renders <tt>./views/index.radius</tt>.
|
427
|
+
Dependency:: {radius}[http://radius.rubyforge.org/]
|
428
|
+
File Extensions:: <tt>.radius</tt>
|
429
|
+
Example:: <tt>radius :index, :locals => { :key => 'value' }</tt>
|
551
430
|
|
552
|
-
Since you cannot call Ruby methods
|
553
|
-
|
554
|
-
|
555
|
-
radius :index, :locals => { :key => 'value' }
|
431
|
+
Since you cannot call Ruby methods directly from a Radius template, you almost
|
432
|
+
always want to pass locals to it.
|
556
433
|
|
557
434
|
=== Markaby Templates
|
558
435
|
|
559
|
-
|
436
|
+
Dependency:: {markaby}[http://markaby.github.com/]
|
437
|
+
File Extensions:: <tt>.mab</tt>
|
438
|
+
Example:: <tt>markaby { h1 "Welcome!" }</tt>
|
560
439
|
|
561
|
-
|
562
|
-
require 'markaby'
|
563
|
-
|
564
|
-
get '/' do
|
565
|
-
markaby :index
|
566
|
-
end
|
567
|
-
|
568
|
-
Renders <tt>./views/index.mab</tt>.
|
569
|
-
|
570
|
-
You may also use inline Markaby:
|
571
|
-
|
572
|
-
get '/' do
|
573
|
-
markaby { h1 "Welcome!" }
|
574
|
-
end
|
440
|
+
It also takes a block for inline templates (see example).
|
575
441
|
|
576
442
|
=== Slim Templates
|
577
443
|
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
require 'slim'
|
444
|
+
Dependency:: {slim}[http://slim-lang.com/]
|
445
|
+
File Extensions:: <tt>.slim</tt>
|
446
|
+
Example:: <tt>slim :index</tt>
|
582
447
|
|
583
|
-
|
584
|
-
slim :index
|
585
|
-
end
|
448
|
+
=== Creole Templates
|
586
449
|
|
587
|
-
|
588
|
-
|
589
|
-
|
450
|
+
Dependency:: {creole}[https://github.com/minad/creole]
|
451
|
+
File Extensions:: <tt>.creole</tt>
|
452
|
+
Example:: <tt>creole :wiki, :layout_engine => :erb</tt>
|
590
453
|
|
591
|
-
|
592
|
-
|
454
|
+
It is not possible to call methods from creole, nor to pass locals to it. You
|
455
|
+
therefore will usually use it in combination with another rendering engine:
|
593
456
|
|
594
|
-
|
595
|
-
* you must be running on OSX
|
596
|
-
* +therubyracer+ gem/library
|
457
|
+
erb :overview, :locals => { :text => creole(:introduction) }
|
597
458
|
|
598
|
-
|
459
|
+
Note that you may also call the +creole+ method from within other templates:
|
599
460
|
|
600
|
-
|
461
|
+
%h1 Hello From Haml!
|
462
|
+
%p= creole(:greetings)
|
601
463
|
|
602
|
-
|
603
|
-
|
464
|
+
Since you cannot call Ruby from Creole, you cannot use layouts written in
|
465
|
+
Creole. However, it is possible to use another rendering engine for the
|
466
|
+
template than for the layout by passing the <tt>:layout_engine</tt> option.
|
604
467
|
|
605
|
-
|
606
|
-
coffee :application
|
607
|
-
end
|
468
|
+
=== CoffeeScript Templates
|
608
469
|
|
609
|
-
|
470
|
+
Dependency:: {coffee-script}[https://github.com/josh/ruby-coffee-script]
|
471
|
+
and a {way to execute javascript}[https://github.com/sstephenson/execjs/blob/master/README.md#readme]
|
472
|
+
File Extensions:: <tt>.coffee</tt>
|
473
|
+
Example:: <tt>coffee :index</tt>
|
610
474
|
|
611
475
|
=== Embedded Templates
|
612
476
|
|
@@ -863,8 +727,8 @@ Sometimes +pass+ is not what you want, instead you would like to get the result
|
|
863
727
|
of calling another route. Simply use +call+ to achieve this:
|
864
728
|
|
865
729
|
get '/foo' do
|
866
|
-
status, headers, body = call
|
867
|
-
[status, body.upcase]
|
730
|
+
status, headers, body = call env.merge("PATH_INFO" => '/bar')
|
731
|
+
[status, headers, body.map(&:upcase)]
|
868
732
|
end
|
869
733
|
|
870
734
|
get '/bar' do
|
@@ -1328,7 +1192,8 @@ You can access those options via <tt>settings</tt>:
|
|
1328
1192
|
[static] Whether Sinatra should handle serving static files.
|
1329
1193
|
Disable when using a Server able to do this on its own.
|
1330
1194
|
Disabling will boost performance.
|
1331
|
-
Enabled per default
|
1195
|
+
Enabled per default in classic style, disabled for
|
1196
|
+
modular apps.
|
1332
1197
|
|
1333
1198
|
[views] views folder.
|
1334
1199
|
|
@@ -1360,7 +1225,7 @@ block or a filter. The exception object can be obtained from the
|
|
1360
1225
|
Custom errors:
|
1361
1226
|
|
1362
1227
|
error MyCustomError do
|
1363
|
-
'So what happened was...' +
|
1228
|
+
'So what happened was...' + env['sinatra.error'].message
|
1364
1229
|
end
|
1365
1230
|
|
1366
1231
|
Then, if this happens:
|
@@ -1513,8 +1378,8 @@ There are only two downsides compared with modular style:
|
|
1513
1378
|
|
1514
1379
|
There is no reason you cannot mix modular and classic style.
|
1515
1380
|
|
1516
|
-
If switching from one style to the other, you should be aware of
|
1517
|
-
|
1381
|
+
If switching from one style to the other, you should be aware of slightly
|
1382
|
+
different default settings:
|
1518
1383
|
|
1519
1384
|
Setting Classic Modular
|
1520
1385
|
|
@@ -1523,6 +1388,7 @@ differences in the setting:
|
|
1523
1388
|
logging true false
|
1524
1389
|
method_override true false
|
1525
1390
|
inline_templates true false
|
1391
|
+
static true false
|
1526
1392
|
|
1527
1393
|
|
1528
1394
|
=== Serving a Modular Application
|
@@ -1882,6 +1748,8 @@ SemVerTag.
|
|
1882
1748
|
* {Twitter}[http://twitter.com/sinatra]
|
1883
1749
|
* {Mailing List}[http://groups.google.com/group/sinatrarb/topics]
|
1884
1750
|
* {IRC: #sinatra}[irc://chat.freenode.net/#sinatra] on http://freenode.net
|
1751
|
+
* {Sinatra Book}[http://sinatra-book.gittr.com] Cookbook Tutorial
|
1752
|
+
* {Sinatra Book Contrib}[http://sinatra-book-contrib.com/] Community contributed recipes
|
1885
1753
|
* API documentation for the {latest release}[http://rubydoc.info/gems/sinatra]
|
1886
1754
|
or the {current HEAD}[http://rubydoc.info/github/sinatra/sinatra] on
|
1887
1755
|
http://rubydoc.info/
|