sinatra 1.4.0.a → 1.4.0.b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -126,6 +126,21 @@ task :authors, [:commit_range, :format, :sep] do |t, a|
126
126
  puts authors.sort_by { |n,c| -c }.map { |e| a.format % e }.join(a.sep)
127
127
  end
128
128
 
129
+ desc "generates TOC"
130
+ task :toc, [:readme] do |t, a|
131
+ a.with_defaults :readme => 'README.md'
132
+
133
+ def self.link(title)
134
+ title.downcase.gsub(/(?!-)\W /, '-').gsub(' ', '-').gsub(/(?!-)\W/, '')
135
+ end
136
+
137
+ puts "* [Sinatra](#sinatra)"
138
+ title = Regexp.new('(?<=\* )(.*)') # so Ruby 1.8 doesn't complain
139
+ File.binread(a.readme).scan(/^##.*/) do |line|
140
+ puts line.gsub(/#(?=#)/, ' ').gsub('#', '*').gsub(title) { "[#{$1}](##{link($1)})" }
141
+ end
142
+ end
143
+
129
144
  # PACKAGING ============================================================
130
145
 
131
146
  if defined?(Gem)
@@ -660,6 +660,11 @@ module Sinatra
660
660
  render :less, template, options, locals
661
661
  end
662
662
 
663
+ def stylus(template, options={}, locals={})
664
+ options.merge! :layout => false, :default_content_type => :css
665
+ render :styl, template, options, locals
666
+ end
667
+
663
668
  def builder(template = nil, options = {}, locals = {}, &block)
664
669
  options[:default_content_type] = :xml
665
670
  render_ruby(:builder, template, options, locals, &block)
@@ -1,3 +1,3 @@
1
1
  module Sinatra
2
- VERSION = '1.4.0.a'
2
+ VERSION = '1.4.0.b'
3
3
  end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ begin
4
+ require 'stylus'
5
+ require 'stylus/tilt'
6
+
7
+ begin
8
+ Stylus.compile '1'
9
+ rescue RuntimeError
10
+ raise LoadError, 'unable to find Stylus compiler'
11
+ end
12
+
13
+ class StylusTest < Test::Unit::TestCase
14
+ def stylus_app(options = {}, &block)
15
+ mock_app do
16
+ set :views, File.dirname(__FILE__) + '/views'
17
+ set(options)
18
+ get('/', &block)
19
+ end
20
+ get '/'
21
+ end
22
+
23
+ it 'renders inline Stylus strings' do
24
+ stylus_app { stylus "a\n margin auto\n" }
25
+ assert ok?
26
+ assert body.include?("a {\n margin: auto;\n}\n")
27
+ end
28
+
29
+ it 'defaults content type to css' do
30
+ stylus_app { stylus :hello }
31
+ assert ok?
32
+ assert_equal "text/css;charset=utf-8", response['Content-Type']
33
+ end
34
+
35
+ it 'defaults allows setting content type per route' do
36
+ stylus_app do
37
+ content_type :html
38
+ stylus :hello
39
+ end
40
+ assert ok?
41
+ assert_equal "text/html;charset=utf-8", response['Content-Type']
42
+ end
43
+
44
+ it 'defaults allows setting content type globally' do
45
+ stylus_app(:styl => { :content_type => 'html' }) do
46
+ stylus :hello
47
+ end
48
+ assert ok?
49
+ assert_equal "text/html;charset=utf-8", response['Content-Type']
50
+ end
51
+
52
+ it 'renders .styl files in views path' do
53
+ stylus_app { stylus :hello }
54
+ assert ok?
55
+ assert_include body, "a {\n margin: auto;\n}\n"
56
+ end
57
+
58
+ it 'ignores the layout option' do
59
+ stylus_app { stylus :hello, :layout => :layout2 }
60
+ assert ok?
61
+ assert_include body, "a {\n margin: auto;\n}\n"
62
+ end
63
+
64
+ it "raises error if template not found" do
65
+ mock_app {
66
+ get('/') { stylus :no_such_template }
67
+ }
68
+ assert_raise(Errno::ENOENT) { get('/') }
69
+ end
70
+
71
+ it "passes stylus options to the stylus engine" do
72
+ stylus_app { stylus :hello, :no_wrap => true }
73
+ assert ok?
74
+ assert_body "a {\n margin: auto;\n}\n"
75
+ end
76
+
77
+ it "passes default stylus options to the stylus engine" do
78
+ mock_app do
79
+ set :stylus, :no_wrap => true # default stylus style is :nested
80
+ get('/') { stylus :hello }
81
+ end
82
+ get '/'
83
+ assert ok?
84
+ assert_body "a {\n margin: auto;\n}\n"
85
+ end
86
+ end
87
+
88
+ rescue LoadError
89
+ warn "#{$!.to_s}: skipping stylus tests"
90
+ end
@@ -0,0 +1,2 @@
1
+ a
2
+ margin auto
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.a
4
+ version: 1.4.0.b
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -158,6 +158,7 @@ files:
158
158
  - test/slim_test.rb
159
159
  - test/static_test.rb
160
160
  - test/streaming_test.rb
161
+ - test/stylus_test.rb
161
162
  - test/templates_test.rb
162
163
  - test/textile_test.rb
163
164
  - test/views/a/in_a.str
@@ -187,6 +188,7 @@ files:
187
188
  - test/views/hello.scss
188
189
  - test/views/hello.slim
189
190
  - test/views/hello.str
191
+ - test/views/hello.styl
190
192
  - test/views/hello.test
191
193
  - test/views/hello.textile
192
194
  - test/views/hello.wlang
@@ -228,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
230
  version: '0'
229
231
  segments:
230
232
  - 0
231
- hash: 610663960316584040
233
+ hash: -3758604451509005806
232
234
  required_rubygems_version: !ruby/object:Gem::Requirement
233
235
  none: false
234
236
  requirements:
@@ -280,6 +282,7 @@ test_files:
280
282
  - test/slim_test.rb
281
283
  - test/static_test.rb
282
284
  - test/streaming_test.rb
285
+ - test/stylus_test.rb
283
286
  - test/templates_test.rb
284
287
  - test/textile_test.rb
285
288
  - test/wlang_test.rb