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.

@@ -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 request.env.merge("PATH_INFO" => '/bar')
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 hacerlo
1371
- por sí solo, porque mejorará el rendimiento. Se encuentra
1372
- habilitada por defecto.
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...' request.env['sinatra.error'].message
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/
@@ -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 request.env.merge("PATH_INFO" => '/bar')
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...' + request.env['sinatra.error'].message
1460
+ 'Donc il est arrivé ceci...' + env['sinatra.error'].message
1447
1461
  end
1448
1462
 
1449
1463
  Donc si ceci arrive:
@@ -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...' + request.env['sinatra.error'].message
402
+ 'Szóval az van, hogy...' + env['sinatra.error'].message
403
403
  end
404
404
 
405
405
  És amikor fellép:
@@ -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
- 'エラーメッセージ...' + request.env['sinatra.error'].message
716
+ 'エラーメッセージ...' + env['sinatra.error'].message
704
717
  end
705
718
 
706
719
  と書いておいて,下記のように呼び出します。
@@ -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...' + request.env['sinatra.error'].message
434
+ 'Então que aconteceu foi...' + env['sinatra.error'].message
435
435
  end
436
436
 
437
437
  Então, se isso acontecer:
@@ -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...' + request.env['sinatra.error'].message
433
+ 'O que aconteceu foi...' + env['sinatra.error'].message
434
434
  end
435
435
 
436
436
  Então, se isso acontecer:
@@ -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
- Templates are assumed to be located directly under the <tt>./views</tt>
213
- directory. To use a different views directory:
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
- haml :index
216
+ erb :index
232
217
  end
233
218
 
234
- Renders <tt>./views/index.haml</tt>.
219
+ This renders <tt>views/index.erb</tt>.
235
220
 
