sinatra 2.2.0 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +93 -16
- data/Gemfile +44 -65
- data/README.md +104 -401
- data/Rakefile +65 -65
- data/VERSION +1 -1
- data/examples/chat.rb +5 -3
- data/examples/rainbows.rb +3 -1
- data/examples/simple.rb +2 -0
- data/examples/stream.ru +2 -0
- data/lib/sinatra/base.rb +345 -335
- data/lib/sinatra/indifferent_hash.rb +25 -33
- data/lib/sinatra/main.rb +18 -16
- data/lib/sinatra/show_exceptions.rb +17 -15
- data/lib/sinatra/version.rb +3 -1
- data/lib/sinatra.rb +2 -0
- data/sinatra.gemspec +38 -33
- metadata +38 -29
- data/README.de.md +0 -3239
- data/README.es.md +0 -3231
- data/README.fr.md +0 -3111
- data/README.hu.md +0 -728
- data/README.ja.md +0 -2844
- data/README.ko.md +0 -2967
- data/README.malayalam.md +0 -3141
- data/README.pt-br.md +0 -3787
- data/README.pt-pt.md +0 -791
- data/README.ru.md +0 -3207
- data/README.zh.md +0 -2934
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Sinatra
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/sinatra.svg)](https://badge.fury.io/rb/sinatra)
|
4
|
-
[![
|
5
|
-
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sinatra&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sinatra&package-manager=bundler&version-scheme=semver)
|
4
|
+
[![Testing](https://github.com/sinatra/sinatra/actions/workflows/test.yml/badge.svg)](https://github.com/sinatra/sinatra/actions/workflows/test.yml)
|
6
5
|
|
7
6
|
Sinatra is a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language) for
|
8
7
|
quickly creating web applications in Ruby with minimal effort:
|
@@ -20,6 +19,7 @@ Install the gem:
|
|
20
19
|
|
21
20
|
```shell
|
22
21
|
gem install sinatra
|
22
|
+
gem install puma # or any other server
|
23
23
|
```
|
24
24
|
|
25
25
|
And run with:
|
@@ -31,101 +31,92 @@ ruby myapp.rb
|
|
31
31
|
View at: [http://localhost:4567](http://localhost:4567)
|
32
32
|
|
33
33
|
The code you changed will not take effect until you restart the server.
|
34
|
-
Please restart the server every time you change or use
|
35
|
-
[
|
34
|
+
Please restart the server every time you change or use a code reloader
|
35
|
+
like [rerun](https://github.com/alexch/rerun) or
|
36
|
+
[rack-unreloader](https://github.com/jeremyevans/rack-unreloader).
|
36
37
|
|
37
38
|
It is recommended to also run `gem install puma`, which Sinatra will
|
38
39
|
pick up if available.
|
39
40
|
|
40
41
|
## Table of Contents
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
* [Application/Class Scope](#applicationclass-scope)
|
120
|
-
* [Request/Instance Scope](#requestinstance-scope)
|
121
|
-
* [Delegation Scope](#delegation-scope)
|
122
|
-
* [Command Line](#command-line)
|
123
|
-
* [Multi-threading](#multi-threading)
|
124
|
-
* [Requirement](#requirement)
|
125
|
-
* [The Bleeding Edge](#the-bleeding-edge)
|
126
|
-
* [With Bundler](#with-bundler)
|
127
|
-
* [Versioning](#versioning)
|
128
|
-
* [Further Reading](#further-reading)
|
43
|
+
- [Sinatra](#sinatra)
|
44
|
+
- [Table of Contents](#table-of-contents)
|
45
|
+
- [Routes](#routes)
|
46
|
+
- [Conditions](#conditions)
|
47
|
+
- [Return Values](#return-values)
|
48
|
+
- [Custom Route Matchers](#custom-route-matchers)
|
49
|
+
- [Static Files](#static-files)
|
50
|
+
- [Views / Templates](#views--templates)
|
51
|
+
- [Literal Templates](#literal-templates)
|
52
|
+
- [Available Template Languages](#available-template-languages)
|
53
|
+
- [Haml Templates](#haml-templates)
|
54
|
+
- [Erb Templates](#erb-templates)
|
55
|
+
- [Builder Templates](#builder-templates)
|
56
|
+
- [Nokogiri Templates](#nokogiri-templates)
|
57
|
+
- [Liquid Templates](#liquid-templates)
|
58
|
+
- [Markdown Templates](#markdown-templates)
|
59
|
+
- [RDoc Templates](#rdoc-templates)
|
60
|
+
- [AsciiDoc Templates](#asciidoc-templates)
|
61
|
+
- [Markaby Templates](#markaby-templates)
|
62
|
+
- [RABL Templates](#rabl-templates)
|
63
|
+
- [Slim Templates](#slim-templates)
|
64
|
+
- [Yajl Templates](#yajl-templates)
|
65
|
+
- [Accessing Variables in Templates](#accessing-variables-in-templates)
|
66
|
+
- [Templates with `yield` and nested layouts](#templates-with-yield-and-nested-layouts)
|
67
|
+
- [Inline Templates](#inline-templates)
|
68
|
+
- [Named Templates](#named-templates)
|
69
|
+
- [Associating File Extensions](#associating-file-extensions)
|
70
|
+
- [Adding Your Own Template Engine](#adding-your-own-template-engine)
|
71
|
+
- [Using Custom Logic for Template Lookup](#using-custom-logic-for-template-lookup)
|
72
|
+
- [Filters](#filters)
|
73
|
+
- [Helpers](#helpers)
|
74
|
+
- [Using Sessions](#using-sessions)
|
75
|
+
- [Session Secret Security](#session-secret-security)
|
76
|
+
- [Session Config](#session-config)
|
77
|
+
- [Choosing Your Own Session Middleware](#choosing-your-own-session-middleware)
|
78
|
+
- [Halting](#halting)
|
79
|
+
- [Passing](#passing)
|
80
|
+
- [Triggering Another Route](#triggering-another-route)
|
81
|
+
- [Setting Body, Status Code, and Headers](#setting-body-status-code-and-headers)
|
82
|
+
- [Streaming Responses](#streaming-responses)
|
83
|
+
- [Logging](#logging)
|
84
|
+
- [Mime Types](#mime-types)
|
85
|
+
- [Generating URLs](#generating-urls)
|
86
|
+
- [Browser Redirect](#browser-redirect)
|
87
|
+
- [Cache Control](#cache-control)
|
88
|
+
- [Sending Files](#sending-files)
|
89
|
+
- [Accessing the Request Object](#accessing-the-request-object)
|
90
|
+
- [Attachments](#attachments)
|
91
|
+
- [Dealing with Date and Time](#dealing-with-date-and-time)
|
92
|
+
- [Looking Up Template Files](#looking-up-template-files)
|
93
|
+
- [Configuration](#configuration)
|
94
|
+
- [Configuring attack protection](#configuring-attack-protection)
|
95
|
+
- [Available Settings](#available-settings)
|
96
|
+
- [Environments](#environments)
|
97
|
+
- [Error Handling](#error-handling)
|
98
|
+
- [Not Found](#not-found)
|
99
|
+
- [Error](#error)
|
100
|
+
- [Rack Middleware](#rack-middleware)
|
101
|
+
- [Testing](#testing)
|
102
|
+
- [Sinatra::Base - Middleware, Libraries, and Modular Apps](#sinatrabase---middleware-libraries-and-modular-apps)
|
103
|
+
- [Modular vs. Classic Style](#modular-vs-classic-style)
|
104
|
+
- [Serving a Modular Application](#serving-a-modular-application)
|
105
|
+
- [Using a Classic Style Application with a config.ru](#using-a-classic-style-application-with-a-configru)
|
106
|
+
- [When to use a config.ru?](#when-to-use-a-configru)
|
107
|
+
- [Using Sinatra as Middleware](#using-sinatra-as-middleware)
|
108
|
+
- [Dynamic Application Creation](#dynamic-application-creation)
|
109
|
+
- [Scopes and Binding](#scopes-and-binding)
|
110
|
+
- [Application/Class Scope](#applicationclass-scope)
|
111
|
+
- [Request/Instance Scope](#requestinstance-scope)
|
112
|
+
- [Delegation Scope](#delegation-scope)
|
113
|
+
- [Command Line](#command-line)
|
114
|
+
- [Multi-threading](#multi-threading)
|
115
|
+
- [Requirement](#requirement)
|
116
|
+
- [The Bleeding Edge](#the-bleeding-edge)
|
117
|
+
- [With Bundler](#with-bundler)
|
118
|
+
- [Versioning](#versioning)
|
119
|
+
- [Further Reading](#further-reading)
|
129
120
|
|
130
121
|
## Routes
|
131
122
|
|
@@ -382,15 +373,16 @@ stop there. You can easily define your own matchers:
|
|
382
373
|
|
383
374
|
```ruby
|
384
375
|
class AllButPattern
|
385
|
-
Match = Struct.new(:captures)
|
386
|
-
|
387
376
|
def initialize(except)
|
388
|
-
@except
|
389
|
-
|
377
|
+
@except = except
|
378
|
+
end
|
379
|
+
|
380
|
+
def to_pattern(options)
|
381
|
+
return self
|
390
382
|
end
|
391
383
|
|
392
|
-
def
|
393
|
-
|
384
|
+
def params(route)
|
385
|
+
return {} unless @except === route
|
394
386
|
end
|
395
387
|
end
|
396
388
|
|
@@ -407,20 +399,12 @@ Note that the above example might be over-engineered, as it can also be
|
|
407
399
|
expressed as:
|
408
400
|
|
409
401
|
```ruby
|
410
|
-
get
|
402
|
+
get /.*/ do
|
411
403
|
pass if request.path_info == "/index"
|
412
404
|
# ...
|
413
405
|
end
|
414
406
|
```
|
415
407
|
|
416
|
-
Or, using negative look ahead:
|
417
|
-
|
418
|
-
```ruby
|
419
|
-
get %r{(?!/index)} do
|
420
|
-
# ...
|
421
|
-
end
|
422
|
-
```
|
423
|
-
|
424
408
|
## Static Files
|
425
409
|
|
426
410
|
Static files are served from the `./public` directory. You can specify
|
@@ -584,7 +568,7 @@ Some languages have multiple implementations. To specify what implementation
|
|
584
568
|
to use (and to be thread-safe), you should simply require it first:
|
585
569
|
|
586
570
|
```ruby
|
587
|
-
require 'rdiscount'
|
571
|
+
require 'rdiscount'
|
588
572
|
get('/') { markdown :index }
|
589
573
|
```
|
590
574
|
|
@@ -612,14 +596,12 @@ get('/') { markdown :index }
|
|
612
596
|
<td>Dependency</td>
|
613
597
|
<td>
|
614
598
|
<a href="https://github.com/jeremyevans/erubi" title="erubi">erubi</a>
|
615
|
-
or <a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
|
616
599
|
or erb (included in Ruby)
|
617
600
|
</td>
|
618
601
|
</tr>
|
619
602
|
<tr>
|
620
603
|
<td>File Extensions</td>
|
621
|
-
<td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubi</tt> (Erubi only)
|
622
|
-
or <tt>.erubis</tt> (Erubis only)</td>
|
604
|
+
<td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubi</tt> (Erubi only)</td>
|
623
605
|
</tr>
|
624
606
|
<tr>
|
625
607
|
<td>Example</td>
|
@@ -667,56 +649,6 @@ It also takes a block for inline templates (see [example](#inline-templates)).
|
|
667
649
|
|
668
650
|
It also takes a block for inline templates (see [example](#inline-templates)).
|
669
651
|
|
670
|
-
#### Sass Templates
|
671
|
-
|
672
|
-
<table>
|
673
|
-
<tr>
|
674
|
-
<td>Dependency</td>
|
675
|
-
<td><a href="https://sass-lang.com/" title="sass">sass</a></td>
|
676
|
-
</tr>
|
677
|
-
<tr>
|
678
|
-
<td>File Extension</td>
|
679
|
-
<td><tt>.sass</tt></td>
|
680
|
-
</tr>
|
681
|
-
<tr>
|
682
|
-
<td>Example</td>
|
683
|
-
<td><tt>sass :stylesheet, :style => :expanded</tt></td>
|
684
|
-
</tr>
|
685
|
-
</table>
|
686
|
-
|
687
|
-
#### SCSS Templates
|
688
|
-
|
689
|
-
<table>
|
690
|
-
<tr>
|
691
|
-
<td>Dependency</td>
|
692
|
-
<td><a href="https://sass-lang.com/" title="sass">sass</a></td>
|
693
|
-
</tr>
|
694
|
-
<tr>
|
695
|
-
<td>File Extension</td>
|
696
|
-
<td><tt>.scss</tt></td>
|
697
|
-
</tr>
|
698
|
-
<tr>
|
699
|
-
<td>Example</td>
|
700
|
-
<td><tt>scss :stylesheet, :style => :expanded</tt></td>
|
701
|
-
</tr>
|
702
|
-
</table>
|
703
|
-
|
704
|
-
#### Less Templates
|
705
|
-
|
706
|
-
<table>
|
707
|
-
<tr>
|
708
|
-
<td>Dependency</td>
|
709
|
-
<td><a href="http://lesscss.org/" title="less">less</a></td>
|
710
|
-
</tr>
|
711
|
-
<tr>
|
712
|
-
<td>File Extension</td>
|
713
|
-
<td><tt>.less</tt></td>
|
714
|
-
</tr>
|
715
|
-
<tr>
|
716
|
-
<td>Example</td>
|
717
|
-
<td><tt>less :stylesheet</tt></td>
|
718
|
-
</tr>
|
719
|
-
</table>
|
720
652
|
|
721
653
|
#### Liquid Templates
|
722
654
|
|
@@ -747,9 +679,7 @@ template, you almost always want to pass locals to it.
|
|
747
679
|
Anyone of:
|
748
680
|
<a href="https://github.com/davidfstr/rdiscount" title="RDiscount">RDiscount</a>,
|
749
681
|
<a href="https://github.com/vmg/redcarpet" title="RedCarpet">RedCarpet</a>,
|
750
|
-
<a href="https://github.com/ged/bluecloth" title="BlueCloth">BlueCloth</a>,
|
751
682
|
<a href="https://kramdown.gettalong.org/" title="kramdown">kramdown</a>,
|
752
|
-
<a href="https://github.com/bhollis/maruku" title="maruku">maruku</a>
|
753
683
|
<a href="https://github.com/gjtorikian/commonmarker" title="commonmarker">commonmarker</a>
|
754
684
|
<a href="https://github.com/alphabetum/pandoc-ruby" title="pandoc">pandoc</a>
|
755
685
|
</td>
|
@@ -784,42 +714,6 @@ Since you cannot call Ruby from Markdown, you cannot use layouts written in
|
|
784
714
|
Markdown. However, it is possible to use another rendering engine for the
|
785
715
|
template than for the layout by passing the `:layout_engine` option.
|
786
716
|
|
787
|
-
#### Textile Templates
|
788
|
-
|
789
|
-
<table>
|
790
|
-
<tr>
|
791
|
-
<td>Dependency</td>
|
792
|
-
<td><a href="http://redcloth.org/" title="RedCloth">RedCloth</a></td>
|
793
|
-
</tr>
|
794
|
-
<tr>
|
795
|
-
<td>File Extension</td>
|
796
|
-
<td><tt>.textile</tt></td>
|
797
|
-
</tr>
|
798
|
-
<tr>
|
799
|
-
<td>Example</td>
|
800
|
-
<td><tt>textile :index, :layout_engine => :erb</tt></td>
|
801
|
-
</tr>
|
802
|
-
</table>
|
803
|
-
|
804
|
-
It is not possible to call methods from Textile, nor to pass locals to
|
805
|
-
it. You therefore will usually use it in combination with another
|
806
|
-
rendering engine:
|
807
|
-
|
808
|
-
```ruby
|
809
|
-
erb :overview, :locals => { :text => textile(:introduction) }
|
810
|
-
```
|
811
|
-
|
812
|
-
Note that you may also call the `textile` method from within other templates:
|
813
|
-
|
814
|
-
```ruby
|
815
|
-
%h1 Hello From Haml!
|
816
|
-
%p= textile(:greetings)
|
817
|
-
```
|
818
|
-
|
819
|
-
Since you cannot call Ruby from Textile, you cannot use layouts written in
|
820
|
-
Textile. However, it is possible to use another rendering engine for the
|
821
|
-
template than for the layout by passing the `:layout_engine` option.
|
822
|
-
|
823
717
|
#### RDoc Templates
|
824
718
|
|
825
719
|
<table>
|
@@ -875,26 +769,6 @@ template than for the layout by passing the `:layout_engine` option.
|
|
875
769
|
Since you cannot call Ruby methods directly from an AsciiDoc template, you
|
876
770
|
almost always want to pass locals to it.
|
877
771
|
|
878
|
-
#### Radius Templates
|
879
|
-
|
880
|
-
<table>
|
881
|
-
<tr>
|
882
|
-
<td>Dependency</td>
|
883
|
-
<td><a href="https://github.com/jlong/radius" title="Radius">Radius</a></td>
|
884
|
-
</tr>
|
885
|
-
<tr>
|
886
|
-
<td>File Extension</td>
|
887
|
-
<td><tt>.radius</tt></td>
|
888
|
-
</tr>
|
889
|
-
<tr>
|
890
|
-
<td>Example</td>
|
891
|
-
<td><tt>radius :index, :locals => { :key => 'value' }</tt></td>
|
892
|
-
</tr>
|
893
|
-
</table>
|
894
|
-
|
895
|
-
Since you cannot call Ruby methods directly from a Radius template, you
|
896
|
-
almost always want to pass locals to it.
|
897
|
-
|
898
772
|
#### Markaby Templates
|
899
773
|
|
900
774
|
<table>
|
@@ -948,139 +822,6 @@ It also takes a block for inline templates (see [example](#inline-templates)).
|
|
948
822
|
</tr>
|
949
823
|
</table>
|
950
824
|
|
951
|
-
#### Creole Templates
|
952
|
-
|
953
|
-
<table>
|
954
|
-
<tr>
|
955
|
-
<td>Dependency</td>
|
956
|
-
<td><a href="https://github.com/minad/creole" title="Creole">Creole</a></td>
|
957
|
-
</tr>
|
958
|
-
<tr>
|
959
|
-
<td>File Extension</td>
|
960
|
-
<td><tt>.creole</tt></td>
|
961
|
-
</tr>
|
962
|
-
<tr>
|
963
|
-
<td>Example</td>
|
964
|
-
<td><tt>creole :wiki, :layout_engine => :erb</tt></td>
|
965
|
-
</tr>
|
966
|
-
</table>
|
967
|
-
|
968
|
-
It is not possible to call methods from Creole, nor to pass locals to it. You
|
969
|
-
therefore will usually use it in combination with another rendering engine:
|
970
|
-
|
971
|
-
```ruby
|
972
|
-
erb :overview, :locals => { :text => creole(:introduction) }
|
973
|
-
```
|
974
|
-
|
975
|
-
Note that you may also call the `creole` method from within other templates:
|
976
|
-
|
977
|
-
```ruby
|
978
|
-
%h1 Hello From Haml!
|
979
|
-
%p= creole(:greetings)
|
980
|
-
```
|
981
|
-
|
982
|
-
Since you cannot call Ruby from Creole, you cannot use layouts written in
|
983
|
-
Creole. However, it is possible to use another rendering engine for the
|
984
|
-
template than for the layout by passing the `:layout_engine` option.
|
985
|
-
|
986
|
-
#### MediaWiki Templates
|
987
|
-
|
988
|
-
<table>
|
989
|
-
<tr>
|
990
|
-
<td>Dependency</td>
|
991
|
-
<td><a href="https://github.com/nricciar/wikicloth" title="WikiCloth">WikiCloth</a></td>
|
992
|
-
</tr>
|
993
|
-
<tr>
|
994
|
-
<td>File Extension</td>
|
995
|
-
<td><tt>.mediawiki</tt> and <tt>.mw</tt></td>
|
996
|
-
</tr>
|
997
|
-
<tr>
|
998
|
-
<td>Example</td>
|
999
|
-
<td><tt>mediawiki :wiki, :layout_engine => :erb</tt></td>
|
1000
|
-
</tr>
|
1001
|
-
</table>
|
1002
|
-
|
1003
|
-
It is not possible to call methods from MediaWiki markup, nor to pass
|
1004
|
-
locals to it. You therefore will usually use it in combination with
|
1005
|
-
another rendering engine:
|
1006
|
-
|
1007
|
-
```ruby
|
1008
|
-
erb :overview, :locals => { :text => mediawiki(:introduction) }
|
1009
|
-
```
|
1010
|
-
|
1011
|
-
Note that you may also call the `mediawiki` method from within other
|
1012
|
-
templates:
|
1013
|
-
|
1014
|
-
```ruby
|
1015
|
-
%h1 Hello From Haml!
|
1016
|
-
%p= mediawiki(:greetings)
|
1017
|
-
```
|
1018
|
-
|
1019
|
-
Since you cannot call Ruby from MediaWiki, you cannot use layouts written in
|
1020
|
-
MediaWiki. However, it is possible to use another rendering engine for the
|
1021
|
-
template than for the layout by passing the `:layout_engine` option.
|
1022
|
-
|
1023
|
-
#### CoffeeScript Templates
|
1024
|
-
|
1025
|
-
<table>
|
1026
|
-
<tr>
|
1027
|
-
<td>Dependency</td>
|
1028
|
-
<td>
|
1029
|
-
<a href="https://github.com/josh/ruby-coffee-script" title="Ruby CoffeeScript">
|
1030
|
-
CoffeeScript
|
1031
|
-
</a> and a
|
1032
|
-
<a href="https://github.com/sstephenson/execjs" title="ExecJS">
|
1033
|
-
way to execute javascript
|
1034
|
-
</a>
|
1035
|
-
</td>
|
1036
|
-
</tr>
|
1037
|
-
<tr>
|
1038
|
-
<td>File Extension</td>
|
1039
|
-
<td><tt>.coffee</tt></td>
|
1040
|
-
</tr>
|
1041
|
-
<tr>
|
1042
|
-
<td>Example</td>
|
1043
|
-
<td><tt>coffee :index</tt></td>
|
1044
|
-
</tr>
|
1045
|
-
</table>
|
1046
|
-
|
1047
|
-
#### Stylus Templates
|
1048
|
-
|
1049
|
-
<table>
|
1050
|
-
<tr>
|
1051
|
-
<td>Dependency</td>
|
1052
|
-
<td>
|
1053
|
-
<a href="https://github.com/forgecrafted/ruby-stylus" title="Ruby Stylus">
|
1054
|
-
Stylus
|
1055
|
-
</a> and a
|
1056
|
-
<a href="https://github.com/sstephenson/execjs" title="ExecJS">
|
1057
|
-
way to execute javascript
|
1058
|
-
</a>
|
1059
|
-
</td>
|
1060
|
-
</tr>
|
1061
|
-
<tr>
|
1062
|
-
<td>File Extension</td>
|
1063
|
-
<td><tt>.styl</tt></td>
|
1064
|
-
</tr>
|
1065
|
-
<tr>
|
1066
|
-
<td>Example</td>
|
1067
|
-
<td><tt>stylus :index</tt></td>
|
1068
|
-
</tr>
|
1069
|
-
</table>
|
1070
|
-
|
1071
|
-
Before being able to use Stylus templates, you need to load `stylus` and
|
1072
|
-
`stylus/tilt` first:
|
1073
|
-
|
1074
|
-
```ruby
|
1075
|
-
require 'sinatra'
|
1076
|
-
require 'stylus'
|
1077
|
-
require 'stylus/tilt'
|
1078
|
-
|
1079
|
-
get '/' do
|
1080
|
-
stylus :example
|
1081
|
-
end
|
1082
|
-
```
|
1083
|
-
|
1084
825
|
#### Yajl Templates
|
1085
826
|
|
1086
827
|
<table>
|
@@ -1122,27 +863,6 @@ var resource = {"foo":"bar","baz":"qux"};
|
|
1122
863
|
present(resource);
|
1123
864
|
```
|
1124
865
|
|
1125
|
-
#### WLang Templates
|
1126
|
-
|
1127
|
-
<table>
|
1128
|
-
<tr>
|
1129
|
-
<td>Dependency</td>
|
1130
|
-
<td><a href="https://github.com/blambeau/wlang" title="WLang">WLang</a></td>
|
1131
|
-
</tr>
|
1132
|
-
<tr>
|
1133
|
-
<td>File Extension</td>
|
1134
|
-
<td><tt>.wlang</tt></td>
|
1135
|
-
</tr>
|
1136
|
-
<tr>
|
1137
|
-
<td>Example</td>
|
1138
|
-
<td><tt>wlang :index, :locals => { :key => 'value' }</tt></td>
|
1139
|
-
</tr>
|
1140
|
-
</table>
|
1141
|
-
|
1142
|
-
Since calling ruby methods is not idiomatic in WLang, you almost always
|
1143
|
-
want to pass locals to it. Layouts written in WLang and `yield` are
|
1144
|
-
supported, though.
|
1145
|
-
|
1146
866
|
### Accessing Variables in Templates
|
1147
867
|
|
1148
868
|
Templates are evaluated within the same context as route handlers. Instance
|
@@ -1201,7 +921,7 @@ end
|
|
1201
921
|
```
|
1202
922
|
|
1203
923
|
Currently, the following rendering methods accept a block: `erb`, `haml`,
|
1204
|
-
`liquid`, `slim
|
924
|
+
`liquid`, `slim `. Also, the general `render` method accepts a block.
|
1205
925
|
|
1206
926
|
### Inline Templates
|
1207
927
|
|
@@ -1218,7 +938,7 @@ __END__
|
|
1218
938
|
|
1219
939
|
@@ layout
|
1220
940
|
%html
|
1221
|
-
|
941
|
+
!= yield
|
1222
942
|
|
1223
943
|
@@ index
|
1224
944
|
%div.title Hello world.
|
@@ -1261,10 +981,10 @@ end
|
|
1261
981
|
|
1262
982
|
To associate a file extension with a template engine, use
|
1263
983
|
`Tilt.register`. For instance, if you like to use the file extension
|
1264
|
-
`tt` for
|
984
|
+
`tt` for Haml templates, you can do the following:
|
1265
985
|
|
1266
986
|
```ruby
|
1267
|
-
Tilt.register :tt, Tilt[:
|
987
|
+
Tilt.register :tt, Tilt[:haml]
|
1268
988
|
```
|
1269
989
|
|
1270
990
|
### Adding Your Own Template Engine
|
@@ -2136,7 +1856,7 @@ end
|
|
2136
1856
|
Another example would be using different directories for different engines:
|
2137
1857
|
|
2138
1858
|
```ruby
|
2139
|
-
set :views, :
|
1859
|
+
set :views, :haml => 'templates', :default => 'views'
|
2140
1860
|
|
2141
1861
|
helpers do
|
2142
1862
|
def find_template(views, name, engine, &block)
|
@@ -3085,9 +2805,9 @@ rainbows -c rainbows.conf
|
|
3085
2805
|
|
3086
2806
|
The following Ruby versions are officially supported:
|
3087
2807
|
<dl>
|
3088
|
-
<dt>Ruby 2.
|
2808
|
+
<dt>Ruby 2.6</dt>
|
3089
2809
|
<dd>
|
3090
|
-
2.
|
2810
|
+
2.6 is fully supported and recommended. There are currently no plans to
|
3091
2811
|
drop official support for it.
|
3092
2812
|
</dd>
|
3093
2813
|
|
@@ -3105,32 +2825,15 @@ The following Ruby versions are officially supported:
|
|
3105
2825
|
</dd>
|
3106
2826
|
</dl>
|
3107
2827
|
|
3108
|
-
Versions of Ruby before 2.
|
3109
|
-
|
3110
|
-
We also keep an eye on upcoming Ruby versions.
|
3111
|
-
|
3112
|
-
The following Ruby implementations are not officially supported but still are
|
3113
|
-
known to run Sinatra:
|
2828
|
+
Versions of Ruby before 2.6 are no longer supported as of Sinatra 3.0.0.
|
3114
2829
|
|
3115
|
-
|
3116
|
-
|
3117
|
-
* MacRuby, Maglev, IronRuby
|
3118
|
-
* Ruby 1.9.0 and 1.9.1 (but we do recommend against using those)
|
3119
|
-
|
3120
|
-
Not being officially supported means if things only break there and not on a
|
3121
|
-
supported platform, we assume it's not our issue but theirs.
|
3122
|
-
|
3123
|
-
We also run our CI against ruby-head (future releases of MRI), but we
|
3124
|
-
can't guarantee anything, since it is constantly moving. Expect upcoming
|
3125
|
-
2.x releases to be fully supported.
|
2830
|
+
We also keep an eye on upcoming Ruby versions. Expect upcoming
|
2831
|
+
3.x releases to be fully supported.
|
3126
2832
|
|
3127
2833
|
Sinatra should work on any operating system supported by the chosen Ruby
|
3128
2834
|
implementation.
|
3129
2835
|
|
3130
|
-
|
3131
|
-
|
3132
|
-
Sinatra currently doesn't run on Cardinal, SmallRuby, BlueRuby or any
|
3133
|
-
Ruby version prior to 2.2.
|
2836
|
+
Running Sinatra on a not officially supported Ruby flavor means that if things only break there we assume it's not our issue but theirs.
|
3134
2837
|
|
3135
2838
|
## The Bleeding Edge
|
3136
2839
|
|
@@ -3200,4 +2903,4 @@ SemVerTag.
|
|
3200
2903
|
* API documentation for the [latest release](http://www.rubydoc.info/gems/sinatra)
|
3201
2904
|
or the [current HEAD](http://www.rubydoc.info/github/sinatra/sinatra) on
|
3202
2905
|
[RubyDoc](http://www.rubydoc.info/)
|
3203
|
-
* [CI
|
2906
|
+
* [CI Actions](https://github.com/sinatra/sinatra/actions)
|