goliath_rack_sprockets 0.1.0
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/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/Guardfile +8 -0
- data/LICENSE +18 -0
- data/README.md +26 -0
- data/Rakefile +1 -0
- data/goliath_rack_sprockets.gemspec +41 -0
- data/lib/goliath/rack/sprockets.rb +52 -0
- data/lib/goliath/rack/sprockets/version.rb +7 -0
- data/spec/fixtures/assets/javascripts/exists.js +1 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/rack/sprockets_spec.rb +108 -0
- metadata +222 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2012 Maarten Hoogendoorn.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Sprockets for Goliath
|
2
|
+
|
3
|
+
[](http://travis-ci.org/moretea/goliath_rack_sprockets)
|
4
|
+
|
5
|
+
|
6
|
+
This gem makes it possible to use sprockets with Goliath.
|
7
|
+
|
8
|
+
## Installation & Prerequisites
|
9
|
+
|
10
|
+
* You should have a Gemfile with Goliath
|
11
|
+
* Add <code>goliath_rack_sprockets</code>
|
12
|
+
|
13
|
+
|
14
|
+
## Example usage
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require "goliath/rack/sprockets"
|
18
|
+
|
19
|
+
class SomeApp < Goliath::API
|
20
|
+
use(Goliath::Rack::Sprockets, asset_paths: ["app/assets/javascripts", "app/assets/stylesheets"])
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
## License
|
25
|
+
|
26
|
+
Sprockets for Goliath is distributed under the MIT license, for full details please see the LICENSE file.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'goliath/rack/sprockets/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'goliath_rack_sprockets'
|
7
|
+
s.version = Goliath::Rack::Sprockets::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Maarten Hoogendoorn']
|
10
|
+
s.email = ['maarten@moretea.nl']
|
11
|
+
s.homepage = 'http://github.com/moretea/goliath_rack_sprockets'
|
12
|
+
s.summary = 'Sprockets middleware for goliath'
|
13
|
+
s.description = s.summary
|
14
|
+
|
15
|
+
s.required_ruby_version = '>=1.9.2'
|
16
|
+
|
17
|
+
s.add_dependency 'goliath', '~> 1.0.0'
|
18
|
+
s.add_dependency 'sprockets', '~> 2.5.0'
|
19
|
+
|
20
|
+
s.add_development_dependency 'simplecov', '>= 0.6.4'
|
21
|
+
s.add_development_dependency 'rspec', '>2.0'
|
22
|
+
s.add_development_dependency 'em-http-request', '>=1.0.0'
|
23
|
+
s.add_development_dependency 'rack-rewrite'
|
24
|
+
s.add_development_dependency 'multipart_body'
|
25
|
+
|
26
|
+
s.add_development_dependency 'guard'
|
27
|
+
s.add_development_dependency 'guard-rspec'
|
28
|
+
|
29
|
+
if RUBY_PLATFORM.include?('darwin')
|
30
|
+
s.add_development_dependency 'growl', '~> 1.0.3'
|
31
|
+
s.add_development_dependency 'rb-fsevent'
|
32
|
+
elsif RUBY_PLATFORM.include?('linux')
|
33
|
+
s.add_development_dependency 'rb-inotify'
|
34
|
+
end
|
35
|
+
|
36
|
+
s.files = `git ls-files`.split("\n")
|
37
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
38
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
39
|
+
|
40
|
+
s.require_paths = ['lib']
|
41
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'goliath/rack/sprockets/version'
|
3
|
+
|
4
|
+
module Goliath
|
5
|
+
module Rack
|
6
|
+
class Sprockets
|
7
|
+
|
8
|
+
def initialize(app, options)
|
9
|
+
@app = app
|
10
|
+
@options = options
|
11
|
+
|
12
|
+
@options[:root] ||= Goliath::Application.root_path
|
13
|
+
@options[:url_path] ||= "/assets/"
|
14
|
+
|
15
|
+
if not @options.has_key?(:asset_paths)
|
16
|
+
raise ArgumentError.new("You should pass the :asset_paths option")
|
17
|
+
end
|
18
|
+
|
19
|
+
if @options[:asset_paths].nil? || @options[:asset_paths].empty?
|
20
|
+
raise ArgumentError.new("The :asset_paths option is invalid")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
if (asset_path = env['REQUEST_PATH']).start_with?(@options[:url_path])
|
26
|
+
logical_name = File.basename(asset_path)
|
27
|
+
|
28
|
+
# Build sprockets environment
|
29
|
+
environment = ::Sprockets::Environment.new(@options[:root])
|
30
|
+
@options[:asset_paths].each do |asset_path|
|
31
|
+
environment.append_path asset_path
|
32
|
+
end
|
33
|
+
|
34
|
+
# Lookup the asset
|
35
|
+
asset = environment[logical_name]
|
36
|
+
|
37
|
+
if asset
|
38
|
+
[200, {
|
39
|
+
'Content-Type' => asset.content_type,
|
40
|
+
'Last-Modified' => asset.mtime,
|
41
|
+
'ETag' => asset.digest
|
42
|
+
}, asset.to_s]
|
43
|
+
else
|
44
|
+
[404, {}, "No such asset (#{logical_name}) found"]
|
45
|
+
end
|
46
|
+
else
|
47
|
+
@app.call(env)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
alert("I exist");
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require "goliath"
|
3
|
+
|
4
|
+
Bundler.setup
|
5
|
+
Bundler.require
|
6
|
+
|
7
|
+
require 'goliath/test_helper'
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start
|
10
|
+
|
11
|
+
Goliath.env = :test
|
12
|
+
|
13
|
+
RSpec.configure do |c|
|
14
|
+
c.include Goliath::TestHelper, :example_group => {
|
15
|
+
:file_path => /spec\/integration/
|
16
|
+
}
|
17
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'goliath/rack/sprockets'
|
3
|
+
require 'goliath/goliath'
|
4
|
+
|
5
|
+
describe Goliath::Rack::Sprockets do
|
6
|
+
let(:app) { mock('app').as_null_object }
|
7
|
+
let(:options) { {
|
8
|
+
root: File.expand_path("../../../fixtures", __FILE__),
|
9
|
+
asset_paths: ["assets/javascripts", "assets/stylesheets"]
|
10
|
+
} }
|
11
|
+
let(:request_path) { "/assets/javascripts/some.js" }
|
12
|
+
|
13
|
+
let(:env) do
|
14
|
+
env = Goliath::Env.new
|
15
|
+
env['REQUEST_PATH'] = request_path
|
16
|
+
env
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { Goliath::Rack::Sprockets.new(app, options) }
|
20
|
+
|
21
|
+
it 'accepts an app' do
|
22
|
+
lambda { Goliath::Rack::Sprockets.new('my app', options) }.should_not raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
context "illegal configuration" do
|
26
|
+
context "empty options" do
|
27
|
+
let(:options) { {} }
|
28
|
+
it "is not allowed" do
|
29
|
+
expect { Goliath::Rack::Sprockets.new(app, options) }.to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "illegal asset path" do
|
34
|
+
it "nil is not accepted" do
|
35
|
+
options = { asset_paths: nil}
|
36
|
+
expect { Goliath::Rack::Sprockets.new(app, options) }.to raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "empty list is not accepted" do
|
40
|
+
options = { asset_paths: [] }
|
41
|
+
expect { Goliath::Rack::Sprockets.new(app, options) }.to raise_error
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "request chain filtering" do
|
47
|
+
context "non asset path" do
|
48
|
+
let(:request_path) { "/not/a/asset" }
|
49
|
+
|
50
|
+
it "hands over execution to the next rack middleware" do
|
51
|
+
app.should_receive(:call)
|
52
|
+
subject.call(env)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "asset path" do
|
57
|
+
let(:request_path) { "/assets/some_file.js" }
|
58
|
+
|
59
|
+
it "stops the chain" do
|
60
|
+
app.should_not_receive(:call)
|
61
|
+
subject.call(env)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "asset handling" do
|
67
|
+
let(:request_path) { "/assets/awesome.js" }
|
68
|
+
|
69
|
+
it "look up the correct logical file name" do
|
70
|
+
::Sprockets::Environment.any_instance.should_receive(:[]).with("awesome.js")
|
71
|
+
subject.call(env)
|
72
|
+
end
|
73
|
+
|
74
|
+
context "existence of asset" do
|
75
|
+
let(:response) { subject.call(env) }
|
76
|
+
let(:response_status) { response[0] }
|
77
|
+
let(:response_body) { response[2] }
|
78
|
+
|
79
|
+
context "asset doesn't exist" do
|
80
|
+
let(:request_path) { "/assets/does_not_exist.js" }
|
81
|
+
|
82
|
+
it "returns a 404" do
|
83
|
+
response_status.should == 404
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns an error message" do
|
87
|
+
response_body.should == "No such asset (does_not_exist.js) found"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "asset exists" do
|
92
|
+
let(:request_path) { "/assets/exists.js" }
|
93
|
+
|
94
|
+
before do
|
95
|
+
File.stub(:exists?).and_return true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns a 200" do
|
99
|
+
response_status.should == 200
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns the content of the asset file" do
|
103
|
+
response_body.chomp.should == 'alert("I exist");'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goliath_rack_sprockets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maarten Hoogendoorn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: goliath
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sprockets
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.5.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: simplecov
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.6.4
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.4
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>'
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>'
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: em-http-request
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.0.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rack-rewrite
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: multipart_body
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: guard-rspec
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: rb-inotify
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
description: Sprockets middleware for goliath
|
175
|
+
email:
|
176
|
+
- maarten@moretea.nl
|
177
|
+
executables: []
|
178
|
+
extensions: []
|
179
|
+
extra_rdoc_files: []
|
180
|
+
files:
|
181
|
+
- .gitignore
|
182
|
+
- .rspec
|
183
|
+
- .travis.yml
|
184
|
+
- Gemfile
|
185
|
+
- Guardfile
|
186
|
+
- LICENSE
|
187
|
+
- README.md
|
188
|
+
- Rakefile
|
189
|
+
- goliath_rack_sprockets.gemspec
|
190
|
+
- lib/goliath/rack/sprockets.rb
|
191
|
+
- lib/goliath/rack/sprockets/version.rb
|
192
|
+
- spec/fixtures/assets/javascripts/exists.js
|
193
|
+
- spec/spec_helper.rb
|
194
|
+
- spec/unit/rack/sprockets_spec.rb
|
195
|
+
homepage: http://github.com/moretea/goliath_rack_sprockets
|
196
|
+
licenses: []
|
197
|
+
post_install_message:
|
198
|
+
rdoc_options: []
|
199
|
+
require_paths:
|
200
|
+
- lib
|
201
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ! '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: 1.9.2
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ! '>='
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
requirements: []
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 1.8.23
|
216
|
+
signing_key:
|
217
|
+
specification_version: 3
|
218
|
+
summary: Sprockets middleware for goliath
|
219
|
+
test_files:
|
220
|
+
- spec/fixtures/assets/javascripts/exists.js
|
221
|
+
- spec/spec_helper.rb
|
222
|
+
- spec/unit/rack/sprockets_spec.rb
|