sinatra-bundles 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Rakefile +2 -1
  2. data/VERSION +1 -1
  3. data/lib/sinatra/bundles/bundle.rb +36 -0
  4. data/lib/sinatra/bundles/helpers.rb +22 -0
  5. data/lib/sinatra/bundles/javascript_bundle.rb +37 -0
  6. data/lib/sinatra/bundles/stylesheet_bundle.rb +36 -0
  7. data/lib/sinatra/bundles.rb +4 -114
  8. data/sinatra-bundles.gemspec +11 -58
  9. data/spec/app.rb +1 -1
  10. data/spec/production_app.rb +1 -1
  11. data/spec/public/javascripts/eval.js +5 -0
  12. data/spec/sinatra-bundles_spec.rb +10 -1
  13. data/spec/spec_helper.rb +5 -6
  14. metadata +17 -57
  15. data/vendor/cache/sinatra-0.10.1.gem +0 -0
  16. data/vendor/gems/sinatra-0.10.1/AUTHORS +0 -43
  17. data/vendor/gems/sinatra-0.10.1/CHANGES +0 -467
  18. data/vendor/gems/sinatra-0.10.1/LICENSE +0 -22
  19. data/vendor/gems/sinatra-0.10.1/README.jp.rdoc +0 -552
  20. data/vendor/gems/sinatra-0.10.1/README.rdoc +0 -622
  21. data/vendor/gems/sinatra-0.10.1/Rakefile +0 -129
  22. data/vendor/gems/sinatra-0.10.1/lib/sinatra/base.rb +0 -1143
  23. data/vendor/gems/sinatra-0.10.1/lib/sinatra/images/404.png +0 -0
  24. data/vendor/gems/sinatra-0.10.1/lib/sinatra/images/500.png +0 -0
  25. data/vendor/gems/sinatra-0.10.1/lib/sinatra/main.rb +0 -28
  26. data/vendor/gems/sinatra-0.10.1/lib/sinatra/showexceptions.rb +0 -303
  27. data/vendor/gems/sinatra-0.10.1/lib/sinatra/tilt.rb +0 -509
  28. data/vendor/gems/sinatra-0.10.1/lib/sinatra.rb +0 -7
  29. data/vendor/gems/sinatra-0.10.1/sinatra.gemspec +0 -86
  30. data/vendor/gems/sinatra-0.10.1/test/base_test.rb +0 -160
  31. data/vendor/gems/sinatra-0.10.1/test/builder_test.rb +0 -65
  32. data/vendor/gems/sinatra-0.10.1/test/contest.rb +0 -64
  33. data/vendor/gems/sinatra-0.10.1/test/erb_test.rb +0 -81
  34. data/vendor/gems/sinatra-0.10.1/test/erubis_test.rb +0 -82
  35. data/vendor/gems/sinatra-0.10.1/test/extensions_test.rb +0 -100
  36. data/vendor/gems/sinatra-0.10.1/test/filter_test.rb +0 -195
  37. data/vendor/gems/sinatra-0.10.1/test/haml_test.rb +0 -90
  38. data/vendor/gems/sinatra-0.10.1/test/helper.rb +0 -76
  39. data/vendor/gems/sinatra-0.10.1/test/helpers_test.rb +0 -573
  40. data/vendor/gems/sinatra-0.10.1/test/mapped_error_test.rb +0 -186
  41. data/vendor/gems/sinatra-0.10.1/test/middleware_test.rb +0 -68
  42. data/vendor/gems/sinatra-0.10.1/test/request_test.rb +0 -33
  43. data/vendor/gems/sinatra-0.10.1/test/response_test.rb +0 -42
  44. data/vendor/gems/sinatra-0.10.1/test/result_test.rb +0 -98
  45. data/vendor/gems/sinatra-0.10.1/test/route_added_hook_test.rb +0 -59
  46. data/vendor/gems/sinatra-0.10.1/test/routing_test.rb +0 -878
  47. data/vendor/gems/sinatra-0.10.1/test/sass_test.rb +0 -79
  48. data/vendor/gems/sinatra-0.10.1/test/server_test.rb +0 -47
  49. data/vendor/gems/sinatra-0.10.1/test/sinatra_test.rb +0 -13
  50. data/vendor/gems/sinatra-0.10.1/test/static_test.rb +0 -87
  51. data/vendor/gems/sinatra-0.10.1/test/templates_test.rb +0 -155
  52. data/vendor/gems/sinatra-0.10.1/test/views/error.builder +0 -3
  53. data/vendor/gems/sinatra-0.10.1/test/views/error.erb +0 -3
  54. data/vendor/gems/sinatra-0.10.1/test/views/error.erubis +0 -3
  55. data/vendor/gems/sinatra-0.10.1/test/views/error.haml +0 -3
  56. data/vendor/gems/sinatra-0.10.1/test/views/error.sass +0 -2
  57. data/vendor/gems/sinatra-0.10.1/test/views/foo/hello.test +0 -1
  58. data/vendor/gems/sinatra-0.10.1/test/views/hello.builder +0 -1
  59. data/vendor/gems/sinatra-0.10.1/test/views/hello.erb +0 -1
  60. data/vendor/gems/sinatra-0.10.1/test/views/hello.erubis +0 -1
  61. data/vendor/gems/sinatra-0.10.1/test/views/hello.haml +0 -1
  62. data/vendor/gems/sinatra-0.10.1/test/views/hello.sass +0 -2
  63. data/vendor/gems/sinatra-0.10.1/test/views/hello.test +0 -1
  64. data/vendor/gems/sinatra-0.10.1/test/views/layout2.builder +0 -3
  65. data/vendor/gems/sinatra-0.10.1/test/views/layout2.erb +0 -2
  66. data/vendor/gems/sinatra-0.10.1/test/views/layout2.erubis +0 -2
  67. data/vendor/gems/sinatra-0.10.1/test/views/layout2.haml +0 -2
  68. data/vendor/gems/sinatra-0.10.1/test/views/layout2.test +0 -1
  69. data/vendor/specifications/sinatra-0.10.1.gemspec +0 -40
