sinatra 1.2.0.c → 1.2.0.d
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/AUTHORS +10 -1
- data/Gemfile +24 -6
- data/README.de.rdoc +696 -72
- data/README.es.rdoc +545 -61
- data/README.fr.rdoc +2 -2
- data/README.jp.rdoc +2 -2
- data/README.rdoc +281 -74
- data/README.ru.rdoc +2 -2
- data/README.zh.rdoc +2 -2
- data/Rakefile +10 -7
- data/lib/sinatra/base.rb +48 -20
- data/sinatra.gemspec +4 -5
- data/test/encoding_test.rb +4 -3
- data/test/helper.rb +2 -0
- data/test/helpers_test.rb +48 -13
- data/test/rdoc_test.rb +1 -1
- data/test/routing_test.rb +5 -0
- data/test/views/{ascii.haml → ascii.erb} +1 -1
- data/test/views/{utf8.haml → utf8.erb} +1 -1
- metadata +6 -7
- data/Gemfile.lock +0 -74
data/README.ru.rdoc
CHANGED
@@ -445,8 +445,8 @@ Sinatra — это предметно-ориентированный язык (D
|
|
445
445
|
|
446
446
|
<tt>rdoc</tt> gem/библиотека необходима для рендеринга RDoc шаблонов:
|
447
447
|
|
448
|
-
# Вам нужно будет подключить rdoc в приложении
|
449
|
-
require "rdoc"
|
448
|
+
# Вам нужно будет подключить rdoc/markup/to_html в приложении
|
449
|
+
require "rdoc/markup/to_html"
|
450
450
|
|
451
451
|
get '/' do
|
452
452
|
rdoc :index
|
data/README.zh.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -9,11 +9,14 @@ task :spec => :test
|
|
9
9
|
CLEAN.include "**/*.rbc"
|
10
10
|
|
11
11
|
def source_version
|
12
|
-
|
13
|
-
|
12
|
+
@source_version ||= begin
|
13
|
+
line = File.read('lib/sinatra/base.rb')[/^\s*VERSION = .*/]
|
14
|
+
line.match(/.*VERSION = '(.*)'/)[1]
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
# SPECS ===============================================================
|
19
|
+
|
17
20
|
task :test do
|
18
21
|
ENV['LANG'] = 'C'
|
19
22
|
ENV.delete 'LC_CTYPE'
|
@@ -24,19 +27,18 @@ Rake::TestTask.new(:test) do |t|
|
|
24
27
|
t.ruby_opts = ['-rubygems'] if defined? Gem
|
25
28
|
t.ruby_opts << '-I.'
|
26
29
|
end
|
30
|
+
|
27
31
|
# Rcov ================================================================
|
32
|
+
|
28
33
|
namespace :test do
|
29
34
|
desc 'Mesures test coverage'
|
30
35
|
task :coverage do
|
31
36
|
rm_f "coverage"
|
32
|
-
|
33
|
-
system("#{rcov} --no-html --no-color test/*_test.rb")
|
37
|
+
sh "rcov -Ilib test/*_test.rb"
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
41
|
# Website =============================================================
|
38
|
-
# Building docs requires HAML and the hanna gem:
|
39
|
-
# gem install mislav-hanna --source=http://gems.github.com
|
40
42
|
|
41
43
|
desc 'Generate RDoc under doc/api'
|
42
44
|
task 'doc' => ['doc:api']
|
@@ -44,6 +46,7 @@ task('doc:api') { sh "yardoc -o doc/api" }
|
|
44
46
|
CLEAN.include 'doc/api'
|
45
47
|
|
46
48
|
# README ===============================================================
|
49
|
+
|
47
50
|
task :add_template, [:name] do |t, args|
|
48
51
|
Dir.glob('README.*') do |file|
|
49
52
|
code = File.read(file)
|
@@ -123,7 +126,7 @@ if defined?(Gem)
|
|
123
126
|
puts "updated #{f.name}"
|
124
127
|
end
|
125
128
|
|
126
|
-
task 'release' => package('.gem') do
|
129
|
+
task 'release' => ['test', package('.gem')] do
|
127
130
|
sh <<-SH
|
128
131
|
gem install #{package('.gem')} --local &&
|
129
132
|
gem push #{package('.gem')} &&
|
data/lib/sinatra/base.rb
CHANGED
@@ -7,7 +7,7 @@ require 'sinatra/showexceptions'
|
|
7
7
|
require 'tilt'
|
8
8
|
|
9
9
|
module Sinatra
|
10
|
-
VERSION = '1.2.0.
|
10
|
+
VERSION = '1.2.0.d'
|
11
11
|
|
12
12
|
# The request object. See Rack::Request for more info:
|
13
13
|
# http://rack.rubyforge.org/doc/classes/Rack/Request.html
|
@@ -318,12 +318,12 @@ module Sinatra
|
|
318
318
|
def expires(amount, *values)
|
319
319
|
values << {} unless values.last.kind_of?(Hash)
|
320
320
|
|
321
|
-
if amount
|
322
|
-
|
323
|
-
time = amount.to_time
|
324
|
-
else
|
321
|
+
if Integer === amount
|
322
|
+
time = Time.now + amount
|
325
323
|
max_age = amount
|
326
|
-
|
324
|
+
else
|
325
|
+
time = time_for amount
|
326
|
+
max_age = time - Time.now
|
327
327
|
end
|
328
328
|
|
329
329
|
values.last.merge!(:max_age => max_age)
|
@@ -341,14 +341,7 @@ module Sinatra
|
|
341
341
|
# with a '304 Not Modified' response.
|
342
342
|
def last_modified(time)
|
343
343
|
return unless time
|
344
|
-
|
345
|
-
time = time.to_time
|
346
|
-
else
|
347
|
-
## make a best effort to convert something else to a time object
|
348
|
-
## if this fails, this should throw an ArgumentError, then the
|
349
|
-
# rescue will result in an http 200, which should be safe
|
350
|
-
time = Time.parse(time.to_s)
|
351
|
-
end
|
344
|
+
time = time_for time
|
352
345
|
response['Last-Modified'] = time.httpdate
|
353
346
|
# compare based on seconds since epoch
|
354
347
|
halt 304 if Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
|
@@ -377,9 +370,39 @@ module Sinatra
|
|
377
370
|
end
|
378
371
|
end
|
379
372
|
|
380
|
-
|
381
|
-
def back
|
373
|
+
# Sugar for redirect (example: redirect back)
|
374
|
+
def back
|
375
|
+
request.referer
|
376
|
+
end
|
377
|
+
|
378
|
+
private
|
382
379
|
|
380
|
+
# Ruby 1.8 has no #to_time method.
|
381
|
+
# This can be removed and calls to it replaced with to_time,
|
382
|
+
# if 1.8 support is dropped.
|
383
|
+
def time_for(value)
|
384
|
+
if value.respond_to? :to_time
|
385
|
+
value.to_time
|
386
|
+
elsif Time === value
|
387
|
+
value
|
388
|
+
elsif value.respond_to? :new_offset
|
389
|
+
# DateTime#to_time does the same on 1.9
|
390
|
+
d = value.new_offset 0
|
391
|
+
t = Time.utc d.year, d.mon, d.mday, d.hour, d.min, d.sec + d.sec_fraction
|
392
|
+
t.getlocal
|
393
|
+
elsif value.respond_to? :mday
|
394
|
+
# Date#to_time does the same on 1.9
|
395
|
+
Time.local(value.year, value.mon, value.mday)
|
396
|
+
elsif Numeric === value
|
397
|
+
Time.at value
|
398
|
+
else
|
399
|
+
Time.parse value.to_s
|
400
|
+
end
|
401
|
+
rescue ArgumentError => boom
|
402
|
+
raise boom.to_s
|
403
|
+
rescue Exception
|
404
|
+
raise ArgumentError, "unable to convert #{value.inspect} to a Time object"
|
405
|
+
end
|
383
406
|
end
|
384
407
|
|
385
408
|
# Template rendering methods. Each method takes the name of a template
|
@@ -391,10 +414,15 @@ module Sinatra
|
|
391
414
|
# that will be rendered.
|
392
415
|
#
|
393
416
|
# Possible options are:
|
394
|
-
# :
|
395
|
-
#
|
396
|
-
#
|
397
|
-
#
|
417
|
+
# :content_type The content type to use, same arguments as content_type.
|
418
|
+
# :layout If set to false, no layout is rendered, otherwise
|
419
|
+
# the specified layout is used (Ignored for `sass` and `less`)
|
420
|
+
# :layout_engine Engine to use for rendering the layout.
|
421
|
+
# :locals A hash with local variables that should be available
|
422
|
+
# in the template
|
423
|
+
# :scope If set, template is evaluate with the binding of the given
|
424
|
+
# object rather than the application instance.
|
425
|
+
# :views Views directory to use.
|
398
426
|
module Templates
|
399
427
|
module ContentTyped
|
400
428
|
attr_accessor :content_type
|
data/sinatra.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'sinatra'
|
6
|
-
s.version = '1.2.0.
|
7
|
-
s.date = '2011-02-
|
6
|
+
s.version = '1.2.0.d'
|
7
|
+
s.date = '2011-02-26'
|
8
8
|
|
9
9
|
s.description = "Classy web-development dressed in a DSL"
|
10
10
|
s.summary = "Classy web-development dressed in a DSL"
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
AUTHORS
|
18
18
|
CHANGES
|
19
19
|
Gemfile
|
20
|
-
Gemfile.lock
|
21
20
|
LICENSE
|
22
21
|
README.de.rdoc
|
23
22
|
README.es.rdoc
|
@@ -74,7 +73,7 @@ Gem::Specification.new do |s|
|
|
74
73
|
test/templates_test.rb
|
75
74
|
test/textile_test.rb
|
76
75
|
test/views/a/in_a.str
|
77
|
-
test/views/ascii.
|
76
|
+
test/views/ascii.erb
|
78
77
|
test/views/b/in_b.str
|
79
78
|
test/views/calc.html.erb
|
80
79
|
test/views/error.builder
|
@@ -114,7 +113,7 @@ Gem::Specification.new do |s|
|
|
114
113
|
test/views/layout2.str
|
115
114
|
test/views/layout2.test
|
116
115
|
test/views/nested.str
|
117
|
-
test/views/utf8.
|
116
|
+
test/views/utf8.erb
|
118
117
|
]
|
119
118
|
# = MANIFEST =
|
120
119
|
|
data/test/encoding_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require File.dirname(__FILE__) + '/helper'
|
3
|
+
require 'erb'
|
3
4
|
|
4
5
|
class BaseTest < Test::Unit::TestCase
|
5
6
|
setup do
|
@@ -9,11 +10,11 @@ class BaseTest < Test::Unit::TestCase
|
|
9
10
|
|
10
11
|
it 'allows unicode strings in ascii templates per default (1.9)' do
|
11
12
|
next unless defined? Encoding
|
12
|
-
@base.new.
|
13
|
+
@base.new.erb(File.read(@base.views + "/ascii.erb").encode("ASCII"), {}, :value => "åkej")
|
13
14
|
end
|
14
15
|
|
15
16
|
it 'allows ascii strings in unicode templates per default (1.9)' do
|
16
17
|
next unless defined? Encoding
|
17
|
-
@base.new.
|
18
|
+
@base.new.erb(:utf8, {}, :value => "Some Lyrics".encode("ASCII"))
|
18
19
|
end
|
19
|
-
end
|
20
|
+
end
|
data/test/helper.rb
CHANGED
data/test/helpers_test.rb
CHANGED
@@ -460,6 +460,12 @@ class HelpersTest < Test::Unit::TestCase
|
|
460
460
|
assert_equal 'attachment; filename="file.txt"', response['Content-Disposition']
|
461
461
|
end
|
462
462
|
|
463
|
+
it "sets the Content-Disposition header when :disposition set to 'inline'" do
|
464
|
+
send_file_app :disposition => 'inline'
|
465
|
+
get '/file.txt'
|
466
|
+
assert_equal 'inline', response['Content-Disposition']
|
467
|
+
end
|
468
|
+
|
463
469
|
it "sets the Content-Disposition header when :filename provided" do
|
464
470
|
send_file_app :filename => 'foo.txt'
|
465
471
|
get '/file.txt'
|
@@ -501,39 +507,67 @@ class HelpersTest < Test::Unit::TestCase
|
|
501
507
|
|
502
508
|
describe 'cache_control' do
|
503
509
|
setup do
|
504
|
-
mock_app
|
505
|
-
get '/' do
|
510
|
+
mock_app do
|
511
|
+
get '/foo' do
|
506
512
|
cache_control :public, :no_cache, :max_age => 60.0
|
507
513
|
'Hello World'
|
508
514
|
end
|
509
|
-
|
515
|
+
|
516
|
+
get '/bar' do
|
517
|
+
cache_control :public, :no_cache
|
518
|
+
'Hello World'
|
519
|
+
end
|
520
|
+
end
|
510
521
|
end
|
511
522
|
|
512
523
|
it 'sets the Cache-Control header' do
|
513
|
-
get '/'
|
524
|
+
get '/foo'
|
514
525
|
assert_equal ['public', 'no-cache', 'max-age=60'], response['Cache-Control'].split(', ')
|
515
526
|
end
|
527
|
+
|
528
|
+
it 'last argument does not have to be a hash' do
|
529
|
+
get '/bar'
|
530
|
+
assert_equal ['public', 'no-cache'], response['Cache-Control'].split(', ')
|
531
|
+
end
|
516
532
|
end
|
517
533
|
|
518
534
|
describe 'expires' do
|
519
535
|
setup do
|
520
|
-
mock_app
|
521
|
-
get '/' do
|
536
|
+
mock_app do
|
537
|
+
get '/foo' do
|
522
538
|
expires 60, :public, :no_cache
|
523
539
|
'Hello World'
|
524
540
|
end
|
525
|
-
|
541
|
+
|
542
|
+
get '/bar' do
|
543
|
+
expires Time.now
|
544
|
+
end
|
545
|
+
|
546
|
+
get '/baz' do
|
547
|
+
expires Time.at(0)
|
548
|
+
end
|
549
|
+
end
|
526
550
|
end
|
527
551
|
|
528
552
|
it 'sets the Cache-Control header' do
|
529
|
-
get '/'
|
553
|
+
get '/foo'
|
530
554
|
assert_equal ['public', 'no-cache', 'max-age=60'], response['Cache-Control'].split(', ')
|
531
555
|
end
|
532
556
|
|
533
557
|
it 'sets the Expires header' do
|
534
|
-
get '/'
|
558
|
+
get '/foo'
|
559
|
+
assert_not_nil response['Expires']
|
560
|
+
end
|
561
|
+
|
562
|
+
it 'allows passing time objects' do
|
563
|
+
get '/bar'
|
535
564
|
assert_not_nil response['Expires']
|
536
565
|
end
|
566
|
+
|
567
|
+
it 'allows passing time objects' do
|
568
|
+
get '/baz'
|
569
|
+
assert_equal 'Thu, 01 Jan 1970 00:00:00 GMT', response['Expires']
|
570
|
+
end
|
537
571
|
end
|
538
572
|
|
539
573
|
describe 'last_modified' do
|
@@ -546,17 +580,18 @@ class HelpersTest < Test::Unit::TestCase
|
|
546
580
|
assert ! response['Last-Modified']
|
547
581
|
end
|
548
582
|
|
549
|
-
[Time, DateTime
|
550
|
-
|
583
|
+
[Time.now, DateTime.now, Date.today, Time.now.to_i,
|
584
|
+
Struct.new(:to_time).new(Time.now) ].each do |last_modified_time|
|
585
|
+
describe "with #{last_modified_time.class.name}" do
|
551
586
|
setup do
|
552
|
-
last_modified_time = klass.now
|
553
587
|
mock_app do
|
554
588
|
get '/' do
|
555
589
|
last_modified last_modified_time
|
556
590
|
'Boo!'
|
557
591
|
end
|
558
592
|
end
|
559
|
-
|
593
|
+
wrapper = Object.new.extend Sinatra::Helpers
|
594
|
+
@last_modified_time = wrapper.send :time_for, last_modified_time
|
560
595
|
end
|
561
596
|
|
562
597
|
# fixes strange missing test error when running complete test suite.
|
data/test/rdoc_test.rb
CHANGED
data/test/routing_test.rb
CHANGED
@@ -778,6 +778,11 @@ class RoutingTest < Test::Unit::TestCase
|
|
778
778
|
end
|
779
779
|
|
780
780
|
it 'raises an ArgumentError with block arity > 1 and too many values' do
|
781
|
+
if RUBY_ENGINE == "rbx"
|
782
|
+
$stderr.puts "\npending test: #{__method__}, #{__FILE__}:#{__LINE__} "
|
783
|
+
next
|
784
|
+
end
|
785
|
+
|
781
786
|
mock_app {
|
782
787
|
get '/:foo/:bar/:baz' do |foo, bar|
|
783
788
|
'quux'
|
@@ -1,2 +1,2 @@
|
|
1
1
|
This file has no unicode in it!
|
2
|
-
|
2
|
+
<%= value %>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
<h1><%= value %></h1>
|
2
2
|
Ingen vill veta var du köpt din tröja.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.2.0.
|
10
|
+
- d
|
11
|
+
version: 1.2.0.d
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Blake Mizerany
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2011-02-
|
22
|
+
date: 2011-02-26 00:00:00 +01:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
@@ -94,7 +94,6 @@ files:
|
|
94
94
|
- AUTHORS
|
95
95
|
- CHANGES
|
96
96
|
- Gemfile
|
97
|
-
- Gemfile.lock
|
98
97
|
- LICENSE
|
99
98
|
- README.de.rdoc
|
100
99
|
- README.es.rdoc
|
@@ -151,7 +150,7 @@ files:
|
|
151
150
|
- test/templates_test.rb
|
152
151
|
- test/textile_test.rb
|
153
152
|
- test/views/a/in_a.str
|
154
|
-
- test/views/ascii.
|
153
|
+
- test/views/ascii.erb
|
155
154
|
- test/views/b/in_b.str
|
156
155
|
- test/views/calc.html.erb
|
157
156
|
- test/views/error.builder
|
@@ -191,7 +190,7 @@ files:
|
|
191
190
|
- test/views/layout2.str
|
192
191
|
- test/views/layout2.test
|
193
192
|
- test/views/nested.str
|
194
|
-
- test/views/utf8.
|
193
|
+
- test/views/utf8.erb
|
195
194
|
has_rdoc: true
|
196
195
|
homepage: http://sinatra.rubyforge.org
|
197
196
|
licenses: []
|
data/Gemfile.lock
DELETED
@@ -1,74 +0,0 @@
|
|
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
|