sinatra 1.4.4 → 1.4.5

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/README.md CHANGED
@@ -52,11 +52,13 @@ pick up if available.
52
52
  * [Markdown Templates](#markdown-templates)
53
53
  * [Textile Templates](#textile-templates)
54
54
  * [RDoc Templates](#rdoc-templates)
55
+ * [AsciiDoc Templates](#asciidoc-templates)
55
56
  * [Radius Templates](#radius-templates)
56
57
  * [Markaby Templates](#markaby-templates)
57
58
  * [RABL Templates](#rabl-templates)
58
59
  * [Slim Templates](#slim-templates)
59
60
  * [Creole Templates](#creole-templates)
61
+ * [MediaWiki Templates](#mediawiki-templates)
60
62
  * [CoffeeScript Templates](#coffeescript-templates)
61
63
  * [Stylus Templates](#stylus-templates)
62
64
  * [Yajl Templates](#yajl-templates)
@@ -225,6 +227,17 @@ get '/posts.?:format?' do
225
227
  end
226
228
  ```
227
229
 
230
+ Routes may also utilize query parameters:
231
+
232
+ ``` ruby
233
+ get '/posts' do
234
+ # matches "GET /posts?title=foo&author=bar"
235
+ title = params[:title]
236
+ author = params[:author]
237
+ # uses title and author variables; query is optional to the /posts route
238
+ end
239
+ ```
240
+
228
241
  By the way, unless you disable the path traversal attack protection (see below),
229
242
  the request path might be modified before matching against your routes.
230
243
 
@@ -465,13 +478,13 @@ Available Options:
465
478
 
466
479
  <dt>layout</dt>
467
480
  <dd>
468
- Whether to use a layout (<tt>true</tt> or <tt>false</tt>), if it's a Symbol, specifies
481
+ Whether to use a layout (<tt>true</tt> or <tt>false</tt>). If it's a Symbol, specifies
469
482
  what template to use. Example: <tt>erb :index, :layout => !request.xhr?</tt>
470
483
  </dd>
471
484
 
472
485
  <dt>content_type</dt>
473
486
  <dd>
474
- Content-Type the template produces, default depends on template language.
487
+ Content-Type the template produces. Default depends on template language.
475
488
  </dd>
476
489
 
477
490
  <dt>scope</dt>
@@ -789,6 +802,26 @@ Since you cannot call Ruby from RDoc, you cannot use layouts written in
789
802
  RDoc. However, it is possible to use another rendering engine for the
790
803
  template than for the layout by passing the `:layout_engine` option.
791
804
 
805
+ #### AsciiDoc Templates
806
+
807
+ <table>
808
+ <tr>
809
+ <td>Dependency</td>
810
+ <td><a href="http://asciidoctor.org/" title="Asciidoctor">Asciidoctor</a></td>
811
+ </tr>
812
+ <tr>
813
+ <td>File Extension</td>
814
+ <td><tt>.asciidoc</tt>, <tt>.adoc</tt> and <tt>.ad</tt></td>
815
+ </tr>
816
+ <tr>
817
+ <td>Example</td>
818
+ <td><tt>asciidoc :README, :layout_engine => :erb</tt></td>
819
+ </tr>
820
+ </table>
821
+
822
+ Since you cannot call Ruby methods directly from an AsciiDoc template, you almost
823
+ always want to pass locals to it.
824
+
792
825
  #### Radius Templates
793
826
 
794
827
  <table>
@@ -897,6 +930,41 @@ Since you cannot call Ruby from Creole, you cannot use layouts written in
897
930
  Creole. However, it is possible to use another rendering engine for the
898
931
  template than for the layout by passing the `:layout_engine` option.
899
932
 
933
+ #### MediaWiki Templates
934
+
935
+ <table>
936
+ <tr>
937
+ <td>Dependency</td>
938
+ <td><a href="https://github.com/nricciar/wikicloth" title="WikiCloth">WikiCloth</a></td>
939
+ </tr>
940
+ <tr>
941
+ <td>File Extension</td>
942
+ <td><tt>.mediawiki</tt> and <tt>.mw</tt></td>
943
+ </tr>
944
+ <tr>
945
+ <td>Example</td>
946
+ <td><tt>mediawiki :wiki, :layout_engine => :erb</tt></td>
947
+ </tr>
948
+ </table>
949
+
950
+ It is not possible to call methods from MediaWiki markup, nor to pass locals to it.
951
+ You therefore will usually use it in combination with another rendering engine:
952
+
953
+ ``` ruby
954
+ erb :overview, :locals => { :text => mediawiki(:introduction) }
955
+ ```
956
+
957
+ Note that you may also call the `mediawiki` method from within other templates:
958
+
959
+ ``` ruby
960
+ %h1 Hello From Haml!
961
+ %p= mediawiki(:greetings)
962
+ ```
963
+
964
+ Since you cannot call Ruby from MediaWiki, you cannot use layouts written in
965
+ MediaWiki. However, it is possible to use another rendering engine for the
966
+ template than for the layout by passing the `:layout_engine` option.
967
+
900
968
  #### CoffeeScript Templates
901
969
 
902
970
  <table>
@@ -994,8 +1062,9 @@ json[:baz] = key
994
1062
  The `:callback` and `:variable` options can be used to decorate the rendered
995
1063
  object:
996
1064
 
997
- ``` ruby
998
- var resource = {"foo":"bar","baz":"qux"}; present(resource);
1065
+ ``` javascript
1066
+ var resource = {"foo":"bar","baz":"qux"};
1067
+ present(resource);
999
1068
  ```
1000
1069
 
1001
1070
  #### WLang Templates
@@ -1003,7 +1072,7 @@ var resource = {"foo":"bar","baz":"qux"}; present(resource);
1003
1072
  <table>
1004
1073
  <tr>
1005
1074
  <td>Dependency</td>
1006
- <td><a href="https://github.com/blambeau/wlang/" title="wlang">wlang</a></td>
1075
+ <td><a href="https://github.com/blambeau/wlang/" title="WLang">WLang</a></td>
1007
1076
  </tr>
1008
1077
  <tr>
1009
1078
  <td>File Extension</td>
@@ -1015,8 +1084,8 @@ var resource = {"foo":"bar","baz":"qux"}; present(resource);
1015
1084
  </tr>
1016
1085
  </table>
1017
1086
 
1018
- Since calling ruby methods is not idiomatic in wlang, you almost always want to pass locals
1019
- to it. Layouts written in wlang and `yield` are supported, though.
1087
+ Since calling ruby methods is not idiomatic in WLang, you almost always want to pass locals
1088
+ to it. Layouts written in WLang and `yield` are supported, though.
1020
1089
 
1021
1090
  ### Accessing Variables in Templates
1022
1091
 
@@ -1075,7 +1144,7 @@ erb :admin_layout, :layout => :main_layout do
1075
1144
  end
1076
1145
  ```
1077
1146
 
1078
- Currently the following rendering method accept a block: `erb`, `haml`,
1147
+ Currently, the following rendering methods accept a block: `erb`, `haml`,
1079
1148
  `liquid`, `slim `, `wlang`.
1080
1149
  Also the general `render` method accepts a block.
1081
1150
 
@@ -1180,9 +1249,9 @@ get '/foo/*' do
1180
1249
  end
1181
1250
  ```
1182
1251
 
1183
- After filters are evaluated after each request within the same context and can
1184
- also modify the request and response. Instance variables set in before filters
1185
- and routes are accessible by after filters:
1252
+ After filters are evaluated after each request within the same
1253
+ context as the routes will be and can also modify the request and response. Instance
1254
+ variables set in before filters and routes are accessible by after filters:
1186
1255
 
1187
1256
  ``` ruby
1188
1257
  after do
@@ -1447,7 +1516,7 @@ end
1447
1516
  ```
1448
1517
 
1449
1518
  This allows you to implement streaming APIs,
1450
- [Server Sent Events](http://dev.w3.org/html5/eventsource/) and can be used as
1519
+ [Server Sent Events](http://dev.w3.org/html5/eventsource/), and can be used as
1451
1520
  the basis for [WebSockets](http://en.wikipedia.org/wiki/WebSocket). It can also be
1452
1521
  used to increase throughput if some but not all content depends on a slow
1453
1522
  resource.
@@ -1507,7 +1576,7 @@ end
1507
1576
 
1508
1577
  This logger will automatically take your Rack handler's logging settings into
1509
1578
  account. If logging is disabled, this method will return a dummy object, so
1510
- you do not have to worry in your routes and filters about it.
1579
+ you do not have to worry about it in your routes and filters.
1511
1580
 
1512
1581
  Note that logging is only enabled for `Sinatra::Application` by
1513
1582
  default, so if you inherit from `Sinatra::Base`, you probably want to
@@ -1682,11 +1751,11 @@ end
1682
1751
  Use the `:static_cache_control` setting (see below) to add
1683
1752
  `Cache-Control` header info to static files.
1684
1753
 
1685
- According to RFC 2616 your application should behave differently if the If-Match
1686
- or If-None-Match header is set to `*` depending on whether the resource
1754
+ According to RFC 2616, your application should behave differently if the If-Match
1755
+ or If-None-Match header is set to `*`, depending on whether the resource
1687
1756
  requested is already in existence. Sinatra assumes resources for safe (like get)
1688
1757
  and idempotent (like put) requests are already in existence, whereas other
1689
- resources (for instance for post requests), are treated as new resources. You
1758
+ resources (for instance post requests) are treated as new resources. You
1690
1759
  can change this behavior by passing in a `:new_resource` option:
1691
1760
 
1692
1761
  ``` ruby
@@ -1742,7 +1811,7 @@ The options are:
1742
1811
 
1743
1812
  <dt>status</dt>
1744
1813
  <dd>
1745
- Status code to be send. Useful when sending a static file as an error page.
1814
+ Status code to be sent. Useful when sending a static file as an error page.
1746
1815
 
1747
1816
  If supported by the Rack handler, other means than streaming from the Ruby
1748
1817
  process will be used. If you use this helper method, Sinatra will automatically
@@ -2016,7 +2085,7 @@ set :protection, :session => true
2016
2085
 
2017
2086
  <dt>add_charsets</dt>
2018
2087
  <dd>
2019
- mime types the <tt>content_type</tt> helper will automatically add the charset info to.
2088
+ Mime types the <tt>content_type</tt> helper will automatically add the charset info to.
2020
2089
  You should add to it rather than overriding this option:
2021
2090
  <tt>settings.add_charsets << "application/foobar"</tt>
2022
2091
  </dd>
@@ -2031,19 +2100,19 @@ set :protection, :session => true
2031
2100
  <dd>IP address to bind to (default: <tt>0.0.0.0</tt> <em>or</em> <tt>localhost</tt> if your `environment` is set to development.). Only used for built-in server.</dd>
2032
2101
 
2033
2102
  <dt>default_encoding</dt>
2034
- <dd>encoding to assume if unknown (defaults to <tt>"utf-8"</tt>).</dd>
2103
+ <dd>Encoding to assume if unknown (defaults to <tt>"utf-8"</tt>).</dd>
2035
2104
 
2036
2105
  <dt>dump_errors</dt>
2037
- <dd>display errors in the log.</dd>
2106
+ <dd>Display errors in the log.</dd>
2038
2107
 
2039
2108
  <dt>environment</dt>
2040
2109
  <dd>
2041
- current environment, defaults to <tt>ENV['RACK_ENV']</tt>, or <tt>"development"</tt> if
2110
+ Current environment. Defaults to <tt>ENV['RACK_ENV']</tt>, or <tt>"development"</tt> if
2042
2111
  not available.
2043
2112
  </dd>
2044
2113
 
2045
2114
  <dt>logging</dt>
2046
- <dd>use the logger.</dd>
2115
+ <dd>Use the logger.</dd>
2047
2116
 
2048
2117
  <dt>lock</dt>
2049
2118
  <dd>
@@ -2054,7 +2123,7 @@ set :protection, :session => true
2054
2123
 
2055
2124
  <dt>method_override</dt>
2056
2125
  <dd>
2057
- use <tt>_method</tt> magic to allow put/delete forms in browsers that
2126
+ Use <tt>_method</tt> magic to allow put/delete forms in browsers that
2058
2127
  don't support it.
2059
2128
  </dd>
2060
2129
 
@@ -2093,18 +2162,18 @@ set :protection, :session => true
2093
2162
 
2094
2163
  <dt>raise_errors</dt>
2095
2164
  <dd>
2096
- raise exceptions (will stop application). Enabled by default when
2165
+ Raise exceptions (will stop application). Enabled by default when
2097
2166
  <tt>environment</tt> is set to <tt>"test"</tt>, disabled otherwise.
2098
2167
  </dd>
2099
2168
 
2100
2169
  <dt>run</dt>
2101
2170
  <dd>
2102
- if enabled, Sinatra will handle starting the web server, do not
2171
+ If enabled, Sinatra will handle starting the web server. Do not
2103
2172
  enable if using rackup or other means.
2104
2173
  </dd>
2105
2174
 
2106
2175
  <dt>running</dt>
2107
- <dd>is the built-in server running now? Do not change this setting!</dd>
2176
+ <dd>Is the built-in server running now? Do not change this setting!</dd>
2108
2177
 
2109
2178
  <dt>server</dt>
2110
2179
  <dd>
@@ -2156,6 +2225,9 @@ set :protection, :session => true
2156
2225
  for processing the request.
2157
2226
  </dd>
2158
2227
 
2228
+ <dt>traps</dt>
2229
+ <dd>Whether Sinatra should handle system signals.</dd>
2230
+
2159
2231
  <dt>views</dt>
2160
2232
  <dd>
2161
2233
  Path to the views folder. Inferred from <tt>app_file</tt> setting if
@@ -2315,8 +2387,7 @@ typically don't have to `use` them explicitly.
2315
2387
  You can find useful middleware in
2316
2388
  [rack](https://github.com/rack/rack/tree/master/lib/rack),
2317
2389
  [rack-contrib](https://github.com/rack/rack-contrib#readm),
2318
- with [CodeRack](http://coderack.org/) or in the
2319
- [Rack wiki](https://github.com/rack/rack/wiki/List-of-Middleware).
2390
+ or in the [Rack wiki](https://github.com/rack/rack/wiki/List-of-Middleware).
2320
2391
 
2321
2392
  ## Testing
2322
2393
 
@@ -2391,8 +2462,21 @@ available via the top-level DSL. Most top-level apps can be converted to
2391
2462
 
2392
2463
  `Sinatra::Base` is a blank slate. Most options are disabled by default,
2393
2464
  including the built-in server. See
2394
- [Options and Configuration](http://sinatra.github.com/configuration.html)
2395
- for details on available options and their behavior.
2465
+ [Configuring Settings](http://sinatra.github.com/configuration.html)
2466
+ for details on available options and their behavior. If you want
2467
+ behavior more similar to when you define your app at the top level (also
2468
+ know as Classic style), you
2469
+ can subclass `Sinatra::Application`.
2470
+
2471
+ ``` ruby
2472
+ require 'sinatra/base'
2473
+
2474
+ class MyApp < Sinatra::Application
2475
+ get '/' do
2476
+ 'Hello world!'
2477
+ end
2478
+ end
2479
+ ```
2396
2480
 
2397
2481
  ### Modular vs. Classic Style
2398
2482
 
@@ -2412,42 +2496,49 @@ different default settings:
2412
2496
  <th>Setting</th>
2413
2497
  <th>Classic</th>
2414
2498
  <th>Modular</th>
2499
+ <th>Modular</th>
2415
2500
  </tr>
2416
2501
 
2417
2502
  <tr>
2418
2503
  <td>app_file</td>
2419
2504
  <td>file loading sinatra</td>
2420
2505
  <td>file subclassing Sinatra::Base</td>
2506
+ <td>file subclassing Sinatra::Application</td>
2421
2507
  </tr>
2422
2508
 
2423
2509
  <tr>
2424
2510
  <td>run</td>
2425
2511
  <td>$0 == app_file</td>
2426
2512
  <td>false</td>
2513
+ <td>false</td>
2427
2514
  </tr>
2428
2515
 
2429
2516
  <tr>
2430
2517
  <td>logging</td>
2431
2518
  <td>true</td>
2432
2519
  <td>false</td>
2520
+ <td>true</td>
2433
2521
  </tr>
2434
2522
 
2435
2523
  <tr>
2436
2524
  <td>method_override</td>
2437
2525
  <td>true</td>
2438
2526
  <td>false</td>
2527
+ <td>true</td>
2439
2528
  </tr>
2440
2529
 
2441
2530
  <tr>
2442
2531
  <td>inline_templates</td>
2443
2532
  <td>true</td>
2444
2533
  <td>false</td>
2534
+ <td>true</td>
2445
2535
  </tr>
2446
2536
 
2447
2537
  <tr>
2448
2538
  <td>static</td>
2449
2539
  <td>true</td>
2450
2540
  <td>false</td>
2541
+ <td>true</td>
2451
2542
  </tr>
2452
2543
  </table>
2453
2544
 
@@ -2562,7 +2653,7 @@ end
2562
2653
  ### Dynamic Application Creation
2563
2654
 
2564
2655
  Sometimes you want to create new applications at runtime without having to
2565
- assign them to a constant, you can do this with `Sinatra.new`:
2656
+ assign them to a constant. You can do this with `Sinatra.new`:
2566
2657
 
2567
2658
  ``` ruby
2568
2659
  require 'sinatra/base'
@@ -2649,7 +2740,7 @@ You can reach the scope object (the class) like this:
2649
2740
  ### Request/Instance Scope
2650
2741
 
2651
2742
  For every incoming request, a new instance of your application class is
2652
- created and all handler blocks run in that scope. From within this scope you
2743
+ created, and all handler blocks run in that scope. From within this scope you
2653
2744
  can access the `request` and `session` objects or call rendering methods like
2654
2745
  `erb` or `haml`. You can access the application scope from within the request
2655
2746
  scope via the `settings` helper:
@@ -2796,7 +2887,7 @@ We also push out prerelease gems from time to time, so you can do a
2796
2887
  gem install sinatra --pre
2797
2888
  ```
2798
2889
 
2799
- To get some of the latest features.
2890
+ to get some of the latest features.
2800
2891
 
2801
2892
  ### With Bundler
2802
2893
 
@@ -2859,7 +2950,7 @@ rake sinatra.gemspec
2859
2950
  rake install
2860
2951
  ```
2861
2952
 
2862
- If you install gems as root, the last step should be
2953
+ If you install gems as root, the last step should be:
2863
2954
 
2864
2955
  ``` shell
2865
2956
  sudo rake install
@@ -63,6 +63,14 @@ end
63
63
  options '/' do
64
64
  # .. что-то ответить ..
65
65
  end
66
+
67
+ link '/' do
68
+ .. что-то подключить ..
69
+ end
70
+
71
+ unlink '/' do
72
+ .. что-то отключить ..
73
+ end
66
74
  ```
67
75
 
68
76
  Маршруты сверяются с запросом в порядке очередности их записи в файле
@@ -702,6 +710,26 @@ erb :overview, :locals => { :text => rdoc(:introduction) }
702
710
  для отображения шаблона, а другой для лэйаута с помощью опции
703
711
  `:layout_engine`.
704
712
 
713
+ #### AsciiDoc шаблоны
714
+
715
+ <table>
716
+ <tr>
717
+ <td>Зависимости</td>
718
+ <td><a href="http://asciidoctor.org/" title="Asciidoctor">Asciidoctor</a></td>
719
+ </tr>
720
+ <tr>
721
+ <td>Расширения файлов</td>
722
+ <td><tt>.asciidoc</tt>, <tt>.adoc</tt> и <tt>.ad</tt></td>
723
+ </tr>
724
+ <tr>
725
+ <td>Пример</td>
726
+ <td><tt>asciidoc :README, :layout_engine => :erb</tt></td>
727
+ </tr>
728
+ </table>
729
+
730
+ Так как в AsciiDoc шаблонах невозможно вызывать методы из Ruby напрямую, то вы
731
+ почти всегда будете передавать в шаблон локальные переменные.
732
+
705
733
  #### Radius шаблоны
706
734
 
707
735
  <table>
@@ -812,6 +840,43 @@ erb :overview, :locals => { :text => creole(:introduction) }
812
840
  один шаблонизатор для отображения шаблона, а другой для лэйаута с помощью
813
841
  опции `:layout_engine`.
814
842
 
843
+ #### MediaWiki шаблоны
844
+
845
+ <table>
846
+ <tr>
847
+ <td>Зависимости</td>
848
+ <td><a href="https://github.com/nricciar/wikicloth" title="WikiCloth">WikiCloth</a></td>
849
+ </tr>
850
+ <tr>
851
+ <td>Расширения файлов</td>
852
+ <td><tt>.mediawiki</tt> и <tt>.mw</tt></td>
853
+ </tr>
854
+ <tr>
855
+ <td>Пример</td>
856
+ <td><tt>mediawiki :wiki, :layout_engine => :erb</tt></td>
857
+ </tr>
858
+ </table>
859
+
860
+ В разметке MediaWiki невозможно вызывать методы или передавать локальные переменные.
861
+ Следовательно, вам, скорее всего, придется использовать этот шаблон совместно
862
+ с другим шаблонизатором:
863
+
864
+ ```ruby
865
+ erb :overview, :locals => { :text => mediawiki(:introduction) }
866
+ ```
867
+
868
+ Заметьте, что вы можете вызывать метод `mediawiki` из других шаблонов:
869
+
870
+ ```ruby
871
+ %h1 Hello From Haml!
872
+ %p= mediawiki(:greetings)
873
+ ```
874
+
875
+ Вы не можете вызывать Ruby из MediaWiki, соответственно, вы не можете
876
+ использовать лэйауты на MediaWiki. Тем не менее, есть возможность использовать
877
+ один шаблонизатор для отображения шаблона, а другой для лэйаута с помощью
878
+ опции `:layout_engine`.
879
+
815
880
  #### CoffeeScript шаблоны
816
881
 
817
882
  <table>
@@ -954,7 +1019,7 @@ end
954
1019
  end
955
1020
  ```
956
1021
 
957
- В настоящее время, следующие интерпретирубщие шаблоны методы
1022
+ В настоящее время, следующие интерпретирующие шаблоны методы
958
1023
  принимают блок:
959
1024
  `erb`, `haml`, `liquid`, `slim `, `wlang`.
960
1025
  Общий метод заполнения шаблонов `render` также принимает блок.
@@ -2051,6 +2116,9 @@ set :protection, :except => [:path_traversal, :session_hijacking]
2051
2116
  обработки запросов.
2052
2117
  </dd>
2053
2118
 
2119
+ <dt>traps</dt>
2120
+ <dd>должна ли Синатра обрабатывать системные сигналы или нет.</tt></dd>
2121
+
2054
2122
  <dt>views</dt>
2055
2123
  <dd>путь к директории с шаблонами.</dd>
2056
2124
  </dl>
@@ -2189,7 +2257,7 @@ Rack распространяется с различными стандартн
2189
2257
  Вы можете найти полезные прослойки в
2190
2258
  [rack](https://github.com/rack/rack/tree/master/lib/rack),
2191
2259
  [rack-contrib](https://github.com/rack/rack-contrib#readme),
2192
- [CodeRack](http://coderack.org/) или в
2260
+ или в
2193
2261
  [Rack wiki](https://github.com/rack/rack/wiki/List-of-Middleware).
2194
2262
 
2195
2263
  ## Тестирование