@@ -1,79 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
- require 'sass'
3
-
4
- class SassTest < Test::Unit::TestCase
5
- def sass_app(&block)
6
- mock_app {
7
- set :views, File.dirname(__FILE__) + '/views'
8
- get '/', &block
9
- }
10
- get '/'
11
- end
12
-
13
- it 'renders inline Sass strings' do
14
- sass_app { sass "#sass\n :background-color #FFF\n" }
15
- assert ok?
16
- assert_equal "#sass {\n background-color: #FFF; }\n", body
17
- end
18
-
19
- it 'renders .sass files in views path' do
20
- sass_app { sass :hello }
21
- assert ok?
22
- assert_equal "#sass {\n background-color: #FFF; }\n", body
23
- end
24
-
25
- it 'ignores the layout option' do
26
- sass_app { sass :hello, :layout => :layout2 }
27
- assert ok?
28
- assert_equal "#sass {\n background-color: #FFF; }\n", body
29
- end
30
-
31
- it "raises error if template not found" do
32
- mock_app {
33
- get('/') { sass :no_such_template }
34
- }
35
- assert_raise(Errno::ENOENT) { get('/') }
36
- end
37
-
38
- it "passes SASS options to the Sass engine" do
39
- sass_app {
40
- sass "#sass\n :background-color #FFF\n :color #000\n", :style => :compact
41
- }
42
- assert ok?
43
- assert_equal "#sass { background-color: #FFF; color: #000; }\n", body
44
- end
45
-
46
- it "passes default SASS options to the Sass engine" do
47
- mock_app {
48
- set :sass, {:style => :compact} # default Sass style is :nested
49
- get '/' do
50
- sass "#sass\n :background-color #FFF\n :color #000\n"
51
- end
52
- }
53
- get '/'
54
- assert ok?
55
- assert_equal "#sass { background-color: #FFF; color: #000; }\n", body
56
- end
57
-
58
- it "merges the default SASS options with the overrides and passes them to the Sass engine" do
59
- mock_app {
60
- set :sass, {:style => :compact, :attribute_syntax => :alternate } # default Sass attribute_syntax is :normal (with : in front)
61
- get '/' do
62
- sass "#sass\n background-color: #FFF\n color: #000\n"
63
- end
64
- get '/raised' do
65
- sass "#sass\n :background-color #FFF\n :color #000\n", :style => :expanded # retains global attribute_syntax settings
66
- end
67
- get '/expanded_normal' do
68
- sass "#sass\n :background-color #FFF\n :color #000\n", :style => :expanded, :attribute_syntax => :normal
69
- end
70
- }
71
- get '/'
72
- assert ok?
73
- assert_equal "#sass { background-color: #FFF; color: #000; }\n", body
74
- assert_raise(Sass::SyntaxError) { get('/raised') }
75
- get '/expanded_normal'
76
- assert ok?
77
- assert_equal "#sass {\n background-color: #FFF;\n color: #000;\n}\n", body
78
- end
79
- end
@@ -1,47 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- module Rack::Handler
4
- class Mock
5
- extend Test::Unit::Assertions
6
-
7
- def self.run(app, options={})
8
- assert(app < Sinatra::Base)
9
- assert_equal 9001, options[:Port]
10
- assert_equal 'foo.local', options[:Host]
11
- yield new
12
- end
13
-
14
- def stop
15
- end
16
- end
17
-
18
- register 'mock', 'Rack::Handler::Mock'
19
- end
20
-
21
- class ServerTest < Test::Unit::TestCase
22
- setup do
23
- mock_app {
24
- set :server, 'mock'
25
- set :host, 'foo.local'
26
- set :port, 9001
27
- }
28
- $stdout = File.open('/dev/null', 'wb')
29
- end
30
-
31
- def teardown
32
- $stdout = STDOUT
33
- end
34
-
35
- it "locates the appropriate Rack handler and calls ::run" do
36
- @app.run!
37
- end
38
-
39
- it "sets options on the app before running" do
40
- @app.run! :sessions => true
41
- assert @app.sessions?
42
- end
43
-
44
- it "falls back on the next server handler when not found" do
45
- @app.run! :server => %w[foo bar mock]
46
- end
47
- end
@@ -1,13 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class SinatraTest < Test::Unit::TestCase
4
- it 'creates a new Sinatra::Base subclass on new' do
5
- app =
6
- Sinatra.new do
7
- get '/' do
8
- 'Hello World'
9
- end
10
- end
11
- assert_same Sinatra::Base, app.superclass
12
- end
13
- end
@@ -1,87 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class StaticTest < Test::Unit::TestCase
4
- setup do
5
- mock_app {
6
- set :static, true
7
- set :public, File.dirname(__FILE__)
8
- }
9
- end
10
-
11
- it 'serves GET requests for files in the public directory' do
12
- get "/#{File.basename(__FILE__)}"
13
- assert ok?
14
- assert_equal File.read(__FILE__), body
15
- assert_equal File.size(__FILE__).to_s, response['Content-Length']
16
- assert response.headers.include?('Last-Modified')
17
- end
18
-
19
- it 'produces a body that can be iterated over multiple times' do
20
- env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
21
- status, headers, body = @app.call(env)
22
- buf1, buf2 = [], []
23
- body.each { |part| buf1 << part }
24
- body.each { |part| buf2 << part }
25
- assert_equal buf1.join, buf2.join
26
- assert_equal File.read(__FILE__), buf1.join
27
- end
28
-
29
- it 'serves HEAD requests for files in the public directory' do
30
- head "/#{File.basename(__FILE__)}"
31
- assert ok?
32
- assert_equal '', body
33
- assert_equal File.size(__FILE__).to_s, response['Content-Length']
34
- assert response.headers.include?('Last-Modified')
35
- end
36
-
37
- %w[POST PUT DELETE].each do |verb|
38
- it "does not serve #{verb} requests" do
39
- send verb.downcase, "/#{File.basename(__FILE__)}"
40
- assert_equal 404, status
41
- end
42
- end
43
-
44
- it 'serves files in preference to custom routes' do
45
- @app.get("/#{File.basename(__FILE__)}") { 'Hello World' }
46
- get "/#{File.basename(__FILE__)}"
47
- assert ok?
48
- assert body != 'Hello World'
49
- end
50
-
51
- it 'does not serve directories' do
52
- get "/"
53
- assert not_found?
54
- end
55
-
56
- it 'passes to the next handler when the static option is disabled' do
57
- @app.set :static, false
58
- get "/#{File.basename(__FILE__)}"
59
- assert not_found?
60
- end
61
-
62
- it 'passes to the next handler when the public option is nil' do
63
- @app.set :public, nil
64
- get "/#{File.basename(__FILE__)}"
65
- assert not_found?
66
- end
67
-
68
- it '404s when a file is not found' do
69
- get "/foobarbaz.txt"
70
- assert not_found?
71
- end
72
-
73
- it 'serves files when .. path traverses within public directory' do
74
- get "/data/../#{File.basename(__FILE__)}"
75
- assert ok?
76
- assert_equal File.read(__FILE__), body
77
- end
78
-
79
- it '404s when .. path traverses outside of public directory' do
80
- mock_app {
81
- set :static, true
82
- set :public, File.dirname(__FILE__) + '/data'
83
- }
84
- get "/../#{File.basename(__FILE__)}"
85
- assert not_found?
86
- end
87
- end
@@ -1,155 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestTemplate < Tilt::Template
4
- def compile!
5
- end
6
-
7
- def evaluate(scope, locals={}, &block)
8
- inner = block ? block.call : ''
9
- data + inner
10
- end
11
-
12
- Tilt.register 'test', self
13
- end
14
-
15
- class TemplatesTest < Test::Unit::TestCase
16
- def render_app(base=Sinatra::Base, &block)
17
- mock_app(base) {
18
- set :views, File.dirname(__FILE__) + '/views'
19
- get '/', &block
20
- template(:layout3) { "Layout 3!\n" }
21
- }
22
- get '/'
23
- end
24
-
25
- def with_default_layout
26
- layout = File.dirname(__FILE__) + '/views/layout.test'
27
- File.open(layout, 'wb') { |io| io.write "Layout!\n" }
28
- yield
29
- ensure
30
- File.unlink(layout) rescue nil
31
- end
32
-
33
- it 'renders String templates directly' do
34
- render_app { render :test, 'Hello World' }
35
- assert ok?
36
- assert_equal 'Hello World', body
37
- end
38
-
39
- it 'renders Proc templates using the call result' do
40
- render_app { render :test, Proc.new {'Hello World'} }
41
- assert ok?
42
- assert_equal 'Hello World', body
43
- end
44
-
45
- it 'looks up Symbol templates in views directory' do
46
- render_app { render :test, :hello }
47
- assert ok?
48
- assert_equal "Hello World!\n", body
49
- end
50
-
51
- it 'uses the default layout template if not explicitly overridden' do
52
- with_default_layout do
53
- render_app { render :test, :hello }
54
- assert ok?
55
- assert_equal "Layout!\nHello World!\n", body
56
- end
57
- end
58
-
59
- it 'uses the default layout template if not really overriden' do
60
- with_default_layout do
61
- render_app { render :test, :hello, :layout => true }
62
- assert ok?
63
- assert_equal "Layout!\nHello World!\n", body
64
- end
65
- end
66
-
67
- it 'uses the layout template specified' do
68
- render_app { render :test, :hello, :layout => :layout2 }
69
- assert ok?
70
- assert_equal "Layout 2!\nHello World!\n", body
71
- end
72
-
73
- it 'uses layout templates defined with the #template method' do
74
- render_app { render :test, :hello, :layout => :layout3 }
75
- assert ok?
76
- assert_equal "Layout 3!\nHello World!\n", body
77
- end
78
-
79
- it 'loads templates from source file with inline_templates enabled' do
80
- mock_app {
81
- enable :inline_templates
82
- }
83
- assert_equal "this is foo\n\n", @app.templates[:foo][0]
84
- assert_equal "X\n= yield\nX\n", @app.templates[:layout][0]
85
- end
86
-
87
- it 'loads templates from specified views directory' do
88
- render_app { render :test, :hello, :views => options.views + '/foo' }
89
-
90
- assert_equal "from another views directory\n", body
91
- end
92
-
93
- test 'use_in_file_templates simply ignores IO errors' do
94
- assert_nothing_raised {
95
- mock_app {
96
- set :inline_templates, '/foo/bar'
97
- }
98
- }
99
-
100
- assert @app.templates.empty?
101
- end
102
-
103
- it 'passes locals to the layout' do
104
- mock_app {
105
- template :my_layout do
106
- 'Hello <%= name %>!<%= yield %>'
107
- end
108
-
109
- get '/' do
110
- erb '<p>content</p>', { :layout => :my_layout }, { :name => 'Mike'}
111
- end
112
- }
113
-
114
- get '/'
115
- assert ok?
116
- assert_equal 'Hello Mike!<p>content</p>', body
117
- end
118
-
119
- it 'loads templates defined in subclasses' do
120
- base = Class.new(Sinatra::Base)
121
- base.template(:foo) { 'bar' }
122
- render_app(base) { render :test, :foo }
123
- assert ok?
124
- assert_equal 'bar', body
125
- end
126
-
127
- it 'uses templates in superclasses before subclasses' do
128
- base = Class.new(Sinatra::Base)
129
- base.template(:foo) { 'template in superclass' }
130
- assert_equal 'template in superclass', base.templates[:foo].first.call
131
-
132
- mock_app(base) {
133
- set :views, File.dirname(__FILE__) + '/views'
134
- template(:foo) { 'template in subclass' }
135
- get('/') { render :test, :foo }
136
- }
137
- assert_equal 'template in subclass', @app.templates[:foo].first.call
138
-
139
- get '/'
140
- assert ok?
141
- assert_equal 'template in subclass', body
142
- end
143
- end
144
-
145
- # __END__ : this is not the real end of the script.
146
-
147
- __END__
148
-
149
- @@ foo
150
- this is foo
151
-
152
- @@ layout
153
- X
154
- = yield
155
- X
@@ -1,3 +0,0 @@
1
- xml.error do
2
- raise "goodbye"
3
- end
@@ -1,3 +0,0 @@
1
- Hello <%= 'World' %>
2
- <% raise 'Goodbye' unless defined?(french) && french %>
3
- <% raise 'Au revoir' if defined?(french) && french %>
@@ -1,3 +0,0 @@
1
- Hello <%= 'World' %>
2
- <% raise 'Goodbye' unless defined?(french) && french %>
3
- <% raise 'Au revoir' if defined?(french) && french %>
@@ -1,3 +0,0 @@
1
- %h1 Hello From Haml
2
- = raise 'goodbye' unless defined?(french) && french
3
- = raise 'au revoir' if defined?(french) && french
@@ -1,2 +0,0 @@
1
- #sass
2
- +argle-bargle
@@ -1 +0,0 @@
1
- from another views directory
@@ -1 +0,0 @@
1
- xml.exclaim "You're my boy, #{@name}!"
@@ -1 +0,0 @@
1
- Hello <%= 'World' %>
@@ -1 +0,0 @@
1
- Hello <%= 'World' %>
@@ -1 +0,0 @@
1
- %h1 Hello From Haml
@@ -1,2 +0,0 @@
1
- #sass
2
- :background-color #FFF
@@ -1 +0,0 @@
1
- Hello World!
@@ -1,3 +0,0 @@
1
- xml.layout do
2
- xml << yield
3
- end
@@ -1,2 +0,0 @@
1
- ERB Layout!
2
- <%= yield %>
@@ -1,2 +0,0 @@
1
- ERubis Layout!
2
- <%= yield %>
@@ -1,2 +0,0 @@
1
- %h1 HAML Layout!
2
- %p= yield
@@ -1 +0,0 @@
1
- Layout 2!
@@ -1,40 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{sinatra}
5
- s.version = "0.10.1"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Blake Mizerany", "Ryan Tomayko", "Simon Rozet"]
9
- s.date = %q{2009-12-13}
10
- s.description = %q{Classy web-development dressed in a DSL}
11
- s.email = %q{sinatrarb@googlegroups.com}
12
- s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
13
- s.files = ["AUTHORS", "CHANGES", "LICENSE", "README.jp.rdoc", "README.rdoc", "Rakefile", "lib/sinatra.rb", "lib/sinatra/base.rb", "lib/sinatra/images/404.png", "lib/sinatra/images/500.png", "lib/sinatra/main.rb", "lib/sinatra/showexceptions.rb", "lib/sinatra/tilt.rb", "sinatra.gemspec", "test/base_test.rb", "test/builder_test.rb", "test/contest.rb", "test/erb_test.rb", "test/erubis_test.rb", "test/extensions_test.rb", "test/filter_test.rb", "test/haml_test.rb", "test/helper.rb", "test/helpers_test.rb", "test/mapped_error_test.rb", "test/middleware_test.rb", "test/request_test.rb", "test/response_test.rb", "test/result_test.rb", "test/route_added_hook_test.rb", "test/routing_test.rb", "test/sass_test.rb", "test/server_test.rb", "test/sinatra_test.rb", "test/static_test.rb", "test/templates_test.rb", "test/views/error.builder", "test/views/error.erb", "test/views/error.erubis", "test/views/error.haml", "test/views/error.sass", "test/views/foo/hello.test", "test/views/hello.builder", "test/views/hello.erb", "test/views/hello.erubis", "test/views/hello.haml", "test/views/hello.sass", "test/views/hello.test", "test/views/layout2.builder", "test/views/layout2.erb", "test/views/layout2.erubis", "test/views/layout2.haml", "test/views/layout2.test"]
14
- s.homepage = %q{http://sinatra.rubyforge.org}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sinatra", "--main", "README.rdoc"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{sinatra}
18
- s.rubygems_version = %q{1.3.5}
19
- s.summary = %q{Classy web-development dressed in a DSL}
20
- s.test_files = ["test/base_test.rb", "test/builder_test.rb", "test/erb_test.rb", "test/erubis_test.rb", "test/extensions_test.rb", "test/filter_test.rb", "test/haml_test.rb", "test/helpers_test.rb", "test/mapped_error_test.rb", "test/middleware_test.rb", "test/request_test.rb", "test/response_test.rb", "test/result_test.rb", "test/route_added_hook_test.rb", "test/routing_test.rb", "test/sass_test.rb", "test/server_test.rb", "test/sinatra_test.rb", "test/static_test.rb", "test/templates_test.rb"]
21
-
22
- if s.respond_to? :specification_version then
23
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 2
25
-
26
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
- s.add_runtime_dependency(%q<rack>, [">= 1.0"])
28
- s.add_development_dependency(%q<shotgun>, [">= 0.3", "< 1.0"])
29
- s.add_development_dependency(%q<rack-test>, [">= 0.3.0"])
30
- else
31
- s.add_dependency(%q<rack>, [">= 1.0"])
32
- s.add_dependency(%q<shotgun>, [">= 0.3", "< 1.0"])
33
- s.add_dependency(%q<rack-test>, [">= 0.3.0"])
34
- end
35
- else
36
- s.add_dependency(%q<rack>, [">= 1.0"])
37
- s.add_dependency(%q<shotgun>, [">= 0.3", "< 1.0"])
38
- s.add_dependency(%q<rack-test>, [">= 0.3.0"])
39
- end
40
- end