236
- {Haml's options}[http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options]
237
- can be set globally through Sinatra's configurations,
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
- haml :index, :format => :html4 # overridden
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
- Renders <tt>./views/index.erb</tt>.
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
- # You'll need to require erubis in your app
264
- require 'erubis'
238
+ Any options not understood by Sinatra will be passed on to the template
239
+ engine:
265
240
 
266
241
  get '/' do
267
- erubis :index
242
+ haml :index, :format => :html5
268
243
  end
269
244
 
270
- Renders <tt>./views/index.erubis</tt>.
245
+ You can also set options per template language in general:
271
246
 
272
- It is also possible to replace Erb with Erubis:
247
+ set :haml, :format => :html5
273
248
 
274
- require 'erubis'
275
- Tilt.register :erb, Tilt[:erubis]
276
-
277
249
  get '/' do
278
- erb :index
250
+ haml :index
279
251
  end
280
252
 
281
- Renders <tt>./views/index.erb</tt> with Erubis.
253
+ Options passed to the render method override options set via +set+.
282
254
 
283
- === Builder Templates
284
-
285
- The <tt>builder</tt> gem/library is required to render builder templates:
255
+ Available Options:
286
256
 
287
- # You'll need to require builder in your app
288
- require 'builder'
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
- get '/' do
291
- builder :index
292
- end
261
+ [default_encoding]
262
+ String encoding to use if uncertain. Defaults to
263
+ <tt>settings.default_encoding</tt>.
293
264
 
294
- Renders <tt>./views/index.builder</tt>.
265
+ [views]
266
+ Views folder to load templates from. Defaults to <tt>settings.views</tt>.
295
267
 
296
- === Nokogiri Templates
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
- The <tt>nokogiri</tt> gem/library is required to render nokogiri templates:
272
+ [content_type]
273
+ Content-Type the template produces, default depends on template language.
299
274
 
300
- # You'll need to require nokogiri in your app
301
- require 'nokogiri'
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
- get '/' do
304
- nokogiri :index
305
- end
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
- Renders <tt>./views/index.nokogiri</tt>.
284
+ Templates are assumed to be located directly under the <tt>./views</tt>
285
+ directory. To use a different views directory:
308
286
 
309
- === Sass Templates
287
+ set :views, settings.root + '/templates'
310
288
 
311
- The <tt>haml</tt> or <tt>sass</tt> gem/library is required to render Sass templates:
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
- # You'll need to require haml or sass in your app
314
- require 'sass'
295
+ === Available Template Languages
315
296
 
316
- get '/stylesheet.css' do
317
- sass :stylesheet
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
- Renders <tt>./views/stylesheet.sass</tt>.
300
+ require 'rdiscount' # or require 'bluecloth'
301
+ get('/') { markdown :index }
321
302
 
322
- {Sass's options}[http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options]
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
- set :sass, :style => :compact # default Sass style is :nested
305
+ Dependency:: {haml}[http://haml-lang.com/]
306
+ File Extensions:: <tt>.haml</tt>
307
+ Example:: <tt>haml :index, :format => :html5</tt>
328
308
 
329
- get '/stylesheet.css' do
330
- sass :stylesheet, :style => :expanded # overridden
331
- end
309
+ === Erb Templates
332
310
 
333
- === Scss Templates
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
- The <tt>haml</tt> or <tt>sass</tt> gem/library is required to render Scss templates:
317
+ === Builder Templates
336
318
 
337
- # You'll need to require haml or sass in your app
338
- require 'sass'
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
- get '/stylesheet.css' do
341
- scss :stylesheet
342
- end
323
+ It also takes a block for inline templates (see example).
343
324
 
344
- Renders <tt>./views/stylesheet.scss</tt>.
325
+ === Nokogiri Templates
345
326
 
346
- {Scss's options}[http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options]
347
- can be set globally through Sinatra's configurations,
348
- see {Options and Configurations}[http://www.sinatrarb.com/configuration.html],
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
- set :scss, :style => :compact # default Scss style is :nested
331
+ It also takes a block for inline templates (see example).
352
332
 
353
- get '/stylesheet.css' do
354
- scss :stylesheet, :style => :expanded # overridden
355
- end
333
+ === Sass Templates
356
334
 
357
- === Less Templates
335
+ Dependency:: {sass}[http://sass-lang.com/]
336
+ File Extensions:: <tt>.sass</tt>
337
+ Example:: <tt>sass :stylesheet, :style => :expanded</tt>
358
338
 
359
- The <tt>less</tt> gem/library is required to render Less templates:
339
+ === SCSS Templates
360
340
 
361
- # You'll need to require less in your app
362
- require 'less'
341
+ Dependency:: {sass}[http://sass-lang.com/]
342
+ File Extensions:: <tt>.scss</tt>
343
+ Example:: <tt>scss :stylesheet, :style => :expanded</tt>
363
344
 
364
- get '/stylesheet.css' do
365
- less :stylesheet
366
- end
345
+ === Less Templates
367
346
 
368
- Renders <tt>./views/stylesheet.less</tt>.
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
- The <tt>liquid</tt> gem/library is required to render Liquid templates:
373
-
374
- # You'll need to require liquid in your app
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
- The <tt>rdiscount</tt> gem/library is required to render Markdown templates:
391
-
392
- # You'll need to require rdiscount in your app
393
- require "rdiscount"
394
-
395
- get '/' do
396
- markdown :index
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
- The <tt>RedCloth</tt> gem/library is required to render Textile templates:
452
-
453
- # You'll need to require redcloth in your app
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
- The <tt>rdoc</tt> gem/library is required to render RDoc templates:
497
-
498
- # You'll need to require rdoc/markup/to_html in your app
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
- The <tt>radius</tt> gem/library is required to render Radius templates:
542
-
543
- # You'll need to require radius in your app
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 (except for +yield+) from a Radius
553
- template, you almost always want to pass locals to it:
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
- The <tt>markaby</tt> gem/library is required to render Markaby templates:
436
+ Dependency:: {markaby}[http://markaby.github.com/]
437
+ File Extensions:: <tt>.mab</tt>
438
+ Example:: <tt>markaby { h1 "Welcome!" }</tt>
560
439
 
561
- # You'll need to require markaby in your app
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
- The <tt>slim</tt> gem/library is required to render Slim templates:
579
-
580
- # You'll need to require slim in your app
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
- get '/' do
584
- slim :index
585
- end
448
+ === Creole Templates
586
449
 
587
- Renders <tt>./views/index.slim</tt>.
588
-
589
- === CoffeeScript Templates
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
- The <tt>coffee-script</tt> gem/library and at least <b>one</b> of the
592
- following options to execute JavaScript:
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
- * +node+ (from Node.js) in your path
595
- * you must be running on OSX
596
- * +therubyracer+ gem/library
457
+ erb :overview, :locals => { :text => creole(:introduction) }
597
458
 
598
- See http://github.com/josh/ruby-coffee-script for an updated list of options.
459
+ Note that you may also call the +creole+ method from within other templates:
599
460
 
600
- Now you can render CoffeeScript templates:
461
+ %h1 Hello From Haml!
462
+ %p= creole(:greetings)
601
463
 
602
- # You'll need to require coffee-script in your app
603
- require 'coffee-script'
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
- get '/application.js' do
606
- coffee :application
607
- end
468
+ === CoffeeScript Templates
608
469
 
609
- Renders <tt>./views/application.coffee</tt>.
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 request.env.merge("PATH_INFO" => '/bar')
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...' + request.env['sinatra.error'].message
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 slight
1517
- differences in the setting:
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/