sprockets-helpers 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Appraisals +12 -0
- data/README.md +43 -23
- data/gemfiles/{sprockets-2.0.gemfile → sprockets_2.0.gemfile} +0 -0
- data/gemfiles/{sprockets-2.1.gemfile → sprockets_2.1.gemfile} +0 -0
- data/gemfiles/{sprockets-2.2.gemfile → sprockets_2.2.gemfile} +0 -0
- data/gemfiles/{sprockets-2.3.gemfile → sprockets_2.3.gemfile} +0 -0
- data/gemfiles/{sprockets-2.4.gemfile → sprockets_2.4.gemfile} +0 -0
- data/gemfiles/{sprockets-2.5.gemfile → sprockets_2.5.gemfile} +0 -0
- data/gemfiles/{sprockets-2.6.gemfile → sprockets_2.6.gemfile} +0 -0
- data/gemfiles/sprockets_2.7.gemfile +7 -0
- data/gemfiles/sprockets_2.8.gemfile +7 -0
- data/gemfiles/sprockets_2.9.gemfile +7 -0
- data/lib/sinatra/sprockets-helpers.rb +1 -0
- data/lib/sinatra/sprockets/helpers.rb +34 -0
- data/lib/sprockets/helpers/version.rb +1 -1
- data/spec/spec_helper.rb +7 -1
- data/spec/sprockets-helpers_spec.rb +124 -82
- data/sprockets-helpers.gemspec +3 -2
- metadata +70 -24
data/Appraisals
CHANGED
@@ -25,3 +25,15 @@ end
|
|
25
25
|
appraise 'sprockets-2.6' do
|
26
26
|
gem 'sprockets', '~> 2.6.0'
|
27
27
|
end
|
28
|
+
|
29
|
+
appraise 'sprockets-2.7' do
|
30
|
+
gem 'sprockets', '~> 2.7.0'
|
31
|
+
end
|
32
|
+
|
33
|
+
appraise 'sprockets-2.8' do
|
34
|
+
gem 'sprockets', '~> 2.8.0'
|
35
|
+
end
|
36
|
+
|
37
|
+
appraise 'sprockets-2.9' do
|
38
|
+
gem 'sprockets', '~> 2.9.0'
|
39
|
+
end
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
sprockets-helpers
|
2
|
-
=================
|
1
|
+
# sprockets-helpers
|
3
2
|
|
4
3
|
**Asset path helpers for Sprockets 2.x applications**
|
5
4
|
|
@@ -12,17 +11,13 @@ Sprockets::Helpers adds the asset_path helpers, familiar to Rails developers, to
|
|
12
11
|
* Optionally outputs digest paths.
|
13
12
|
* Falls back to file paths in the public directory & adds cache busting timestamp.
|
14
13
|
|
15
|
-
|
16
|
-
Installation
|
17
|
-
------------
|
14
|
+
## Installation
|
18
15
|
|
19
16
|
``` bash
|
20
17
|
$ gem install sprockets-helpers
|
21
18
|
```
|
22
19
|
|
23
|
-
|
24
|
-
Setup
|
25
|
-
-----
|
20
|
+
## Setup
|
26
21
|
|
27
22
|
Let's build a simple Sinatra app using Sprockets and Sprockets::Helpers (See my fork of [sinatra-asset-pipeline](https://github.com/petebrowne/sinatra-asset-pipeline) for complete setup):
|
28
23
|
|
@@ -67,9 +62,7 @@ class App < Sinatra::Base
|
|
67
62
|
end
|
68
63
|
```
|
69
64
|
|
70
|
-
|
71
|
-
Usage in Assets
|
72
|
-
---------------
|
65
|
+
## Usage in Assets
|
73
66
|
|
74
67
|
Simply requiring sprockets-helpers will add the asset path helpers to the Sprocket context, making them available within any asset. For example, a file `assets/javascripts/paths.js.erb`:
|
75
68
|
|
@@ -83,9 +76,7 @@ Would be transformed into:
|
|
83
76
|
var Paths = { railsImage: '/assets/rails.png' };
|
84
77
|
```
|
85
78
|
|
86
|
-
|
87
|
-
Usage in the App
|
88
|
-
----------------
|
79
|
+
## Usage in the App
|
89
80
|
|
90
81
|
The helpers can also be used in the app itself. You just include the `Sprockets::Helpers` module and set Sprockets::Helpers.environment to the Sprockets environment to search for the assets. Alternatively you can define an #assets_environment method in the context of #asset_path, which returns a reference to the Sprockets environment (see above).
|
91
82
|
|
@@ -159,9 +150,7 @@ Would become:
|
|
159
150
|
</html>
|
160
151
|
```
|
161
152
|
|
162
|
-
|
163
|
-
Fallback to Public Directory
|
164
|
-
----------------------------
|
153
|
+
## Fallback to Public Directory
|
165
154
|
|
166
155
|
If the source is not an asset in the Sprockets environment, Sprockets::Helpers will fallback to looking for the file in the application's public directory. It will also append the cache busting timestamp of the file. For example:
|
167
156
|
|
@@ -177,11 +166,9 @@ Would become:
|
|
177
166
|
<img src='/images/logo.jpg?1320093919'>
|
178
167
|
```
|
179
168
|
|
169
|
+
## Manifest Usage
|
180
170
|
|
181
|
-
|
182
|
-
--------------
|
183
|
-
|
184
|
-
**New in 0.4**: Sprockets::Helpers will use the latest fingerprinted filename directly from a `manifest.json` file:
|
171
|
+
Sprockets::Helpers will use the latest fingerprinted filename directly from a `manifest.json` file:
|
185
172
|
|
186
173
|
|
187
174
|
``` ruby
|
@@ -195,8 +182,41 @@ end
|
|
195
182
|
# ...
|
196
183
|
```
|
197
184
|
|
185
|
+
## Sinatra Integration
|
186
|
+
|
187
|
+
**New in 1.0**: there is an easier way to integrate with Sinatra applications. You can register the `Sinatra::Sprockets::Helpers` extension and it will automatically include the helpers:
|
188
|
+
|
189
|
+
``` ruby
|
190
|
+
require 'sinatra/base'
|
191
|
+
require 'sprockets'
|
192
|
+
require 'sinatra/sprockets-helpers'
|
193
|
+
|
194
|
+
class App < Sinatra::Base
|
195
|
+
register Sinatra::Sprockets::Helpers
|
196
|
+
set :sprockets, Sprockets::Environment.new(root)
|
197
|
+
set :assets_prefix, '/assets'
|
198
|
+
set :digest_assets, true
|
199
|
+
|
200
|
+
configure do
|
201
|
+
# Setup Sprockets
|
202
|
+
sprockets.append_path File.join(root, 'assets', 'stylesheets')
|
203
|
+
sprockets.append_path File.join(root, 'assets', 'javascripts')
|
204
|
+
sprockets.append_path File.join(root, 'assets', 'images')
|
205
|
+
|
206
|
+
configure_sprockets_helpers do |helpers|
|
207
|
+
# This will automatically configure Sprockets::Helpers based on the
|
208
|
+
# `sprockets`, `public_folder`, `assets_prefix`, and `digest_assets`
|
209
|
+
# settings if they exist. Otherwise you can configure as normal:
|
210
|
+
helpers.asset_host = 'some-bucket.s3.amazon.com'
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
get '/' do
|
215
|
+
erb :index
|
216
|
+
end
|
217
|
+
end
|
218
|
+
```
|
198
219
|
|
199
|
-
Copyright
|
200
|
-
---------
|
220
|
+
## Copyright
|
201
221
|
|
202
222
|
Copyright (c) 2011 [Peter Browne](http://petebrowne.com). See LICENSE for details.
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sinatra/sprockets/helpers'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sprockets/helpers'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
module Sprockets
|
6
|
+
module Helpers
|
7
|
+
def self.registered(app)
|
8
|
+
app.helpers ::Sprockets::Helpers
|
9
|
+
app.configure_sprockets_helpers
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure_sprockets_helpers(&block)
|
13
|
+
::Sprockets::Helpers.configure do |helpers|
|
14
|
+
with_setting(:sprockets) { |value| helpers.environment = value }
|
15
|
+
with_setting(:public_folder) { |value| helpers.public_path = value }
|
16
|
+
with_setting(:digest_assets) { |value| helpers.digest = value }
|
17
|
+
with_setting(:assets_prefix) { |value| helpers.prefix = value }
|
18
|
+
end
|
19
|
+
::Sprockets::Helpers.configure(&block) if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def with_setting(name, &block)
|
25
|
+
return unless settings.respond_to?(name)
|
26
|
+
|
27
|
+
value = settings.__send__(name)
|
28
|
+
yield value unless value.nil?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
register Sprockets::Helpers
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'sprockets'
|
2
2
|
require 'sprockets-helpers'
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'sinatra/sprockets/helpers'
|
3
5
|
require 'construct'
|
4
6
|
require 'pathname'
|
5
7
|
|
@@ -10,6 +12,11 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
10
12
|
RSpec.configure do |config|
|
11
13
|
config.include Construct::Helpers
|
12
14
|
|
15
|
+
# Disable old `should` syntax
|
16
|
+
config.expect_with :rspec do |c|
|
17
|
+
c.syntax = :expect
|
18
|
+
end
|
19
|
+
|
13
20
|
# Returns a Sprockets environment. Automatically
|
14
21
|
# appends the 'assets' path if available.
|
15
22
|
def env
|
@@ -44,5 +51,4 @@ RSpec.configure do |config|
|
|
44
51
|
c.file('assets/b.css')
|
45
52
|
}.call(construct)
|
46
53
|
end
|
47
|
-
|
48
54
|
end
|
@@ -6,12 +6,12 @@ describe Sprockets::Helpers do
|
|
6
6
|
within_construct do |c|
|
7
7
|
c.file 'assets/main.css'
|
8
8
|
|
9
|
-
context.asset_path('main.css').
|
9
|
+
expect(context.asset_path('main.css')).to eq('/assets/main.css')
|
10
10
|
Sprockets::Helpers.configure do |config|
|
11
11
|
config.digest = true
|
12
12
|
config.prefix = '/themes'
|
13
13
|
end
|
14
|
-
context.asset_path('main.css').
|
14
|
+
expect(context.asset_path('main.css')).to match(%r(/themes/main-[0-9a-f]+.css))
|
15
15
|
Sprockets::Helpers.digest = nil
|
16
16
|
Sprockets::Helpers.prefix = nil
|
17
17
|
end
|
@@ -23,9 +23,9 @@ describe Sprockets::Helpers do
|
|
23
23
|
within_construct do |c|
|
24
24
|
c.file 'assets/main.js'
|
25
25
|
|
26
|
-
context.asset_path('main', :ext => 'js').
|
26
|
+
expect(context.asset_path('main', :ext => 'js')).to eq('/assets/main.js')
|
27
27
|
Sprockets::Helpers.digest = true
|
28
|
-
context.asset_path('main', :ext => 'js').
|
28
|
+
expect(context.asset_path('main', :ext => 'js')).to match(%r(/assets/main-[0-9a-f]+.js))
|
29
29
|
Sprockets::Helpers.digest = nil
|
30
30
|
end
|
31
31
|
end
|
@@ -39,7 +39,7 @@ describe Sprockets::Helpers do
|
|
39
39
|
custom_env = Sprockets::Environment.new
|
40
40
|
custom_env.append_path 'themes'
|
41
41
|
Sprockets::Helpers.environment = custom_env
|
42
|
-
context.asset_path('main.css').
|
42
|
+
expect(context.asset_path('main.css')).to eq('/assets/main.css')
|
43
43
|
Sprockets::Helpers.environment = nil
|
44
44
|
end
|
45
45
|
end
|
@@ -53,8 +53,8 @@ describe Sprockets::Helpers do
|
|
53
53
|
c.file 'public/logo.jpg'
|
54
54
|
|
55
55
|
Sprockets::Helpers.asset_host = 'assets.example.com'
|
56
|
-
context.asset_path('main.js').
|
57
|
-
context.asset_path('logo.jpg').
|
56
|
+
expect(context.asset_path('main.js')).to eq('http://assets.example.com/assets/main.js')
|
57
|
+
expect(context.asset_path('logo.jpg')).to match(%r(http://assets.example.com/logo.jpg\?\d+))
|
58
58
|
Sprockets::Helpers.asset_host = nil
|
59
59
|
end
|
60
60
|
end
|
@@ -66,8 +66,8 @@ describe Sprockets::Helpers do
|
|
66
66
|
c.file 'public/logo.jpg'
|
67
67
|
|
68
68
|
Sprockets::Helpers.asset_host = 'assets%d.example.com'
|
69
|
-
context.asset_path('main.css').
|
70
|
-
context.asset_path('logo.jpg').
|
69
|
+
expect(context.asset_path('main.css')).to match(%r(http://assets[0-3].example.com/assets/main.css))
|
70
|
+
expect(context.asset_path('logo.jpg')).to match(%r(http://assets[0-3].example.com/logo.jpg\?\d+))
|
71
71
|
Sprockets::Helpers.asset_host = nil
|
72
72
|
end
|
73
73
|
end
|
@@ -81,8 +81,8 @@ describe Sprockets::Helpers do
|
|
81
81
|
c.file 'public/logo.jpg'
|
82
82
|
|
83
83
|
Sprockets::Helpers.asset_host = Proc.new { |source| File.basename(source, File.extname(source)) + '.assets.example.com' }
|
84
|
-
context.asset_path('main.js').
|
85
|
-
context.asset_path('logo.jpg').
|
84
|
+
expect(context.asset_path('main.js')).to eq('http://main.assets.example.com/assets/main.js')
|
85
|
+
expect(context.asset_path('logo.jpg')).to match(%r(http://logo.assets.example.com/logo.jpg\?\d+))
|
86
86
|
Sprockets::Helpers.asset_host = nil
|
87
87
|
end
|
88
88
|
end
|
@@ -94,9 +94,9 @@ describe Sprockets::Helpers do
|
|
94
94
|
within_construct do |c|
|
95
95
|
c.file 'assets/logo.jpg'
|
96
96
|
|
97
|
-
context.asset_path('logo.jpg').
|
97
|
+
expect(context.asset_path('logo.jpg')).to eq('/assets/logo.jpg')
|
98
98
|
Sprockets::Helpers.prefix = '/images'
|
99
|
-
context.asset_path('logo.jpg').
|
99
|
+
expect(context.asset_path('logo.jpg')).to eq('/images/logo.jpg')
|
100
100
|
Sprockets::Helpers.prefix = nil
|
101
101
|
end
|
102
102
|
end
|
@@ -110,8 +110,8 @@ describe Sprockets::Helpers do
|
|
110
110
|
|
111
111
|
Sprockets::Helpers.asset_host = 'assets.example.com'
|
112
112
|
Sprockets::Helpers.protocol = 'https'
|
113
|
-
context.asset_path('main.js').
|
114
|
-
context.asset_path('logo.jpg').
|
113
|
+
expect(context.asset_path('main.js')).to eq('https://assets.example.com/assets/main.js')
|
114
|
+
expect(context.asset_path('logo.jpg')).to match(%r(https://assets.example.com/logo.jpg\?\d+))
|
115
115
|
Sprockets::Helpers.asset_host = nil
|
116
116
|
Sprockets::Helpers.protocol = nil
|
117
117
|
end
|
@@ -125,8 +125,8 @@ describe Sprockets::Helpers do
|
|
125
125
|
|
126
126
|
Sprockets::Helpers.asset_host = 'assets.example.com'
|
127
127
|
Sprockets::Helpers.protocol = :relative
|
128
|
-
context.asset_path('main.js').
|
129
|
-
context.asset_path('logo.jpg').
|
128
|
+
expect(context.asset_path('main.js')).to eq('//assets.example.com/assets/main.js')
|
129
|
+
expect(context.asset_path('logo.jpg')).to match(%r(\A//assets.example.com/logo.jpg\?\d+))
|
130
130
|
Sprockets::Helpers.asset_host = nil
|
131
131
|
Sprockets::Helpers.protocol = nil
|
132
132
|
end
|
@@ -139,9 +139,9 @@ describe Sprockets::Helpers do
|
|
139
139
|
within_construct do |c|
|
140
140
|
c.file 'output/main.js'
|
141
141
|
|
142
|
-
context.asset_path('main.js').
|
142
|
+
expect(context.asset_path('main.js')).to eq('/main.js')
|
143
143
|
Sprockets::Helpers.public_path = './output'
|
144
|
-
context.asset_path('main.js').
|
144
|
+
expect(context.asset_path('main.js')).to match(%r(/main.js\?\d+))
|
145
145
|
Sprockets::Helpers.public_path = nil
|
146
146
|
end
|
147
147
|
end
|
@@ -150,31 +150,28 @@ describe Sprockets::Helpers do
|
|
150
150
|
describe '#asset_path' do
|
151
151
|
context 'with URIs' do
|
152
152
|
it 'returns URIs untouched' do
|
153
|
-
context.asset_path('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').
|
154
|
-
|
155
|
-
context.asset_path('
|
156
|
-
'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
|
157
|
-
context.asset_path('//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').should ==
|
158
|
-
'//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
|
153
|
+
expect(context.asset_path('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js')).to eq('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js')
|
154
|
+
expect(context.asset_path('http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js')).to eq('http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js')
|
155
|
+
expect(context.asset_path('//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js')).to eq('//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js')
|
159
156
|
end
|
160
157
|
end
|
161
158
|
|
162
159
|
context 'with regular files' do
|
163
160
|
it 'returns absolute paths' do
|
164
|
-
context.asset_path('/path/to/file.js').
|
165
|
-
context.asset_path('/path/to/file.jpg').
|
166
|
-
context.asset_path('/path/to/file.eot?#iefix').
|
161
|
+
expect(context.asset_path('/path/to/file.js')).to eq('/path/to/file.js')
|
162
|
+
expect(context.asset_path('/path/to/file.jpg')).to eq('/path/to/file.jpg')
|
163
|
+
expect(context.asset_path('/path/to/file.eot?#iefix')).to eq('/path/to/file.eot?#iefix')
|
167
164
|
end
|
168
165
|
|
169
166
|
it 'appends the extension for javascripts and stylesheets' do
|
170
|
-
context.asset_path('/path/to/file', :ext => 'js').
|
171
|
-
context.asset_path('/path/to/file', :ext => 'css').
|
167
|
+
expect(context.asset_path('/path/to/file', :ext => 'js')).to eq('/path/to/file.js')
|
168
|
+
expect(context.asset_path('/path/to/file', :ext => 'css')).to eq('/path/to/file.css')
|
172
169
|
end
|
173
170
|
|
174
171
|
it 'prepends a base dir' do
|
175
|
-
context.asset_path('main', :dir => 'stylesheets', :ext => 'css').
|
176
|
-
context.asset_path('main', :dir => 'javascripts', :ext => 'js').
|
177
|
-
context.asset_path('logo.jpg', :dir => 'images').
|
172
|
+
expect(context.asset_path('main', :dir => 'stylesheets', :ext => 'css')).to eq('/stylesheets/main.css')
|
173
|
+
expect(context.asset_path('main', :dir => 'javascripts', :ext => 'js')).to eq('/javascripts/main.js')
|
174
|
+
expect(context.asset_path('logo.jpg', :dir => 'images')).to eq('/images/logo.jpg')
|
178
175
|
end
|
179
176
|
|
180
177
|
it 'appends a timestamp if the file exists in the output path' do
|
@@ -184,10 +181,10 @@ describe Sprockets::Helpers do
|
|
184
181
|
c.file 'public/font.eot'
|
185
182
|
c.file 'public/font.svg'
|
186
183
|
|
187
|
-
context.asset_path('main', :ext => 'js').
|
188
|
-
context.asset_path('/favicon.ico').
|
189
|
-
context.asset_path('font.eot?#iefix').
|
190
|
-
context.asset_path('font.svg#FontName').
|
184
|
+
expect(context.asset_path('main', :ext => 'js')).to match(%r{/main.js\?\d+})
|
185
|
+
expect(context.asset_path('/favicon.ico')).to match(%r{/favicon.ico\?\d+})
|
186
|
+
expect(context.asset_path('font.eot?#iefix')).to match(%r{/font.eot\?\d+#iefix})
|
187
|
+
expect(context.asset_path('font.svg#FontName')).to match(%r{/font.svg\?\d+#FontName})
|
191
188
|
end
|
192
189
|
end
|
193
190
|
end
|
@@ -199,9 +196,9 @@ describe Sprockets::Helpers do
|
|
199
196
|
c.file 'assets/main.js'
|
200
197
|
c.file 'assets/main.css'
|
201
198
|
|
202
|
-
context.asset_path('main', :ext => 'css').
|
203
|
-
context.asset_path('main', :ext => 'js').
|
204
|
-
context.asset_path('logo.jpg').
|
199
|
+
expect(context.asset_path('main', :ext => 'css')).to eq('/assets/main.css')
|
200
|
+
expect(context.asset_path('main', :ext => 'js')).to eq('/assets/main.js')
|
201
|
+
expect(context.asset_path('logo.jpg')).to eq('/assets/logo.jpg')
|
205
202
|
end
|
206
203
|
end
|
207
204
|
|
@@ -209,8 +206,8 @@ describe Sprockets::Helpers do
|
|
209
206
|
within_construct do |c|
|
210
207
|
c.file 'assets/logo.jpg'
|
211
208
|
|
212
|
-
context.asset_path('logo.jpg').
|
213
|
-
context.asset_path('logo.jpg', :prefix => '/images').
|
209
|
+
expect(context.asset_path('logo.jpg')).to eq('/assets/logo.jpg')
|
210
|
+
expect(context.asset_path('logo.jpg', :prefix => '/images')).to eq('/images/logo.jpg')
|
214
211
|
end
|
215
212
|
end
|
216
213
|
|
@@ -220,10 +217,10 @@ describe Sprockets::Helpers do
|
|
220
217
|
c.file 'assets/font.eot'
|
221
218
|
c.file 'assets/font.svg'
|
222
219
|
|
223
|
-
context.asset_path('main', :ext => 'js').
|
224
|
-
context.asset_path('main', :ext => 'js', :digest => true).
|
225
|
-
context.asset_path('font.eot?#iefix', :digest => true).
|
226
|
-
context.asset_path('font.svg#FontName', :digest => true).
|
220
|
+
expect(context.asset_path('main', :ext => 'js')).to eq('/assets/main.js')
|
221
|
+
expect(context.asset_path('main', :ext => 'js', :digest => true)).to match(%r{/assets/main-[0-9a-f]+.js})
|
222
|
+
expect(context.asset_path('font.eot?#iefix', :digest => true)).to match(%r{/assets/font-[0-9a-f]+.eot\?#iefix})
|
223
|
+
expect(context.asset_path('font.svg#FontName', :digest => true)).to match(%r{/assets/font-[0-9a-f]+.svg#FontName})
|
227
224
|
end
|
228
225
|
end
|
229
226
|
|
@@ -233,9 +230,9 @@ describe Sprockets::Helpers do
|
|
233
230
|
c.file 'assets/font.eot'
|
234
231
|
c.file 'assets/font.svg'
|
235
232
|
|
236
|
-
context.asset_path('main', :ext => 'js', :body => true).
|
237
|
-
context.asset_path('font.eot?#iefix', :body => true).
|
238
|
-
context.asset_path('font.svg#FontName', :body => true).
|
233
|
+
expect(context.asset_path('main', :ext => 'js', :body => true)).to eq('/assets/main.js?body=1')
|
234
|
+
expect(context.asset_path('font.eot?#iefix', :body => true)).to eq('/assets/font.eot?body=1#iefix')
|
235
|
+
expect(context.asset_path('font.svg#FontName', :body => true)).to eq('/assets/font.svg?body=1#FontName')
|
239
236
|
end
|
240
237
|
end
|
241
238
|
end
|
@@ -246,7 +243,7 @@ describe Sprockets::Helpers do
|
|
246
243
|
c.file 'assets/main.js'
|
247
244
|
|
248
245
|
Sprockets::Helpers.digest = true
|
249
|
-
context.asset_path('main.js', :debug => true).
|
246
|
+
expect(context.asset_path('main.js', :debug => true)).to eq('/assets/main.js')
|
250
247
|
Sprockets::Helpers.digest = nil
|
251
248
|
end
|
252
249
|
end
|
@@ -256,7 +253,7 @@ describe Sprockets::Helpers do
|
|
256
253
|
c.file 'assets/main.js'
|
257
254
|
|
258
255
|
Sprockets::Helpers.asset_host = 'assets.example.com'
|
259
|
-
context.asset_path('main.js', :debug => true).
|
256
|
+
expect(context.asset_path('main.js', :debug => true)).to eq('/assets/main.js')
|
260
257
|
Sprockets::Helpers.asset_host = nil
|
261
258
|
end
|
262
259
|
end
|
@@ -279,7 +276,7 @@ describe Sprockets::Helpers do
|
|
279
276
|
end
|
280
277
|
|
281
278
|
asset_file.delete
|
282
|
-
context.asset_path('application.js').
|
279
|
+
expect(context.asset_path('application.js')).to match(%r(/assets/application-[0-9a-f]+.js))
|
283
280
|
|
284
281
|
Sprockets::Helpers.digest = nil
|
285
282
|
Sprockets::Helpers.prefix = nil
|
@@ -301,7 +298,7 @@ describe Sprockets::Helpers do
|
|
301
298
|
config.manifest = Sprockets::Manifest.new(env, manifest_file)
|
302
299
|
end
|
303
300
|
|
304
|
-
context.asset_path('application.js', :debug => true).
|
301
|
+
expect(context.asset_path('application.js', :debug => true)).to eq('/assets/application.js')
|
305
302
|
|
306
303
|
Sprockets::Helpers.digest = nil
|
307
304
|
Sprockets::Helpers.prefix = nil
|
@@ -315,13 +312,13 @@ describe Sprockets::Helpers do
|
|
315
312
|
describe '#javascript_path' do
|
316
313
|
context 'with regular files' do
|
317
314
|
it 'appends the js extension' do
|
318
|
-
context.javascript_path('/path/to/file').
|
319
|
-
context.javascript_path('/path/to/file.min').
|
315
|
+
expect(context.javascript_path('/path/to/file')).to eq('/path/to/file.js')
|
316
|
+
expect(context.javascript_path('/path/to/file.min')).to eq('/path/to/file.min.js')
|
320
317
|
end
|
321
318
|
|
322
319
|
it 'prepends the javascripts dir' do
|
323
|
-
context.javascript_path('main').
|
324
|
-
context.javascript_path('main.min').
|
320
|
+
expect(context.javascript_path('main')).to eq('/javascripts/main.js')
|
321
|
+
expect(context.javascript_path('main.min')).to eq('/javascripts/main.min.js')
|
325
322
|
end
|
326
323
|
end
|
327
324
|
end
|
@@ -329,13 +326,13 @@ describe Sprockets::Helpers do
|
|
329
326
|
describe '#stylesheet_path' do
|
330
327
|
context 'with regular files' do
|
331
328
|
it 'appends the css extension' do
|
332
|
-
context.stylesheet_path('/path/to/file').
|
333
|
-
context.stylesheet_path('/path/to/file.min').
|
329
|
+
expect(context.stylesheet_path('/path/to/file')).to eq('/path/to/file.css')
|
330
|
+
expect(context.stylesheet_path('/path/to/file.min')).to eq('/path/to/file.min.css')
|
334
331
|
end
|
335
332
|
|
336
333
|
it 'prepends the stylesheets dir' do
|
337
|
-
context.stylesheet_path('main').
|
338
|
-
context.stylesheet_path('main.min').
|
334
|
+
expect(context.stylesheet_path('main')).to eq('/stylesheets/main.css')
|
335
|
+
expect(context.stylesheet_path('main.min')).to eq('/stylesheets/main.min.css')
|
339
336
|
end
|
340
337
|
end
|
341
338
|
end
|
@@ -343,7 +340,7 @@ describe Sprockets::Helpers do
|
|
343
340
|
describe '#image_path' do
|
344
341
|
context 'with regular files' do
|
345
342
|
it 'prepends the images dir' do
|
346
|
-
context.image_path('logo.jpg').
|
343
|
+
expect(context.image_path('logo.jpg')).to eq('/images/logo.jpg')
|
347
344
|
end
|
348
345
|
end
|
349
346
|
end
|
@@ -351,7 +348,7 @@ describe Sprockets::Helpers do
|
|
351
348
|
describe '#font_path' do
|
352
349
|
context 'with regular files' do
|
353
350
|
it 'prepends the fonts dir' do
|
354
|
-
context.font_path('font.ttf').
|
351
|
+
expect(context.font_path('font.ttf')).to eq('/fonts/font.ttf')
|
355
352
|
end
|
356
353
|
end
|
357
354
|
end
|
@@ -359,7 +356,7 @@ describe Sprockets::Helpers do
|
|
359
356
|
describe '#video_path' do
|
360
357
|
context 'with regular files' do
|
361
358
|
it 'prepends the videos dir' do
|
362
|
-
context.video_path('video.mp4').
|
359
|
+
expect(context.video_path('video.mp4')).to eq('/videos/video.mp4')
|
363
360
|
end
|
364
361
|
end
|
365
362
|
end
|
@@ -367,7 +364,7 @@ describe Sprockets::Helpers do
|
|
367
364
|
describe '#audio_path' do
|
368
365
|
context 'with regular files' do
|
369
366
|
it 'prepends the audios dir' do
|
370
|
-
context.audio_path('audio.mp3').
|
367
|
+
expect(context.audio_path('audio.mp3')).to eq('/audios/audio.mp3')
|
371
368
|
end
|
372
369
|
end
|
373
370
|
end
|
@@ -375,7 +372,7 @@ describe Sprockets::Helpers do
|
|
375
372
|
describe '#asset_tag' do
|
376
373
|
it 'receives block to generate tag' do
|
377
374
|
actual = context.asset_tag('main.js') { |path| "<script src=#{path}></script>" }
|
378
|
-
actual.
|
375
|
+
expect(actual).to eq('<script src=/main.js></script>')
|
379
376
|
end
|
380
377
|
|
381
378
|
it 'raises when called without block' do
|
@@ -407,10 +404,10 @@ describe Sprockets::Helpers do
|
|
407
404
|
tags = context.asset_tag('main.js', :expand => true) do |path|
|
408
405
|
"<script src=\"#{path}\"></script>"
|
409
406
|
end
|
410
|
-
tags.split(
|
411
|
-
tags.
|
412
|
-
tags.
|
413
|
-
tags.
|
407
|
+
expect(tags.split('</script>')).to have(3).scripts
|
408
|
+
expect(tags).to include('<script src="/assets/main.js?body=1"></script>')
|
409
|
+
expect(tags).to include('<script src="/assets/a.js?body=1"></script>')
|
410
|
+
expect(tags).to include('<script src="/assets/b.js?body=1"></script>')
|
414
411
|
end
|
415
412
|
end
|
416
413
|
|
@@ -419,15 +416,15 @@ describe Sprockets::Helpers do
|
|
419
416
|
|
420
417
|
describe '#javascript_tag' do
|
421
418
|
it 'generates script tag' do
|
422
|
-
context.javascript_tag('/main.js').
|
419
|
+
expect(context.javascript_tag('/main.js')).to eq('<script src="/main.js"></script>')
|
423
420
|
end
|
424
421
|
|
425
422
|
it 'appends extension' do
|
426
|
-
context.javascript_tag('/main').
|
423
|
+
expect(context.javascript_tag('/main')).to eq('<script src="/main.js"></script>')
|
427
424
|
end
|
428
425
|
|
429
426
|
it 'prepends the javascript dir' do
|
430
|
-
context.javascript_tag('main').
|
427
|
+
expect(context.javascript_tag('main')).to eq('<script src="/javascripts/main.js"></script>')
|
431
428
|
end
|
432
429
|
|
433
430
|
describe 'when expanding' do
|
@@ -435,9 +432,9 @@ describe Sprockets::Helpers do
|
|
435
432
|
within_construct do |construct|
|
436
433
|
assets_layout(construct)
|
437
434
|
tags = context.javascript_tag('main.js', :expand => true)
|
438
|
-
tags.
|
439
|
-
tags.
|
440
|
-
tags.
|
435
|
+
expect(tags).to include('<script src="/assets/main.js?body=1"></script>')
|
436
|
+
expect(tags).to include('<script src="/assets/a.js?body=1"></script>')
|
437
|
+
expect(tags).to include('<script src="/assets/b.js?body=1"></script>')
|
441
438
|
end
|
442
439
|
end
|
443
440
|
end
|
@@ -445,15 +442,15 @@ describe Sprockets::Helpers do
|
|
445
442
|
|
446
443
|
describe '#stylesheet_tag' do
|
447
444
|
it 'generates stylesheet tag' do
|
448
|
-
context.stylesheet_tag('/main.css').
|
445
|
+
expect(context.stylesheet_tag('/main.css')).to eq('<link rel="stylesheet" href="/main.css">')
|
449
446
|
end
|
450
447
|
|
451
448
|
it 'appends extension' do
|
452
|
-
context.stylesheet_tag('/main').
|
449
|
+
expect(context.stylesheet_tag('/main')).to eq('<link rel="stylesheet" href="/main.css">')
|
453
450
|
end
|
454
451
|
|
455
452
|
it 'prepends the stylesheets dir' do
|
456
|
-
context.stylesheet_tag('main').
|
453
|
+
expect(context.stylesheet_tag('main')).to eq('<link rel="stylesheet" href="/stylesheets/main.css">')
|
457
454
|
end
|
458
455
|
|
459
456
|
describe 'when expanding' do
|
@@ -461,11 +458,56 @@ describe Sprockets::Helpers do
|
|
461
458
|
within_construct do |construct|
|
462
459
|
assets_layout(construct)
|
463
460
|
tags = context.stylesheet_tag('main.css', :expand => true)
|
464
|
-
tags.
|
465
|
-
tags.
|
466
|
-
tags.
|
461
|
+
expect(tags).to include('<link rel="stylesheet" href="/assets/main.css?body=1">')
|
462
|
+
expect(tags).to include('<link rel="stylesheet" href="/assets/a.css?body=1">')
|
463
|
+
expect(tags).to include('<link rel="stylesheet" href="/assets/b.css?body=1">')
|
467
464
|
end
|
468
465
|
end
|
469
466
|
end
|
470
467
|
end
|
468
|
+
|
469
|
+
describe 'Sinatra integration' do
|
470
|
+
it 'adds the helpers' do
|
471
|
+
app = Class.new(Sinatra::Base) do
|
472
|
+
register Sinatra::Sprockets::Helpers
|
473
|
+
end
|
474
|
+
|
475
|
+
expect(app).to include(Sprockets::Helpers)
|
476
|
+
end
|
477
|
+
|
478
|
+
it 'automatically configures' do
|
479
|
+
custom_env = Sprockets::Environment.new
|
480
|
+
|
481
|
+
app = Class.new(Sinatra::Base) do
|
482
|
+
set :sprockets, custom_env
|
483
|
+
set :assets_prefix, '/static'
|
484
|
+
set :digest_assets, true
|
485
|
+
|
486
|
+
register Sinatra::Sprockets::Helpers
|
487
|
+
end
|
488
|
+
|
489
|
+
expect(Sprockets::Helpers.environment).to be(custom_env)
|
490
|
+
expect(Sprockets::Helpers.prefix).to eq('/static')
|
491
|
+
expect(Sprockets::Helpers.digest).to be_true
|
492
|
+
end
|
493
|
+
|
494
|
+
it 'manually configures with configure method' do
|
495
|
+
custom_env = Sprockets::Environment.new
|
496
|
+
|
497
|
+
app = Class.new(Sinatra::Base) do
|
498
|
+
register Sinatra::Sprockets::Helpers
|
499
|
+
|
500
|
+
set :sprockets, custom_env
|
501
|
+
set :assets_prefix, '/static'
|
502
|
+
|
503
|
+
configure_sprockets_helpers do |helpers|
|
504
|
+
helpers.expand = true
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
expect(Sprockets::Helpers.environment).to be(custom_env)
|
509
|
+
expect(Sprockets::Helpers.prefix).to eq('/static')
|
510
|
+
expect(Sprockets::Helpers.expand).to be_true
|
511
|
+
end
|
512
|
+
end
|
471
513
|
end
|
data/sprockets-helpers.gemspec
CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
21
|
s.add_dependency 'sprockets', '~> 2.0'
|
22
|
-
s.add_development_dependency 'appraisal', '~> 0.
|
23
|
-
s.add_development_dependency 'rspec', '~> 2.
|
22
|
+
s.add_development_dependency 'appraisal', '~> 0.5'
|
23
|
+
s.add_development_dependency 'rspec', '~> 2.13'
|
24
24
|
s.add_development_dependency 'test-construct', '~> 1.2'
|
25
|
+
s.add_development_dependency 'sinatra', '~> 1.4'
|
25
26
|
s.add_development_dependency 'rake'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,43 +21,79 @@ dependencies:
|
|
21
21
|
version: '2.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: appraisal
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
31
36
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0.
|
37
|
+
version: '0.5'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.5'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: '2.
|
53
|
+
version: '2.13'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.13'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: test-construct
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.2'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
73
|
none: false
|
51
74
|
requirements:
|
52
75
|
- - ~>
|
53
76
|
- !ruby/object:Gem::Version
|
54
77
|
version: '1.2'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: sinatra
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.4'
|
55
86
|
type: :development
|
56
87
|
prerelease: false
|
57
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.4'
|
58
94
|
- !ruby/object:Gem::Dependency
|
59
95
|
name: rake
|
60
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
61
97
|
none: false
|
62
98
|
requirements:
|
63
99
|
- - ! '>='
|
@@ -65,7 +101,12 @@ dependencies:
|
|
65
101
|
version: '0'
|
66
102
|
type: :development
|
67
103
|
prerelease: false
|
68
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
69
110
|
description: Asset path helpers for Sprockets 2.x applications
|
70
111
|
email:
|
71
112
|
- me@petebrowne.com
|
@@ -79,13 +120,18 @@ files:
|
|
79
120
|
- LICENSE
|
80
121
|
- README.md
|
81
122
|
- Rakefile
|
82
|
-
- gemfiles/
|
83
|
-
- gemfiles/
|
84
|
-
- gemfiles/
|
85
|
-
- gemfiles/
|
86
|
-
- gemfiles/
|
87
|
-
- gemfiles/
|
88
|
-
- gemfiles/
|
123
|
+
- gemfiles/sprockets_2.0.gemfile
|
124
|
+
- gemfiles/sprockets_2.1.gemfile
|
125
|
+
- gemfiles/sprockets_2.2.gemfile
|
126
|
+
- gemfiles/sprockets_2.3.gemfile
|
127
|
+
- gemfiles/sprockets_2.4.gemfile
|
128
|
+
- gemfiles/sprockets_2.5.gemfile
|
129
|
+
- gemfiles/sprockets_2.6.gemfile
|
130
|
+
- gemfiles/sprockets_2.7.gemfile
|
131
|
+
- gemfiles/sprockets_2.8.gemfile
|
132
|
+
- gemfiles/sprockets_2.9.gemfile
|
133
|
+
- lib/sinatra/sprockets-helpers.rb
|
134
|
+
- lib/sinatra/sprockets/helpers.rb
|
89
135
|
- lib/sprockets-helpers.rb
|
90
136
|
- lib/sprockets/helpers.rb
|
91
137
|
- lib/sprockets/helpers/asset_path.rb
|
@@ -110,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
156
|
version: '0'
|
111
157
|
segments:
|
112
158
|
- 0
|
113
|
-
hash:
|
159
|
+
hash: -4510165657637312689
|
114
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
161
|
none: false
|
116
162
|
requirements:
|
@@ -119,10 +165,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
165
|
version: '0'
|
120
166
|
segments:
|
121
167
|
- 0
|
122
|
-
hash:
|
168
|
+
hash: -4510165657637312689
|
123
169
|
requirements: []
|
124
170
|
rubyforge_project: sprockets-helpers
|
125
|
-
rubygems_version: 1.8.
|
171
|
+
rubygems_version: 1.8.23
|
126
172
|
signing_key:
|
127
173
|
specification_version: 3
|
128
174
|
summary: Asset path helpers for Sprockets 2.x applications
|