sinatra 1.2.0.a → 1.2.0.c
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/AUTHORS +2 -0
- data/CHANGES +69 -1
- data/Gemfile +35 -0
- data/Gemfile.lock +74 -0
- data/README.de.rdoc +16 -16
- data/README.es.rdoc +360 -80
- data/README.fr.rdoc +16 -16
- data/README.hu.rdoc +4 -4
- data/README.jp.rdoc +16 -16
- data/README.pt-br.rdoc +6 -6
- data/README.rdoc +629 -95
- data/README.ru.rdoc +317 -103
- data/README.zh.rdoc +16 -16
- data/Rakefile +6 -14
- data/lib/sinatra/base.rb +70 -30
- data/lib/sinatra/showexceptions.rb +25 -0
- data/sinatra.gemspec +8 -18
- data/test/builder_test.rb +6 -0
- data/test/coffee_test.rb +1 -1
- data/test/erubis_test.rb +6 -0
- data/test/haml_test.rb +2 -1
- data/test/helpers_test.rb +53 -0
- data/test/less_test.rb +6 -0
- data/test/liquid_test.rb +2 -1
- data/test/markaby_test.rb +2 -1
- data/test/markdown_test.rb +3 -2
- data/test/nokogiri_test.rb +2 -1
- data/test/radius_test.rb +3 -2
- data/test/rdoc_test.rb +2 -1
- data/test/routing_test.rb +49 -5
- data/test/sass_test.rb +1 -1
- data/test/scss_test.rb +1 -1
- data/test/slim_test.rb +2 -1
- data/test/templates_test.rb +43 -0
- data/test/textile_test.rb +2 -1
- data/test/views/a/in_a.str +1 -0
- data/test/views/b/in_b.str +1 -0
- data/test/views/calc.html.erb +1 -0
- metadata +22 -223
data/AUTHORS
CHANGED
@@ -36,6 +36,8 @@ Sinatra would not be possible:
|
|
36
36
|
* Rick Olson (technoweenie) for the killer plug at RailsConf '08.
|
37
37
|
* Steven Garcia for the amazing custom artwork you see on 404's and 500's
|
38
38
|
* Pat Nakajima (nakajima) for fixing non-nested params in nested params Hash's.
|
39
|
+
* Konstantin Haase for his hard work and ongoing commitment to improving
|
40
|
+
Sinatra, for 1.1.0, 1.2.0 and beyond..
|
39
41
|
|
40
42
|
and last but not least:
|
41
43
|
|
data/CHANGES
CHANGED
@@ -6,7 +6,71 @@
|
|
6
6
|
* The `markaby` rendering method now allows passing a block, making inline
|
7
7
|
usage possible. Requires Tilt 1.2 or newer. (Konstantin Haase)
|
8
8
|
|
9
|
-
|
9
|
+
* All render methods now take a `:layout_engine` option, allowing to use a
|
10
|
+
layout in a different template language. Even more useful than using this
|
11
|
+
directly (`erb :index, :layout_engine => :haml`) is setting this globally for
|
12
|
+
a template engine that otherwise does not support layouts, like Markdown or
|
13
|
+
Textile (`set :markdown, :layout_engine => :erb`). (Konstantin Haase)
|
14
|
+
|
15
|
+
* Before and after filters now support conditions, both with and without
|
16
|
+
patterns (`before '/api/*', :agent => /Songbird/`). (Konstantin Haase)
|
17
|
+
|
18
|
+
* Added a `url` helper method which constructs absolute URLs. Copes with
|
19
|
+
reverse proxies and Rack handlers correctly. Aliased to `to`, so you can
|
20
|
+
write `redirect to('/foo')`. (Konstantin Haase)
|
21
|
+
|
22
|
+
* If running on 1.9, patterns for routes and filters now support named
|
23
|
+
captures: `get(%r{/hi/(?<name>[^/?#]+)}) { "Hi #{params['name']}" }`.
|
24
|
+
(Steve Price)
|
25
|
+
|
26
|
+
* All rendering methods now take a `:scope` option, which renders them in
|
27
|
+
another context. Note that helpers and instance variables will be
|
28
|
+
unavailable if you use this feature. (Paul Walker)
|
29
|
+
|
30
|
+
* The behavior of `redirect` can now be configured with `absolute_redirects`
|
31
|
+
and `prefixed_redirects`. (Konstantin Haase)
|
32
|
+
|
33
|
+
* `send_file` now allows overriding the Last-Modified header, which defaults
|
34
|
+
to the file's mtime, by passing a `:last_modified` option. (Konstantin Haase)
|
35
|
+
|
36
|
+
* You can use your own template lookup method by defining `find_template`.
|
37
|
+
This allows, among other things, using more than one views folder.
|
38
|
+
(Konstantin Haase)
|
39
|
+
|
40
|
+
* Largely improved documentation. (burningTyger, Vasily Polovnyov, Gabriel
|
41
|
+
Andretta, Konstantin Haase)
|
42
|
+
|
43
|
+
* Improved error handling. (cactus, Konstantin Haase)
|
44
|
+
|
45
|
+
* Skip missing template engines in tests correctly. (cactus)
|
46
|
+
|
47
|
+
* Sinatra now ships with a Gemfile for development dependencies, since it eases
|
48
|
+
supporting different platforms, like JRuby. (Konstantin Haase)
|
49
|
+
|
50
|
+
= 1.1.3 / Not Yet Released
|
51
|
+
|
52
|
+
* Fixed issues with `user_agent` condition if the user agent header is missing.
|
53
|
+
(Konstantin Haase)
|
54
|
+
|
55
|
+
* Fix some routing tests that have been skipped by accident (Ross A. Baker)
|
56
|
+
|
57
|
+
* Fix rendering issues with Builder and Nokogiri (Konstantin Haase)
|
58
|
+
|
59
|
+
* Replace last_modified helper with better implementation. (cactus,
|
60
|
+
Konstantin Haase)
|
61
|
+
|
62
|
+
* Fix issue with charset not being set when using `provides` condition.
|
63
|
+
(Konstantin Haase)
|
64
|
+
|
65
|
+
* Fix issue with `render` not picking up all alternative file extensions for
|
66
|
+
a rendering engine - it was not possible to register ".html.erb" without
|
67
|
+
tricks. (Konstantin Haase)
|
68
|
+
|
69
|
+
= 1.1.2 / 2010-10-25
|
70
|
+
|
71
|
+
Like 1.1.1, but with proper CHANGES file.
|
72
|
+
|
73
|
+
= 1.1.1 / 2010-10-25
|
10
74
|
|
11
75
|
* README has been translated to Russian (Nickolay Schwarz, Vasily Polovnyov)
|
12
76
|
and Portuguese (Luciano Sousa).
|
@@ -34,6 +98,10 @@
|
|
34
98
|
* Headers set by cache_control now always set max_age as an Integer, making
|
35
99
|
sure it is compatible with RFC2616. (Konstantin Haase)
|
36
100
|
|
101
|
+
* Further improved handling of string encodings on Ruby 1.9, templates now
|
102
|
+
honor default_encoding and URLs support unicode characters. (Konstantin
|
103
|
+
Haase)
|
104
|
+
|
37
105
|
= 1.1.0 / 2010-10-24
|
38
106
|
|
39
107
|
* Before and after filters now support pattern matching, including the
|
data/Gemfile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Why use bundler?
|
2
|
+
# Well, not all development dependencies install on all rubies. Moreover, `gem
|
3
|
+
# install sinatra --development` doesn't work, as it will also try to install
|
4
|
+
# development dependencies of our dependencies, and those are not conflict free.
|
5
|
+
# So, here we are, `bundle install`.
|
6
|
+
#
|
7
|
+
# If you have issues with on gem: `bundle install --without-coffee-script`.
|
8
|
+
|
9
|
+
source :rubygems
|
10
|
+
gemspec
|
11
|
+
|
12
|
+
gem 'rake'
|
13
|
+
gem 'rack-test', '>= 0.5.6'
|
14
|
+
|
15
|
+
gem 'haml', '>= 3.0', :group => 'haml'
|
16
|
+
gem 'builder', :group => 'builder'
|
17
|
+
gem 'erubis', :group => 'erubis'
|
18
|
+
gem 'less', :group => 'less'
|
19
|
+
gem 'liquid', :group => 'liquid'
|
20
|
+
gem 'RedCloth', :group => 'redcloth'
|
21
|
+
gem 'rdoc', :group => 'rdoc'
|
22
|
+
gem 'nokogiri', :group => 'nokogiri'
|
23
|
+
gem 'slim', :group => 'slim'
|
24
|
+
|
25
|
+
gem 'coffee-script', '>= 2.0', :group => 'coffee-script'
|
26
|
+
|
27
|
+
platforms :ruby do
|
28
|
+
gem 'rdiscount', :group => 'rdiscount'
|
29
|
+
end
|
30
|
+
|
31
|
+
platforms :ruby_18, :jruby do
|
32
|
+
gem 'json', :group => 'coffee-script'
|
33
|
+
gem 'markaby', :group => 'markaby'
|
34
|
+
gem 'radius', :group => 'radius'
|
35
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sinatra (1.2.0.a)
|
5
|
+
rack (~> 1.1)
|
6
|
+
tilt (>= 1.2.2, < 2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
RedCloth (4.2.7)
|
12
|
+
RedCloth (4.2.7-java)
|
13
|
+
abstract (1.0.0)
|
14
|
+
builder (3.0.0)
|
15
|
+
coffee-script (2.1.3)
|
16
|
+
coffee-script-source
|
17
|
+
coffee-script-source (1.0.1)
|
18
|
+
erubis (2.6.6)
|
19
|
+
abstract (>= 1.0.0)
|
20
|
+
haml (3.0.25)
|
21
|
+
json (1.5.1)
|
22
|
+
json (1.5.1-java)
|
23
|
+
less (1.2.21)
|
24
|
+
mutter (>= 0.4.2)
|
25
|
+
treetop (>= 1.4.2)
|
26
|
+
liquid (2.2.2)
|
27
|
+
markaby (0.7.1)
|
28
|
+
builder (>= 2.0.0)
|
29
|
+
mutter (0.5.3)
|
30
|
+
nokogiri (1.4.4)
|
31
|
+
nokogiri (1.4.4-java)
|
32
|
+
weakling (>= 0.0.3)
|
33
|
+
polyglot (0.3.1)
|
34
|
+
rack (1.2.1)
|
35
|
+
rack-test (0.5.7)
|
36
|
+
rack (>= 1.0)
|
37
|
+
radius (0.6.1)
|
38
|
+
rake (0.8.7)
|
39
|
+
rdiscount (1.6.8)
|
40
|
+
rdoc (3.5.3)
|
41
|
+
shotgun (0.8)
|
42
|
+
rack (>= 1.0)
|
43
|
+
slim (0.9.0)
|
44
|
+
temple (~> 0.1.7)
|
45
|
+
tilt (~> 1.2)
|
46
|
+
temple (0.1.7)
|
47
|
+
tilt (1.2.2)
|
48
|
+
treetop (1.4.9)
|
49
|
+
polyglot (>= 0.3.1)
|
50
|
+
weakling (0.0.4-java)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
java
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
RedCloth
|
58
|
+
builder
|
59
|
+
coffee-script (>= 2.0)
|
60
|
+
erubis
|
61
|
+
haml (>= 3.0)
|
62
|
+
json
|
63
|
+
less
|
64
|
+
liquid
|
65
|
+
markaby
|
66
|
+
nokogiri
|
67
|
+
rack-test (>= 0.5.6)
|
68
|
+
radius
|
69
|
+
rake
|
70
|
+
rdiscount
|
71
|
+
rdoc
|
72
|
+
shotgun (~> 0.6)
|
73
|
+
sinatra!
|
74
|
+
slim
|
data/README.de.rdoc
CHANGED
@@ -177,7 +177,7 @@ Renderingmethoden rendern jeden String direkt.
|
|
177
177
|
|
178
178
|
Das haml gem wird benötigt, um Haml-Templates rendern zu können:
|
179
179
|
|
180
|
-
|
180
|
+
# haml muss eingebunden werden
|
181
181
|
require 'haml'
|
182
182
|
|
183
183
|
get '/' do
|
@@ -199,7 +199,7 @@ und individuell überschrieben werden.
|
|
199
199
|
|
200
200
|
=== Erb-Templates
|
201
201
|
|
202
|
-
|
202
|
+
# erb muss eingebunden werden
|
203
203
|
require 'erb'
|
204
204
|
|
205
205
|
get '/' do
|
@@ -212,7 +212,7 @@ Dieser Code rendert <tt>./views/index.erb</tt>.
|
|
212
212
|
|
213
213
|
Das erubis gem wird benötigt, um Erubis-Templates rendern zu können:
|
214
214
|
|
215
|
-
|
215
|
+
# erbubis muss eingebunden werden
|
216
216
|
require 'erubis'
|
217
217
|
|
218
218
|
get '/' do
|
@@ -225,7 +225,7 @@ Dieser Code rendert <tt>./views/index.erubis</tt>.
|
|
225
225
|
|
226
226
|
Das buidler gem wird benötigt, um Builder-Templates rendern zu können:
|
227
227
|
|
228
|
-
|
228
|
+
# builder muss eingebunden werden
|
229
229
|
require 'builder'
|
230
230
|
|
231
231
|
get '/' do
|
@@ -238,7 +238,7 @@ Dieser Code rendert <tt>./views/index.builder</tt>.
|
|
238
238
|
|
239
239
|
Das nokogiri gem wird benötigt, um Nokogiri-Templates rendern zu können:
|
240
240
|
|
241
|
-
|
241
|
+
# nokogiri muss eingebunden werden
|
242
242
|
require 'nokogiri'
|
243
243
|
|
244
244
|
get '/' do
|
@@ -251,7 +251,7 @@ Dieser Code rendert <tt>./views/index.nokogiri</tt>.
|
|
251
251
|
|
252
252
|
Das haml gem wird benötigt, um SASS-Templates rendern zu können:
|
253
253
|
|
254
|
-
|
254
|
+
# sass muss eingebunden werden
|
255
255
|
require 'sass'
|
256
256
|
|
257
257
|
get '/stylesheet.css' do
|
@@ -275,7 +275,7 @@ und individuell überschrieben werden.
|
|
275
275
|
|
276
276
|
Das haml gem wird benötigt, um SCSS-Templates rendern zu können:
|
277
277
|
|
278
|
-
|
278
|
+
# sass muss eingebunden werden
|
279
279
|
require 'sass'
|
280
280
|
|
281
281
|
get '/stylesheet.css' do
|
@@ -299,7 +299,7 @@ und individuell überschrieben werden.
|
|
299
299
|
|
300
300
|
Das less gem wird benötigt, um Less-Templates rendern zu können:
|
301
301
|
|
302
|
-
|
302
|
+
# less muss eingebunden werden
|
303
303
|
require 'less'
|
304
304
|
|
305
305
|
get '/stylesheet.css' do
|
@@ -312,7 +312,7 @@ Dieser Code rendert <tt>./views/stylesheet.less</tt>.
|
|
312
312
|
|
313
313
|
Das liquid gem wird benötigt, um Liquid-Templates rendern zu können:
|
314
314
|
|
315
|
-
|
315
|
+
# liquid muss eingebunden werden
|
316
316
|
require 'liquid'
|
317
317
|
|
318
318
|
get '/' do
|
@@ -330,7 +330,7 @@ aufrufen kann, will man nahezu in allen Fällen +locals+ übergeben:
|
|
330
330
|
|
331
331
|
Das rdiscount gem wird benötigt, um Markdown-Templates rendern zu können:
|
332
332
|
|
333
|
-
|
333
|
+
# rdiscount muss eingebunden werden
|
334
334
|
require "rdiscount"
|
335
335
|
|
336
336
|
get '/' do
|
@@ -356,7 +356,7 @@ aufzurufen:
|
|
356
356
|
|
357
357
|
Das RedCloth gem wird benötigt, um Textile-Templates rendern zu können:
|
358
358
|
|
359
|
-
|
359
|
+
# redcloth muss eingebunden werden
|
360
360
|
require "redcloth"
|
361
361
|
|
362
362
|
get '/' do
|
@@ -381,7 +381,7 @@ aufzurufen:
|
|
381
381
|
|
382
382
|
Das rdoc gem wird benötigt, um RDoc-Templates rendern zu können:
|
383
383
|
|
384
|
-
|
384
|
+
# RDoc muss eingebunden werden
|
385
385
|
require "rdoc"
|
386
386
|
|
387
387
|
get '/' do
|
@@ -406,7 +406,7 @@ aufzurufen:
|
|
406
406
|
|
407
407
|
Das radius gem wird benötigt, um Radius-Templates rendern zu können:
|
408
408
|
|
409
|
-
|
409
|
+
# radius muss eingebunden werden
|
410
410
|
require 'radius'
|
411
411
|
|
412
412
|
get '/' do
|
@@ -424,7 +424,7 @@ aufrufen kann, will man nahezu in allen Fällen +locals+ übergeben:
|
|
424
424
|
|
425
425
|
Das markaby gem wird benötigt, um Markaby-Templates rendern zu können:
|
426
426
|
|
427
|
-
|
427
|
+
# markaby muss eingebunden werden
|
428
428
|
require 'markaby'
|
429
429
|
|
430
430
|
get '/' do
|
@@ -437,7 +437,7 @@ Dieser Code rendert <tt>./views/index.mab</tt>.
|
|
437
437
|
|
438
438
|
Das slim gem wird benötigt, um Slim-Templates rendern zu können:
|
439
439
|
|
440
|
-
|
440
|
+
# slim muss eingebunden werden
|
441
441
|
require 'slim'
|
442
442
|
|
443
443
|
get '/' do
|
@@ -450,7 +450,7 @@ Dieser Code rendert <tt>./views/index.slim</tt>.
|
|
450
450
|
|
451
451
|
Das coffee-script gem und das `coffee`-Programm werden benötigt, um CoffeScript-Templates rendern zu können:
|
452
452
|
|
453
|
-
|
453
|
+
# coffee-script muss eingebunden werden
|
454
454
|
require 'coffee-script'
|
455
455
|
|
456
456
|
get '/application.js' do
|
data/README.es.rdoc
CHANGED
@@ -151,7 +151,7 @@ De esa manera podemos, por ejemplo, implementar fácilmente un streaming:
|
|
151
151
|
|
152
152
|
get('/') { Stream.new }
|
153
153
|
|
154
|
-
== Archivos
|
154
|
+
== Archivos Estáticos
|
155
155
|
|
156
156
|
Los archivos estáticos son servidos desde el directorio público
|
157
157
|
<tt>./public</tt>. Podés especificar una ubicación diferente ajustando la
|
@@ -178,9 +178,9 @@ les pase como argumento.
|
|
178
178
|
|
179
179
|
=== Plantillas Haml
|
180
180
|
|
181
|
-
La gem/librería haml es necesaria para para renderizar plantillas HAML:
|
181
|
+
La gem/librería <tt>haml</tt> es necesaria para para renderizar plantillas HAML:
|
182
182
|
|
183
|
-
|
183
|
+
# Vas a necesitar requerir haml en tu app
|
184
184
|
require 'haml'
|
185
185
|
|
186
186
|
get '/' do
|
@@ -202,7 +202,7 @@ y reemplazadas individualmente.
|
|
202
202
|
|
203
203
|
=== Plantillas Erb
|
204
204
|
|
205
|
-
|
205
|
+
# Vas a necesitar requerir erb en tu app
|
206
206
|
require 'erb'
|
207
207
|
|
208
208
|
get '/' do
|
@@ -211,24 +211,36 @@ y reemplazadas individualmente.
|
|
211
211
|
|
212
212
|
Renderiza <tt>./views/index.erb</tt>
|
213
213
|
|
214
|
-
=== Erubis
|
214
|
+
=== Plantillas Erubis
|
215
215
|
|
216
|
-
La gem/librería erubis es necesaria para renderizar plantillas
|
216
|
+
La gem/librería <tt>erubis</tt> es necesaria para renderizar plantillas Erubis:
|
217
217
|
|
218
|
-
|
218
|
+
# Vas a necesitar requerir erubis en tu app
|
219
219
|
require 'erubis'
|
220
220
|
|
221
221
|
get '/' do
|
222
222
|
erubis :index
|
223
223
|
end
|
224
224
|
|
225
|
-
Renderiza <tt>./views/index.erubis</tt
|
225
|
+
Renderiza <tt>./views/index.erubis</tt>.
|
226
|
+
|
227
|
+
También es posible reemplazar Erb con Erubis:
|
228
|
+
|
229
|
+
require 'erubis'
|
230
|
+
Tilt.register :erb, Tilt[:erubis]
|
231
|
+
|
232
|
+
get '/' do
|
233
|
+
erb :index
|
234
|
+
end
|
235
|
+
|
236
|
+
Renderiza <tt>./views/index.erb</tt> con Erubis.
|
226
237
|
|
227
238
|
=== Plantillas Builder
|
228
239
|
|
229
|
-
La gem/librería builder es necesaria para renderizar plantillas
|
240
|
+
La gem/librería <tt>builder</tt> es necesaria para renderizar plantillas
|
241
|
+
builder:
|
230
242
|
|
231
|
-
|
243
|
+
# Vas a necesitar requerir builder en tu app
|
232
244
|
require 'builder'
|
233
245
|
|
234
246
|
get '/' do
|
@@ -239,9 +251,10 @@ Renderiza <tt>./views/index.builder</tt>.
|
|
239
251
|
|
240
252
|
=== Plantillas Nokogiri
|
241
253
|
|
242
|
-
La gem/librería nokogiri es necesaria para renderizar plantillas
|
254
|
+
La gem/librería <tt>nokogiri</tt> es necesaria para renderizar plantillas
|
255
|
+
nokogiri:
|
243
256
|
|
244
|
-
|
257
|
+
# Vas a necesitar requerir nokogiri en tu app
|
245
258
|
require 'nokogiri'
|
246
259
|
|
247
260
|
get '/' do
|
@@ -252,9 +265,10 @@ Renderiza <tt>./views/index.nokogiri</tt>.
|
|
252
265
|
|
253
266
|
=== Plantillas Sass
|
254
267
|
|
255
|
-
La gem/librería haml es necesaria para renderizar
|
268
|
+
La gem/librería <tt>haml</tt> o <tt>sass</tt> es necesaria para renderizar
|
269
|
+
plantillas Sass:
|
256
270
|
|
257
|
-
|
271
|
+
# Vas a necesitar requerir haml o sass en tu app
|
258
272
|
require 'sass'
|
259
273
|
|
260
274
|
get '/stylesheet.css' do
|
@@ -276,9 +290,10 @@ y reemplazadas individualmente.
|
|
276
290
|
|
277
291
|
=== Plantillas Scss
|
278
292
|
|
279
|
-
La gem/librería haml es necesaria para renderizar
|
293
|
+
La gem/librería <tt>haml</tt> o <tt>sass</tt>es necesaria para renderizar
|
294
|
+
plantillas Scss:
|
280
295
|
|
281
|
-
|
296
|
+
# Vas a necesitar requerir haml o sass en tu app
|
282
297
|
require 'sass'
|
283
298
|
|
284
299
|
get '/stylesheet.css' do
|
@@ -300,9 +315,9 @@ y reemplazadas individualmente.
|
|
300
315
|
|
301
316
|
=== Plantillas Less
|
302
317
|
|
303
|
-
La gem/librería less es necesaria para renderizar plantillas Less:
|
318
|
+
La gem/librería <tt>less</tt> es necesaria para renderizar plantillas Less:
|
304
319
|
|
305
|
-
|
320
|
+
# Vas a necesitar requerir less en tu app
|
306
321
|
require 'less'
|
307
322
|
|
308
323
|
get '/stylesheet.css' do
|
@@ -313,9 +328,9 @@ Renderiza <tt>./views/stylesheet.less</tt>.
|
|
313
328
|
|
314
329
|
=== Plantillas Liquid
|
315
330
|
|
316
|
-
La gem/librería liquid es necesaria para renderizar plantillas Liquid:
|
331
|
+
La gem/librería <tt>liquid</tt> es necesaria para renderizar plantillas Liquid:
|
317
332
|
|
318
|
-
|
333
|
+
# Vas a necesitar requerir liquid en tu app
|
319
334
|
require 'liquid'
|
320
335
|
|
321
336
|
get '/' do
|
@@ -331,9 +346,10 @@ plantilla Liquid, casi siempre vas a querer pasarle locales:
|
|
331
346
|
|
332
347
|
=== Plantillas Markdown
|
333
348
|
|
334
|
-
La gem/librería rdiscount es necesaria para renderizar plantillas
|
349
|
+
La gem/librería <tt>rdiscount</tt> es necesaria para renderizar plantillas
|
350
|
+
Markdown:
|
335
351
|
|
336
|
-
|
352
|
+
# Vas a necesitar requerir rdiscount en tu app
|
337
353
|
require "rdiscount"
|
338
354
|
|
339
355
|
get '/' do
|
@@ -348,17 +364,53 @@ generalmente vas a usarlo en combinación con otro motor de renderizado:
|
|
348
364
|
|
349
365
|
erb :resumen, :locals => { :texto => markdown(:introduccion) }
|
350
366
|
|
351
|
-
Tené en cuenta que también podés llamar al método markdown desde otras
|
367
|
+
Tené en cuenta que también podés llamar al método +markdown+ desde otras
|
352
368
|
plantillas:
|
353
369
|
|
354
370
|
%h1 Hola Desde Haml!
|
355
371
|
%p= markdown(:saludos)
|
356
372
|
|
357
|
-
|
373
|
+
Como no podés utilizar Ruby desde Markdown, no podés usar layouts escritos en
|
374
|
+
Markdown. De todos modos, es posible usar un motor de renderizado para el
|
375
|
+
layout distinto al de la plantilla pasando la opción `:layout_engine`:
|
376
|
+
|
377
|
+
get '/' do
|
378
|
+
markdown :index, :layout_engine => :erb
|
379
|
+
end
|
380
|
+
|
381
|
+
Renderiza <tt>./views/index.md</tt> con el layout <tt>./views/layout.erb</tt>.
|
382
|
+
|
383
|
+
Recordá que podés asignar las opciones de renderizado globalmente:
|
384
|
+
|
385
|
+
set :markdown, :layout_engine => :haml, :layout => :post
|
358
386
|
|
359
|
-
|
387
|
+
get '/' do
|
388
|
+
markdown :index
|
389
|
+
end
|
360
390
|
|
361
|
-
|
391
|
+
Renderiza <tt>./views/index.md</tt> (o cualquier otra plantilla Markdown) con
|
392
|
+
el layout <tt>./views/post.haml</tt>.
|
393
|
+
|
394
|
+
También es posible parsear Markdown con BlueCloth en lugar de RDiscount:
|
395
|
+
|
396
|
+
require 'bluecloth'
|
397
|
+
|
398
|
+
Tilt.register 'markdown', BlueClothTemplate
|
399
|
+
Tilt.register 'mkd', BlueClothTemplate
|
400
|
+
Tilt.register 'md', BlueClothTemplate
|
401
|
+
|
402
|
+
get '/' do
|
403
|
+
markdown :index
|
404
|
+
end
|
405
|
+
|
406
|
+
Renderiza <tt>./views/index.md</tt> con BlueCloth.
|
407
|
+
|
408
|
+
=== Plantillas Textile
|
409
|
+
|
410
|
+
La gem/librería <tt>RedCloth</tt> es necesaria para renderizar plantillas
|
411
|
+
Textile:
|
412
|
+
|
413
|
+
# Vas a necesitar requerir redcloth en tu app
|
362
414
|
require "redcloth"
|
363
415
|
|
364
416
|
get '/' do
|
@@ -372,17 +424,39 @@ generalmente vas a usarlo en combinación con otro motor de renderizado:
|
|
372
424
|
|
373
425
|
erb :resumen, :locals => { :texto => textile(:introduccion) }
|
374
426
|
|
375
|
-
Tené en cuenta que también podés llamar al método textile desde otras
|
427
|
+
Tené en cuenta que también podés llamar al método +textile+ desde otras
|
376
428
|
plantillas:
|
377
429
|
|
378
430
|
%h1 Hola Desde Haml!
|
379
431
|
%p= textile(:saludos)
|
380
432
|
|
433
|
+
Como no podés utilizar Ruby desde Textile, no podés usar layouts escritos en
|
434
|
+
Textile. De todos modos, es posible usar un motor de renderizado para el
|
435
|
+
layout distinto al de la plantilla pasando la opción `:layout_engine`:
|
436
|
+
|
437
|
+
get '/' do
|
438
|
+
textile :index, :layout_engine => :erb
|
439
|
+
end
|
440
|
+
|
441
|
+
Renderiza <tt>./views/index.textile</tt> con el layout
|
442
|
+
<tt>./views/layout.erb</tt>.
|
443
|
+
|
444
|
+
Recordá que podés asignar las opciones de renderizado globalmente:
|
445
|
+
|
446
|
+
set :textile, :layout_engine => :haml, :layout => :post
|
447
|
+
|
448
|
+
get '/' do
|
449
|
+
textile :index
|
450
|
+
end
|
451
|
+
|
452
|
+
Renderiza <tt>./views/index.textile</tt> (o cualquier otra plantilla Textile)
|
453
|
+
con el layout <tt>./views/post.haml</tt>.
|
454
|
+
|
381
455
|
=== Plantillas RDoc
|
382
456
|
|
383
|
-
La gem/librería
|
457
|
+
La gem/librería <tt>rdoc</tt> es necesaria para renderizar plantillas RDoc:
|
384
458
|
|
385
|
-
|
459
|
+
# Vas a necesitar requerir rdoc en tu app
|
386
460
|
require "rdoc"
|
387
461
|
|
388
462
|
get '/' do
|
@@ -396,17 +470,38 @@ generalmente vas a usarlo en combinación con otro motor de renderizado:
|
|
396
470
|
|
397
471
|
erb :resumen, :locals => { :texto => rdoc(:introduccion) }
|
398
472
|
|
399
|
-
Tené en cuenta que también podés llamar al método rdoc desde otras
|
473
|
+
Tené en cuenta que también podés llamar al método +rdoc+ desde otras
|
400
474
|
plantillas:
|
401
475
|
|
402
476
|
%h1 Hola Desde Haml!
|
403
477
|
%p= rdoc(:saludos)
|
404
478
|
|
479
|
+
Como no podés utilizar Ruby desde RDoc, no podés usar layouts escritos en RDoc.
|
480
|
+
De todos modos, es posible usar un motor de renderizado para el layout distinto
|
481
|
+
al de la plantilla pasando la opción `:layout_engine`:
|
482
|
+
|
483
|
+
get '/' do
|
484
|
+
rdoc :index, :layout_engine => :erb
|
485
|
+
end
|
486
|
+
|
487
|
+
Renderiza <tt>./views/index.rdoc</tt> con el layout <tt>./views/layout.erb</tt>.
|
488
|
+
|
489
|
+
Recordá que podés asignar las opciones de renderizado globalmente:
|
490
|
+
|
491
|
+
set :rdoc, :layout_engine => :haml, :layout => :post
|
492
|
+
|
493
|
+
get '/' do
|
494
|
+
rdoc :index
|
495
|
+
end
|
496
|
+
|
497
|
+
Renderiza <tt>./views/index.rdoc</tt> (o cualquier otra plantilla RDoc) con el
|
498
|
+
layout <tt>./views/post.haml</tt>.
|
499
|
+
|
405
500
|
=== Plantillas Radius
|
406
501
|
|
407
|
-
La gem/librería radius es necesaria para renderizar plantillas Radius:
|
502
|
+
La gem/librería <tt>radius</tt> es necesaria para renderizar plantillas Radius:
|
408
503
|
|
409
|
-
|
504
|
+
# Vas a necesitar requerir radius en tu app
|
410
505
|
require 'radius'
|
411
506
|
|
412
507
|
get '/' do
|
@@ -422,9 +517,10 @@ plantilla Radius, casi siempre vas a querer pasarle locales:
|
|
422
517
|
|
423
518
|
=== Plantillas Markaby
|
424
519
|
|
425
|
-
La gem/librería markaby es necesaria para renderizar plantillas
|
520
|
+
La gem/librería <tt>markaby</tt> es necesaria para renderizar plantillas
|
521
|
+
Markaby:
|
426
522
|
|
427
|
-
|
523
|
+
# Vas a necesitar requerir markaby en tu app
|
428
524
|
require 'markaby'
|
429
525
|
|
430
526
|
get '/' do
|
@@ -433,7 +529,7 @@ La gem/librería markaby es necesaria para renderizar plantillas Markaby:
|
|
433
529
|
|
434
530
|
Renderiza <tt>./views/index.mab</tt>.
|
435
531
|
|
436
|
-
|
532
|
+
También podés usar Markaby inline:
|
437
533
|
|
438
534
|
get '/' do
|
439
535
|
markaby { h1 "Bienvenido!" }
|
@@ -442,9 +538,9 @@ Si tenés Tilt 1.2 o posterior, podés usar markaby inline:
|
|
442
538
|
|
443
539
|
=== Plantillas Slim
|
444
540
|
|
445
|
-
La gem/librería slim es necesaria para renderizar plantillas Slim:
|
541
|
+
La gem/librería <tt>slim</tt> es necesaria para renderizar plantillas Slim:
|
446
542
|
|
447
|
-
|
543
|
+
# Vas a necesitar requerir slim en tu app
|
448
544
|
require 'slim'
|
449
545
|
|
450
546
|
get '/' do
|
@@ -455,10 +551,16 @@ Renderiza <tt>./views/index.slim</tt>.
|
|
455
551
|
|
456
552
|
=== Plantillas CoffeeScript
|
457
553
|
|
458
|
-
La gem/librería coffee-script y
|
459
|
-
|
554
|
+
La gem/librería <tt>coffee-script</tt> y al menos <b>una</b> de las siguientes
|
555
|
+
opciones para ejecutar JavaScript:
|
556
|
+
|
557
|
+
* +node+ (de Node.js) en tu path
|
558
|
+
* utilizar OSX
|
559
|
+
* la gem/librería +therubyracer+
|
560
|
+
|
561
|
+
son necesarios para renderizar plantillas CoffeeScript:
|
460
562
|
|
461
|
-
|
563
|
+
# Vas a necesitar requerir coffee-script en tu app
|
462
564
|
require 'coffee-script'
|
463
565
|
|
464
566
|
get '/application.js' do
|
@@ -467,13 +569,13 @@ renderizar plantillas CoffeeScript:
|
|
467
569
|
|
468
570
|
Renderiza <tt>./views/application.coffee</tt>.
|
469
571
|
|
470
|
-
=== Plantillas
|
572
|
+
=== Plantillas Embebidas
|
471
573
|
|
472
574
|
get '/' do
|
473
575
|
haml '%div.titulo Hola Mundo'
|
474
576
|
end
|
475
577
|
|
476
|
-
Renderiza el template
|
578
|
+
Renderiza el template embebido en el string.
|
477
579
|
|
478
580
|
=== Accediendo a Variables en Plantillas
|
479
581
|
|
@@ -539,28 +641,39 @@ Las plantillas también pueden ser definidas usando el método top-level
|
|
539
641
|
end
|
540
642
|
|
541
643
|
Si existe una plantilla con el nombre "layout", va a ser usada cada vez que
|
542
|
-
una plantilla es renderizada. Podés desactivar los layouts
|
543
|
-
<tt>:layout => false</tt
|
644
|
+
una plantilla es renderizada. Podés desactivar los layouts individualmente
|
645
|
+
pasando <tt>:layout => false</tt> o globalmente con
|
646
|
+
<tt>set :haml, :layout => false</tt>.
|
544
647
|
|
545
648
|
get '/' do
|
546
649
|
haml :index, :layout => !request.xhr?
|
547
650
|
end
|
548
651
|
|
549
|
-
|
652
|
+
=== Asociando Extensiones de Archivo
|
550
653
|
|
551
|
-
|
552
|
-
|
654
|
+
Para asociar una extensión de archivo con un motor de renderizado, usá
|
655
|
+
<tt>Tilt.register</tt>. Por ejemplo, si querés usar la extensión +tt+ para
|
656
|
+
las plantillas Textile, podés hacer lo siguiente:
|
657
|
+
|
658
|
+
Tilt.register :tt, Tilt[:textile]
|
659
|
+
|
660
|
+
=== Agregando Tu Propio Motor de Renderizado
|
661
|
+
|
662
|
+
Primero, registrá tu motor con Tilt, y después, creá tu método de renderizado:
|
663
|
+
|
664
|
+
Tilt.register :mipg, MiMotorParaPlantillaGenial
|
553
665
|
|
554
666
|
helpers do
|
555
|
-
def
|
556
|
-
"#{nombre}bar"
|
557
|
-
end
|
667
|
+
def mypg(*args) render(:mypg, *args) end
|
558
668
|
end
|
559
669
|
|
560
|
-
get '
|
561
|
-
|
670
|
+
get '/' do
|
671
|
+
mypg :index
|
562
672
|
end
|
563
673
|
|
674
|
+
Renderiza <tt>./views/index.mypg</tt>. Mirá https://github.com/rtomayko/tilt
|
675
|
+
para aprender más de Tilt.
|
676
|
+
|
564
677
|
== Filtros
|
565
678
|
|
566
679
|
Los filtros before son evaluados antes de cada petición dentro del mismo
|
@@ -587,6 +700,10 @@ filtros after:
|
|
587
700
|
puts response.status
|
588
701
|
end
|
589
702
|
|
703
|
+
Nota: A menos que usés el método `body` en lugar de simplemente devolver un
|
704
|
+
string desde una ruta, el cuerpo de la respuesta no va a estar disponible en
|
705
|
+
un filtro after, debido a que todavía no se ha generado.
|
706
|
+
|
590
707
|
Los filtros aceptan un patrón opcional, que cuando está presente causa que los
|
591
708
|
mismos sean evaluados únicamente si el path de la petición coincide con ese
|
592
709
|
patrón:
|
@@ -609,7 +726,22 @@ Al igual que las rutas, los filtros también aceptan condiciones:
|
|
609
726
|
# ...
|
610
727
|
end
|
611
728
|
|
612
|
-
==
|
729
|
+
== Ayudantes
|
730
|
+
|
731
|
+
Usá el método top-level <tt>helpers</tt> para definir métodos ayudantes que
|
732
|
+
pueden ser utilizados dentro de los manejadores de rutas y las plantillas:
|
733
|
+
|
734
|
+
helpers do
|
735
|
+
def bar(nombre)
|
736
|
+
"#{nombre}bar"
|
737
|
+
end
|
738
|
+
end
|
739
|
+
|
740
|
+
get '/:nombre' do
|
741
|
+
bar(params[:nombre])
|
742
|
+
end
|
743
|
+
|
744
|
+
=== Interrupción
|
613
745
|
|
614
746
|
Para detener inmediatamente una petición dentro de un filtro o una ruta usá:
|
615
747
|
|
@@ -631,7 +763,7 @@ Con cabeceras:
|
|
631
763
|
|
632
764
|
halt 402, { 'Content-Type' => 'text/plain' }, 'venganza'
|
633
765
|
|
634
|
-
|
766
|
+
=== Paso
|
635
767
|
|
636
768
|
Una ruta puede pasarle el procesamiento a la siguiente ruta que coincida con
|
637
769
|
la petición usando <tt>pass</tt>:
|
@@ -648,7 +780,66 @@ la petición usando <tt>pass</tt>:
|
|
648
780
|
Se sale inmediatamente del bloque de la ruta y se le pasa el control a la
|
649
781
|
siguiente ruta que coincida. Si no coincide ninguna ruta, se devuelve un 404.
|
650
782
|
|
651
|
-
|
783
|
+
=== Asignando el cuerpo y el código de estado de una respuesta
|
784
|
+
|
785
|
+
Es posible, y se recomienda, asignar el código de estado y el cuerpo de una
|
786
|
+
respuesta con el valor de retorno de una ruta. De cualquier manera, en varios
|
787
|
+
escenarios, puede que sea conveniente asignar el cuerpo en un punto arbitrario
|
788
|
+
del flujo de ejecución con el método `body`. A partir de ahí, podés usar ese
|
789
|
+
mismo método para acceder al cuerpo de la respuesta:
|
790
|
+
|
791
|
+
get '/foo' do
|
792
|
+
body "bar"
|
793
|
+
end
|
794
|
+
|
795
|
+
after do
|
796
|
+
puts body
|
797
|
+
end
|
798
|
+
|
799
|
+
También es posible pasarle un bloque a body, que será ejecutado por el rack
|
800
|
+
handler (podés usar esto para implementar streaming, mirá
|
801
|
+
[Valores de retorno](#Valores%20de%20retorno)).
|
802
|
+
|
803
|
+
De manera similar, también podés asignar el código de estado:
|
804
|
+
|
805
|
+
get '/foo' do
|
806
|
+
status 418
|
807
|
+
halt "I'm a teapot"
|
808
|
+
end
|
809
|
+
|
810
|
+
=== Redirección del Navegador
|
811
|
+
|
812
|
+
Podés redireccionar al navegador con el método `redirect`:
|
813
|
+
|
814
|
+
get '/foo' do
|
815
|
+
redirect '/bar'
|
816
|
+
end
|
817
|
+
|
818
|
+
Cualquier parámetro adicional se utiliza de la misma manera que los argumentos
|
819
|
+
pasados a `halt`:
|
820
|
+
|
821
|
+
redirect '/bar', 303
|
822
|
+
redirect '/bar', 'te confundiste de lugar, compañero'
|
823
|
+
|
824
|
+
Para pasar argumetnos con una redirección, podés agregarlo a la cadena de
|
825
|
+
búsqueda:
|
826
|
+
|
827
|
+
redirect '/bar?suma=42'
|
828
|
+
|
829
|
+
O usar una sesión:
|
830
|
+
|
831
|
+
enable :session
|
832
|
+
|
833
|
+
get '/foo' do
|
834
|
+
session[:secreto] = 'foo'
|
835
|
+
redirect '/bar'
|
836
|
+
end
|
837
|
+
|
838
|
+
get '/bar' do
|
839
|
+
session[:secreto]
|
840
|
+
end
|
841
|
+
|
842
|
+
=== Accediendo al objeto de la petición
|
652
843
|
|
653
844
|
El objeto de la petición entrante puede ser accedido desde el nivel de la
|
654
845
|
petición (filtros, rutas y manejadores de errores) a través del método
|
@@ -718,7 +909,7 @@ Ejecutar cuando el entorno es <tt>:production</tt> o <tt>:test</tt>:
|
|
718
909
|
...
|
719
910
|
end
|
720
911
|
|
721
|
-
== Manejo de
|
912
|
+
== Manejo de Errores
|
722
913
|
|
723
914
|
Los manejadores de errores se ejecutan dentro del mismo contexto que las rutas
|
724
915
|
y los filtros before, lo que significa que podés usar, por ejemplo,
|
@@ -884,13 +1075,6 @@ etc.). Ahí es donde Sinatra::Base entra en el juego:
|
|
884
1075
|
end
|
885
1076
|
end
|
886
1077
|
|
887
|
-
La clase MiApp es un componente Rack independiente que puede actuar como Rack
|
888
|
-
middleware, una aplicación Rack, o Rails metal. Podés usar (con +use+) o
|
889
|
-
ejecutar (con +run+) esta clase desde un archivo rackup +config.ru+; o,
|
890
|
-
controlar un componente de servidor provisto como una librería:
|
891
|
-
|
892
|
-
MiApp.run! :host => 'localhost', :port => 9090
|
893
|
-
|
894
1078
|
Las subclases de Sinatra::Base tienen disponibles exactamente los mismos
|
895
1079
|
métodos que los provistos por el DSL de top-level. La mayoría de las
|
896
1080
|
aplicaciones top-level se pueden convertir en componentes Sinatra::Base con
|
@@ -907,6 +1091,64 @@ desactivadas por defecto, incluyendo el servidor incorporado. Mirá
|
|
907
1091
|
{Opciones y Configuraciones}[http://sinatra.github.com/configuration.html]
|
908
1092
|
para detalles sobre las opciones disponibles y su comportamiento.
|
909
1093
|
|
1094
|
+
=== Sirviendo una Aplicación Modular
|
1095
|
+
|
1096
|
+
Las dos opciones más comunes para iniciar una aplicación modular son, iniciarla
|
1097
|
+
activamente con <tt>run!</tt>:
|
1098
|
+
|
1099
|
+
# mi_app.rb
|
1100
|
+
require 'sinatra/base'
|
1101
|
+
|
1102
|
+
class MiApp < Sinatra::Base
|
1103
|
+
# ... código de la app ...
|
1104
|
+
|
1105
|
+
# iniciar el servidor si el archivo fue ejecutado directamente
|
1106
|
+
run! if app_file == $0
|
1107
|
+
end
|
1108
|
+
|
1109
|
+
Iniciar con:
|
1110
|
+
|
1111
|
+
ruby mi_app.rb
|
1112
|
+
|
1113
|
+
O, con un archivo <tt>config.ru</tt>, que permite usar cualquier handler Rack:
|
1114
|
+
|
1115
|
+
# config.ru
|
1116
|
+
require 'mi_app'
|
1117
|
+
run MiApp
|
1118
|
+
|
1119
|
+
Después ejecutar:
|
1120
|
+
|
1121
|
+
rackup -p 4567
|
1122
|
+
|
1123
|
+
=== Usando una Aplicación Clásica con un Archivo config.ru
|
1124
|
+
|
1125
|
+
Escribí el archivo de tu aplicación:
|
1126
|
+
|
1127
|
+
# app.rb
|
1128
|
+
require 'sinatra'
|
1129
|
+
|
1130
|
+
get '/' do
|
1131
|
+
'Hola mundo!'
|
1132
|
+
end
|
1133
|
+
|
1134
|
+
Y el <tt>config.ru</tt> correspondiente:
|
1135
|
+
|
1136
|
+
require 'app'
|
1137
|
+
run Sinatra::Application
|
1138
|
+
|
1139
|
+
=== ¿Cuándo Usar config.ru?
|
1140
|
+
|
1141
|
+
Indicadores de que probablemente querés usar <tt>config.ru</tt>:
|
1142
|
+
|
1143
|
+
* Querés realizar el deploy con un hanlder Rack distinto (Passenger, Unicorn,
|
1144
|
+
Heroku, ...).
|
1145
|
+
* Querés usar más de una subclase de <tt>Sinatra::Base</tt>.
|
1146
|
+
* Querés usar Sinatra únicamente para middleware, pero no como un endpoint.
|
1147
|
+
|
1148
|
+
<b>No hay necesidad de utilizar un archivo <tt>config.ru</tt> exclusivamente
|
1149
|
+
porque tenés una aplicación modular, y no necesitás una aplicación modular para
|
1150
|
+
iniciarla con <tt>config.ru</tt>.</b>
|
1151
|
+
|
910
1152
|
=== Utilizando Sinatra como Middleware
|
911
1153
|
|
912
1154
|
Sinatra no solo es capaz de usar otro Rack middleware, sino que a su vez,
|
@@ -1029,7 +1271,7 @@ Pegale una mirada al código: acá está el
|
|
1029
1271
|
{Sinatra::Delegator mixin}[http://github.com/sinatra/sinatra/blob/ceac46f0bc129a6e994a06100aa854f606fe5992/lib/sinatra/base.rb#L1128]
|
1030
1272
|
que es {incluido en el espacio de nombres principal}[http://github.com/sinatra/sinatra/blob/ceac46f0bc129a6e994a06100aa854f606fe5992/lib/sinatra/main.rb#L28].
|
1031
1273
|
|
1032
|
-
== Línea de
|
1274
|
+
== Línea de Comandos
|
1033
1275
|
|
1034
1276
|
Las aplicaciones Sinatra pueden ser ejecutadas directamente:
|
1035
1277
|
|
@@ -1044,33 +1286,71 @@ Las opciones son:
|
|
1044
1286
|
-s # especifica el servidor/manejador rack (thin es usado por defecto)
|
1045
1287
|
-x # activa el mutex lock (está desactivado por defecto)
|
1046
1288
|
|
1047
|
-
== A la
|
1289
|
+
== A la Vanguardia
|
1290
|
+
|
1291
|
+
Si querés usar el código de Sinatra más reciente, sentite libre de ejecutar
|
1292
|
+
tu aplicación sobre la rama master, en general es bastante estable.
|
1293
|
+
|
1294
|
+
También liberamos prereleases de vez en cuando, así, podés hacer
|
1295
|
+
|
1296
|
+
gem install sinatra --pre
|
1297
|
+
|
1298
|
+
Para obtener algunas de las últimas características.
|
1048
1299
|
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1300
|
+
=== Con Bundler
|
1301
|
+
|
1302
|
+
Esta es la manera recomendada para ejecutar tu aplicación sobre la última
|
1303
|
+
versión de Sinatra usando {Bundler}[http://gembundler.com/].
|
1304
|
+
|
1305
|
+
Primero, instalá bundler si no lo hiciste todavía:
|
1306
|
+
|
1307
|
+
gem install bundler
|
1308
|
+
|
1309
|
+
Después, en el directorio de tu proyecto, creá un archivo +Gemfile+:
|
1310
|
+
|
1311
|
+
source :rubygems
|
1312
|
+
gem 'sinatra', :git => "git://github.com/sinatra/sinatra.git"
|
1313
|
+
|
1314
|
+
# otras dependencias
|
1315
|
+
gem 'haml' # por ejemplo, si usás haml
|
1316
|
+
gem 'activerecord', '~> 3.0' # quizás también necesités ActiveRecord 3.x
|
1317
|
+
|
1318
|
+
Tené en cuenta que tenés que listar todas las dependencias directas de tu
|
1319
|
+
aplicación. No es necesario listar las dependencias de Sinatra (Rack y Tilt)
|
1320
|
+
porque Bundler las agrega directamente.
|
1321
|
+
|
1322
|
+
Ahora podés arrancar tu aplicación así:
|
1323
|
+
|
1324
|
+
bundle exec ruby miapp.rb
|
1325
|
+
|
1326
|
+
=== Con Git
|
1327
|
+
|
1328
|
+
Cloná el repositorio localmente y ejecutá tu aplicación, asegurándote que el
|
1329
|
+
directorio <tt>sinatra/lib</tt> esté en el <tt>LOAD_PATH</tt>:
|
1052
1330
|
|
1053
1331
|
cd miapp
|
1054
1332
|
git clone git://github.com/sinatra/sinatra.git
|
1055
1333
|
ruby -Isinatra/lib miapp.rb
|
1056
1334
|
|
1057
|
-
|
1058
|
-
<tt>LOAD_PATH</tt> dentro de tu aplicación:
|
1335
|
+
Para actualizar el código fuente de Sinatra en el futuro:
|
1059
1336
|
|
1060
|
-
|
1061
|
-
|
1062
|
-
require 'sinatra'
|
1337
|
+
cd miapp/sinatra
|
1338
|
+
git pull
|
1063
1339
|
|
1064
|
-
|
1065
|
-
"Estoy usando la versión " + Sinatra::VERSION
|
1066
|
-
end
|
1340
|
+
=== Instalación Global
|
1067
1341
|
|
1068
|
-
|
1342
|
+
Podés construir la gem vos mismo:
|
1069
1343
|
|
1070
|
-
|
1071
|
-
|
1344
|
+
git clone git://github.com/sinatra/sinatra.git
|
1345
|
+
cd sinatra
|
1346
|
+
rake sinatra.gemspec
|
1347
|
+
rake install
|
1348
|
+
|
1349
|
+
Si instalás tus gems como root, el último paso debería ser
|
1350
|
+
|
1351
|
+
sudo rake install
|
1072
1352
|
|
1073
|
-
==
|
1353
|
+
== Lecturas Recomendadas
|
1074
1354
|
|
1075
1355
|
* {Sito web del proyecto}[http://www.sinatrarb.com/] - Documentación
|
1076
1356
|
adicional, noticias, y enlaces a otros recursos.
|