sprockets-helpers 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Appraisals +16 -4
- data/Gemfile +1 -1
- data/README.md +33 -15
- data/Rakefile +3 -3
- data/gemfiles/sprockets-2.2.gemfile +7 -0
- data/gemfiles/sprockets-2.3.gemfile +7 -0
- data/gemfiles/sprockets-2.4.gemfile +7 -0
- data/lib/sprockets-helpers.rb +1 -1
- data/lib/sprockets/helpers.rb +55 -46
- data/lib/sprockets/helpers/asset_path.rb +1 -2
- data/lib/sprockets/helpers/file_path.rb +1 -1
- data/lib/sprockets/helpers/manifest_path.rb +17 -0
- data/lib/sprockets/helpers/version.rb +1 -1
- data/spec/spec_helper.rb +8 -8
- data/spec/sprockets-helpers_spec.rb +121 -95
- data/sprockets-helpers.gemspec +16 -16
- metadata +70 -97
data/Appraisals
CHANGED
@@ -1,7 +1,19 @@
|
|
1
|
-
appraise
|
2
|
-
gem
|
1
|
+
appraise 'sprockets-2.0' do
|
2
|
+
gem 'sprockets', '~> 2.0.0'
|
3
3
|
end
|
4
4
|
|
5
|
-
appraise
|
6
|
-
gem
|
5
|
+
appraise 'sprockets-2.1' do
|
6
|
+
gem 'sprockets', '~> 2.1.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'sprockets-2.2' do
|
10
|
+
gem 'sprockets', '~> 2.2.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'sprockets-2.3' do
|
14
|
+
gem 'sprockets', '~> 2.3.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise 'sprockets-2.4' do
|
18
|
+
gem 'sprockets', '~> 2.4.0'
|
7
19
|
end
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,20 +27,20 @@ Setup
|
|
27
27
|
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
28
|
|
29
29
|
``` ruby
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
30
|
+
require 'sinatra/base'
|
31
|
+
require 'sprockets'
|
32
|
+
require 'sprockets-helpers'
|
33
33
|
|
34
34
|
class App < Sinatra::Base
|
35
35
|
set :sprockets, Sprockets::Environment.new(root)
|
36
|
-
set :assets_prefix,
|
36
|
+
set :assets_prefix, '/assets'
|
37
37
|
set :digest_assets, false
|
38
38
|
|
39
39
|
configure do
|
40
40
|
# Setup Sprockets
|
41
|
-
sprockets.append_path File.join(root,
|
42
|
-
sprockets.append_path File.join(root,
|
43
|
-
sprockets.append_path File.join(root,
|
41
|
+
sprockets.append_path File.join(root, 'assets', 'stylesheets')
|
42
|
+
sprockets.append_path File.join(root, 'assets', 'javascripts')
|
43
|
+
sprockets.append_path File.join(root, 'assets', 'images')
|
44
44
|
|
45
45
|
# Configure Sprockets::Helpers (if necessary)
|
46
46
|
Sprockets::Helpers.configure do |config|
|
@@ -61,7 +61,7 @@ class App < Sinatra::Base
|
|
61
61
|
# end
|
62
62
|
end
|
63
63
|
|
64
|
-
get
|
64
|
+
get '/' do
|
65
65
|
erb :index
|
66
66
|
end
|
67
67
|
end
|
@@ -74,13 +74,13 @@ Usage in Assets
|
|
74
74
|
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
75
|
|
76
76
|
``` js+erb
|
77
|
-
var Paths = { railsImage: "<%= image_path
|
77
|
+
var Paths = { railsImage: "<%= image_path 'rails.png' %>" };
|
78
78
|
```
|
79
79
|
|
80
80
|
Would be transformed into:
|
81
81
|
|
82
82
|
``` javascript
|
83
|
-
var Paths = { railsImage:
|
83
|
+
var Paths = { railsImage: '/assets/rails.png' };
|
84
84
|
```
|
85
85
|
|
86
86
|
|
@@ -97,11 +97,11 @@ Now the following index file:
|
|
97
97
|
<head>
|
98
98
|
<meta charset="utf-8">
|
99
99
|
<title>Sinatra with Sprockets 2 (Asset Pipeline)</title>
|
100
|
-
<link rel="stylesheet" href="<%= stylesheet_path
|
101
|
-
<script src="<%= javascript_path
|
100
|
+
<link rel="stylesheet" href="<%= stylesheet_path 'application' %>">
|
101
|
+
<script src="<%= javascript_path 'application' %>"></script>
|
102
102
|
</head>
|
103
103
|
<body>
|
104
|
-
<img src="<%= image_path
|
104
|
+
<img src="<%= image_path 'rails.png' %>">
|
105
105
|
</body>
|
106
106
|
</html>
|
107
107
|
```
|
@@ -132,13 +132,31 @@ If the source is not an asset in the Sprockets environment, Sprockets::Helpers w
|
|
132
132
|
Given an image, `public/images/logo.jpg`:
|
133
133
|
|
134
134
|
``` html+erb
|
135
|
-
<img src="<%= image_path
|
135
|
+
<img src="<%= image_path 'logo.jpg' %>">
|
136
136
|
```
|
137
137
|
|
138
138
|
Would become:
|
139
139
|
|
140
140
|
``` html
|
141
|
-
<img src=
|
141
|
+
<img src='/images/logo.jpg?1320093919'>
|
142
|
+
```
|
143
|
+
|
144
|
+
|
145
|
+
Manifest Usage
|
146
|
+
--------------
|
147
|
+
|
148
|
+
**New in 0.4**: Sprockets::Helpers will use the latest fingerprinted filename directly from a `manifest.json` file:
|
149
|
+
|
150
|
+
|
151
|
+
``` ruby
|
152
|
+
# ...
|
153
|
+
Sprockets::Helpers.configure do |config|
|
154
|
+
config.environment = sprockets
|
155
|
+
config.manifest = Sprockets::Manifest.new(sprockets, 'path/to/manifset.json')
|
156
|
+
config.prefix = assets_prefix
|
157
|
+
config.public_path = public_folder
|
158
|
+
end
|
159
|
+
# ...
|
142
160
|
```
|
143
161
|
|
144
162
|
|
data/Rakefile
CHANGED
data/lib/sprockets-helpers.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'sprockets/helpers'
|
data/lib/sprockets/helpers.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'sprockets/helpers/version'
|
2
|
+
require 'sprockets'
|
3
3
|
|
4
4
|
module Sprockets
|
5
5
|
module Helpers
|
6
|
-
autoload :AssetPath,
|
7
|
-
autoload :FilePath,
|
6
|
+
autoload :AssetPath, 'sprockets/helpers/asset_path'
|
7
|
+
autoload :FilePath, 'sprockets/helpers/file_path'
|
8
|
+
autoload :ManifestPath, 'sprockets/helpers/manifest_path'
|
8
9
|
|
9
10
|
# Pattern for checking if a given path is an external URI.
|
10
11
|
URI_MATCH = %r(^[-a-z]+://|^cid:|^//)
|
@@ -16,19 +17,22 @@ module Sprockets
|
|
16
17
|
# Set the Sprockets environment to search for assets.
|
17
18
|
# This defaults to the context's #environment method.
|
18
19
|
attr_accessor :environment
|
19
|
-
|
20
|
+
|
21
|
+
# The manifest file used for lookup
|
22
|
+
attr_accessor :manifest
|
23
|
+
|
20
24
|
# The base URL the Sprocket environment is mapped to.
|
21
|
-
# This defaults to
|
25
|
+
# This defaults to '/assets'.
|
22
26
|
def prefix
|
23
|
-
@prefix ||=
|
27
|
+
@prefix ||= '/assets'
|
24
28
|
end
|
25
29
|
attr_writer :prefix
|
26
30
|
|
27
31
|
# The path to the public directory, where the assets
|
28
32
|
# not managed by Sprockets will be located.
|
29
|
-
# Defaults to
|
33
|
+
# Defaults to './public'
|
30
34
|
def public_path
|
31
|
-
@public_path ||=
|
35
|
+
@public_path ||= './public'
|
32
36
|
end
|
33
37
|
attr_writer :public_path
|
34
38
|
|
@@ -53,19 +57,19 @@ module Sprockets
|
|
53
57
|
#
|
54
58
|
# For files within Sprockets:
|
55
59
|
#
|
56
|
-
# asset_path
|
57
|
-
# asset_path
|
58
|
-
# asset_path
|
59
|
-
# asset_path
|
60
|
+
# asset_path 'xmlhr.js' # => '/assets/xmlhr.js'
|
61
|
+
# asset_path 'xmlhr', :ext => 'js' # => '/assets/xmlhr.js'
|
62
|
+
# asset_path 'xmlhr.js', :digest => true # => '/assets/xmlhr-27a8f1f96afd8d4c67a59eb9447f45bd.js'
|
63
|
+
# asset_path 'xmlhr.js', :prefix => '/themes' # => '/themes/xmlhr.js'
|
60
64
|
#
|
61
65
|
# For files outside of Sprockets:
|
62
66
|
#
|
63
|
-
# asset_path
|
64
|
-
# asset_path
|
65
|
-
# asset_path
|
66
|
-
# asset_path
|
67
|
-
# asset_path
|
68
|
-
# asset_path
|
67
|
+
# asset_path 'xmlhr' # => '/xmlhr'
|
68
|
+
# asset_path 'xmlhr', :ext => 'js' # => '/xmlhr.js'
|
69
|
+
# asset_path 'dir/xmlhr.js', :dir => 'javascripts' # => '/javascripts/dir/xmlhr.js'
|
70
|
+
# asset_path '/dir/xmlhr.js', :dir => 'javascripts' # => '/dir/xmlhr.js'
|
71
|
+
# asset_path 'http://www.example.com/js/xmlhr' # => 'http://www.example.com/js/xmlhr'
|
72
|
+
# asset_path 'http://www.example.com/js/xmlhr.js' # => 'http://www.example.com/js/xmlhr.js'
|
69
73
|
#
|
70
74
|
def asset_path(source, options = {})
|
71
75
|
return source if source =~ URI_MATCH
|
@@ -75,6 +79,11 @@ module Sprockets
|
|
75
79
|
source << ".#{options[:ext]}"
|
76
80
|
end
|
77
81
|
|
82
|
+
# If a manifest is present, try to grab the path from the manifest first
|
83
|
+
if Helpers.manifest && Helpers.manifest.assets[source]
|
84
|
+
return ManifestPath.new(Helpers.manifest.assets[source], options).to_s
|
85
|
+
end
|
86
|
+
|
78
87
|
# If the source points to an asset in the Sprockets
|
79
88
|
# environment use AssetPath to generate the full path.
|
80
89
|
assets_environment.resolve(source) do |path|
|
@@ -94,20 +103,20 @@ module Sprockets
|
|
94
103
|
#
|
95
104
|
# For files within Sprockets:
|
96
105
|
#
|
97
|
-
# javascript_path
|
98
|
-
# javascript_path
|
99
|
-
# javascript_path
|
106
|
+
# javascript_path 'xmlhr' # => '/assets/xmlhr.js'
|
107
|
+
# javascript_path 'dir/xmlhr.js' # => '/assets/dir/xmlhr.js'
|
108
|
+
# javascript_path '/dir/xmlhr' # => '/assets/dir/xmlhr.js'
|
100
109
|
#
|
101
110
|
# For files outside of Sprockets:
|
102
111
|
#
|
103
|
-
# javascript_path
|
104
|
-
# javascript_path
|
105
|
-
# javascript_path
|
106
|
-
# javascript_path
|
107
|
-
# javascript_path
|
112
|
+
# javascript_path 'xmlhr' # => '/javascripts/xmlhr.js'
|
113
|
+
# javascript_path 'dir/xmlhr.js' # => '/javascripts/dir/xmlhr.js'
|
114
|
+
# javascript_path '/dir/xmlhr' # => '/dir/xmlhr.js'
|
115
|
+
# javascript_path 'http://www.example.com/js/xmlhr' # => 'http://www.example.com/js/xmlhr'
|
116
|
+
# javascript_path 'http://www.example.com/js/xmlhr.js' # => 'http://www.example.com/js/xmlhr.js'
|
108
117
|
#
|
109
118
|
def javascript_path(source, options = {})
|
110
|
-
asset_path source, { :dir =>
|
119
|
+
asset_path source, { :dir => 'javascripts', :ext => 'js' }.merge(options)
|
111
120
|
end
|
112
121
|
alias_method :path_to_javascript, :javascript_path
|
113
122
|
|
@@ -119,20 +128,20 @@ module Sprockets
|
|
119
128
|
#
|
120
129
|
# For files within Sprockets:
|
121
130
|
#
|
122
|
-
# stylesheet_path
|
123
|
-
# stylesheet_path
|
124
|
-
# stylesheet_path
|
131
|
+
# stylesheet_path 'style' # => '/assets/style.css'
|
132
|
+
# stylesheet_path 'dir/style.css' # => '/assets/dir/style.css'
|
133
|
+
# stylesheet_path '/dir/style.css' # => '/assets/dir/style.css'
|
125
134
|
#
|
126
135
|
# For files outside of Sprockets:
|
127
136
|
#
|
128
|
-
# stylesheet_path
|
129
|
-
# stylesheet_path
|
130
|
-
# stylesheet_path
|
131
|
-
# stylesheet_path
|
132
|
-
# stylesheet_path
|
137
|
+
# stylesheet_path 'style' # => '/stylesheets/style.css'
|
138
|
+
# stylesheet_path 'dir/style.css' # => '/stylesheets/dir/style.css'
|
139
|
+
# stylesheet_path '/dir/style.css' # => '/dir/style.css'
|
140
|
+
# stylesheet_path 'http://www.example.com/css/style' # => 'http://www.example.com/css/style'
|
141
|
+
# stylesheet_path 'http://www.example.com/css/style.css' # => 'http://www.example.com/css/style.css'
|
133
142
|
#
|
134
143
|
def stylesheet_path(source, options = {})
|
135
|
-
asset_path source, { :dir =>
|
144
|
+
asset_path source, { :dir => 'stylesheets', :ext => 'css' }.merge(options)
|
136
145
|
end
|
137
146
|
alias_method :path_to_stylesheet, :stylesheet_path
|
138
147
|
|
@@ -143,20 +152,20 @@ module Sprockets
|
|
143
152
|
#
|
144
153
|
# With files within Sprockets:
|
145
154
|
#
|
146
|
-
# image_path
|
147
|
-
# image_path
|
148
|
-
# image_path
|
155
|
+
# image_path 'edit.png' # => '/assets/edit.png'
|
156
|
+
# image_path 'icons/edit.png' # => '/assets/icons/edit.png'
|
157
|
+
# image_path '/icons/edit.png' # => '/assets/icons/edit.png'
|
149
158
|
#
|
150
159
|
# With files outside of Sprockets:
|
151
160
|
#
|
152
|
-
# image_path
|
153
|
-
# image_path
|
154
|
-
# image_path
|
155
|
-
# image_path
|
156
|
-
# image_path
|
161
|
+
# image_path 'edit' # => '/images/edit'
|
162
|
+
# image_path 'edit.png' # => '/images/edit.png'
|
163
|
+
# image_path 'icons/edit.png' # => '/images/icons/edit.png'
|
164
|
+
# image_path '/icons/edit.png' # => '/icons/edit.png'
|
165
|
+
# image_path 'http://www.example.com/img/edit.png' # => 'http://www.example.com/img/edit.png'
|
157
166
|
#
|
158
167
|
def image_path(source, options = {})
|
159
|
-
asset_path source, { :dir =>
|
168
|
+
asset_path source, { :dir => 'images' }.merge(options)
|
160
169
|
end
|
161
170
|
alias_method :path_to_image, :image_path
|
162
171
|
|
@@ -16,8 +16,7 @@ module Sprockets
|
|
16
16
|
|
17
17
|
protected
|
18
18
|
|
19
|
-
# Prepends the
|
20
|
-
# already an absolute path.
|
19
|
+
# Prepends the assets prefix
|
21
20
|
def rewrite_base_path(path) # :nodoc:
|
22
21
|
prefix = if options[:prefix].respond_to? :call
|
23
22
|
options[:prefix].call path
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Helpers
|
3
|
+
# `ManifestPath` uses the digest path and
|
4
|
+
# prepends the prefix.
|
5
|
+
class ManifestPath < AssetPath
|
6
|
+
#
|
7
|
+
def initialize(path, options = {})
|
8
|
+
@options = {
|
9
|
+
:body => false,
|
10
|
+
:prefix => Helpers.prefix
|
11
|
+
}.merge options
|
12
|
+
|
13
|
+
@source = path.to_s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'sprockets'
|
2
|
+
require 'sprockets-helpers'
|
3
|
+
require 'construct'
|
4
|
+
require 'pathname'
|
5
5
|
|
6
6
|
# Requires supporting files with custom matchers and macros, etc,
|
7
7
|
# in ./support/ and its subdirectories.
|
@@ -11,16 +11,16 @@ RSpec.configure do |config|
|
|
11
11
|
config.include Construct::Helpers
|
12
12
|
|
13
13
|
# Returns a Sprockets environment. Automatically
|
14
|
-
# appends the
|
14
|
+
# appends the 'assets' path if available.
|
15
15
|
def env
|
16
16
|
@env ||= Sprockets::Environment.new.tap do |env|
|
17
|
-
env.append_path
|
17
|
+
env.append_path 'assets' if File.directory?('assets')
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
# Returns a fresh context, that can be used to test helpers.
|
22
|
-
def context(logical_path =
|
23
|
-
pathname ||= Pathname.new(File.join(
|
22
|
+
def context(logical_path = 'application.js', pathname = nil)
|
23
|
+
pathname ||= Pathname.new(File.join('assets', logical_path)).expand_path
|
24
24
|
env.context_class.new env, logical_path, pathname
|
25
25
|
end
|
26
26
|
end
|
@@ -1,199 +1,225 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Sprockets::Helpers do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '.configure' do
|
5
|
+
it 'sets global configuration' do
|
6
6
|
within_construct do |c|
|
7
|
-
c.file
|
7
|
+
c.file 'assets/main.css'
|
8
8
|
|
9
|
-
context.asset_path(
|
9
|
+
context.asset_path('main.css').should == '/assets/main.css'
|
10
10
|
Sprockets::Helpers.configure do |config|
|
11
11
|
config.digest = true
|
12
|
-
config.prefix =
|
12
|
+
config.prefix = '/themes'
|
13
13
|
end
|
14
|
-
context.asset_path(
|
14
|
+
context.asset_path('main.css').should =~ %r(/themes/main-[0-9a-f]+.css)
|
15
15
|
Sprockets::Helpers.digest = nil
|
16
16
|
Sprockets::Helpers.prefix = nil
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
21
|
+
describe '.digest' do
|
22
|
+
it 'globally configures digest paths' do
|
23
23
|
within_construct do |c|
|
24
|
-
c.file
|
24
|
+
c.file 'assets/main.js'
|
25
25
|
|
26
|
-
context.asset_path(
|
26
|
+
context.asset_path('main', :ext => 'js').should == '/assets/main.js'
|
27
27
|
Sprockets::Helpers.digest = true
|
28
|
-
context.asset_path(
|
28
|
+
context.asset_path('main', :ext => 'js').should =~ %r(/assets/main-[0-9a-f]+.js)
|
29
29
|
Sprockets::Helpers.digest = nil
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
it
|
34
|
+
describe '.environment' do
|
35
|
+
it 'sets a custom assets environment' do
|
36
36
|
within_construct do |c|
|
37
|
-
c.file
|
37
|
+
c.file 'themes/main.css'
|
38
38
|
|
39
39
|
custom_env = Sprockets::Environment.new
|
40
|
-
custom_env.append_path
|
40
|
+
custom_env.append_path 'themes'
|
41
41
|
Sprockets::Helpers.environment = custom_env
|
42
|
-
context.asset_path(
|
42
|
+
context.asset_path('main.css').should == '/assets/main.css'
|
43
43
|
Sprockets::Helpers.environment = nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
49
|
-
context
|
50
|
-
it
|
48
|
+
describe '.prefix' do
|
49
|
+
context 'that is a string' do
|
50
|
+
it 'sets a custom assets prefix' do
|
51
51
|
within_construct do |c|
|
52
|
-
c.file
|
52
|
+
c.file 'assets/logo.jpg'
|
53
53
|
|
54
|
-
context.asset_path(
|
55
|
-
Sprockets::Helpers.prefix =
|
56
|
-
context.asset_path(
|
54
|
+
context.asset_path('logo.jpg').should == '/assets/logo.jpg'
|
55
|
+
Sprockets::Helpers.prefix = '/images'
|
56
|
+
context.asset_path('logo.jpg').should == '/images/logo.jpg'
|
57
57
|
Sprockets::Helpers.prefix = nil
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
context
|
63
|
-
it
|
62
|
+
context 'that is a proc' do
|
63
|
+
it 'sets a custom assets prefix' do
|
64
64
|
within_construct do |c|
|
65
|
-
c.file
|
65
|
+
c.file 'assets/logo.jpg'
|
66
66
|
|
67
67
|
Sprockets::Helpers.prefix = Proc.new { |source| "http://example.com/#{File.basename(source, '.jpg')}" }
|
68
|
-
context.asset_path(
|
68
|
+
context.asset_path('logo.jpg').should == 'http://example.com/logo/logo.jpg'
|
69
69
|
Sprockets::Helpers.prefix = nil
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe
|
76
|
-
it
|
75
|
+
describe '.public_path' do
|
76
|
+
it 'sets a custom location for the public path' do
|
77
77
|
within_construct do |c|
|
78
|
-
c.file
|
78
|
+
c.file 'output/main.js'
|
79
79
|
|
80
|
-
context.asset_path(
|
81
|
-
Sprockets::Helpers.public_path =
|
82
|
-
context.asset_path(
|
80
|
+
context.asset_path('main.js').should == '/main.js'
|
81
|
+
Sprockets::Helpers.public_path = './output'
|
82
|
+
context.asset_path('main.js').should =~ %r(/main.js\?\d+)
|
83
83
|
Sprockets::Helpers.public_path = nil
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
88
|
-
describe
|
89
|
-
context
|
90
|
-
it
|
91
|
-
context.asset_path(
|
92
|
-
|
93
|
-
context.asset_path(
|
94
|
-
|
95
|
-
context.asset_path(
|
96
|
-
|
87
|
+
|
88
|
+
describe '#asset_path' do
|
89
|
+
context 'with URIs' do
|
90
|
+
it 'returns URIs untouched' do
|
91
|
+
context.asset_path('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').should ==
|
92
|
+
'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
|
93
|
+
context.asset_path('http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').should ==
|
94
|
+
'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
|
95
|
+
context.asset_path('//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').should ==
|
96
|
+
'//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
context
|
101
|
-
it
|
102
|
-
context.asset_path(
|
103
|
-
context.asset_path(
|
100
|
+
context 'with regular files' do
|
101
|
+
it 'returns absolute paths' do
|
102
|
+
context.asset_path('/path/to/file.js').should == '/path/to/file.js'
|
103
|
+
context.asset_path('/path/to/file.jpg').should == '/path/to/file.jpg'
|
104
104
|
end
|
105
105
|
|
106
|
-
it
|
107
|
-
context.asset_path(
|
108
|
-
context.asset_path(
|
106
|
+
it 'appends the extension for javascripts and stylesheets' do
|
107
|
+
context.asset_path('/path/to/file', :ext => 'js').should == '/path/to/file.js'
|
108
|
+
context.asset_path('/path/to/file', :ext => 'css').should == '/path/to/file.css'
|
109
109
|
end
|
110
110
|
|
111
|
-
it
|
112
|
-
context.asset_path(
|
113
|
-
context.asset_path(
|
114
|
-
context.asset_path(
|
111
|
+
it 'prepends a base dir' do
|
112
|
+
context.asset_path('main', :dir => 'stylesheets', :ext => 'css').should == '/stylesheets/main.css'
|
113
|
+
context.asset_path('main', :dir => 'javascripts', :ext => 'js').should == '/javascripts/main.js'
|
114
|
+
context.asset_path('logo.jpg', :dir => 'images').should == '/images/logo.jpg'
|
115
115
|
end
|
116
116
|
|
117
|
-
it
|
117
|
+
it 'appends a timestamp if the file exists in the output path' do
|
118
118
|
within_construct do |c|
|
119
|
-
c.file
|
120
|
-
c.file
|
119
|
+
c.file 'public/main.js'
|
120
|
+
c.file 'public/favicon.ico'
|
121
121
|
|
122
|
-
context.asset_path(
|
123
|
-
context.asset_path(
|
122
|
+
context.asset_path('main', :ext => 'js').should =~ %r(/main.js\?\d+)
|
123
|
+
context.asset_path('/favicon.ico').should =~ %r(/favicon.ico\?\d+)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
context
|
129
|
-
it
|
128
|
+
context 'with assets' do
|
129
|
+
it 'returns URLs to the assets' do
|
130
130
|
within_construct do |c|
|
131
|
-
c.file
|
132
|
-
c.file
|
133
|
-
c.file
|
131
|
+
c.file 'assets/logo.jpg'
|
132
|
+
c.file 'assets/main.js'
|
133
|
+
c.file 'assets/main.css'
|
134
134
|
|
135
|
-
context.asset_path(
|
136
|
-
context.asset_path(
|
137
|
-
context.asset_path(
|
135
|
+
context.asset_path('main', :ext => 'css').should == '/assets/main.css'
|
136
|
+
context.asset_path('main', :ext => 'js').should == '/assets/main.js'
|
137
|
+
context.asset_path('logo.jpg').should == '/assets/logo.jpg'
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
141
|
+
it 'prepends the assets prefix' do
|
142
142
|
within_construct do |c|
|
143
|
-
c.file
|
143
|
+
c.file 'assets/logo.jpg'
|
144
144
|
|
145
|
-
context.asset_path(
|
146
|
-
context.asset_path(
|
145
|
+
context.asset_path('logo.jpg').should == '/assets/logo.jpg'
|
146
|
+
context.asset_path('logo.jpg', :prefix => '/images').should == '/images/logo.jpg'
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
-
it
|
150
|
+
it 'uses the digest path if configured' do
|
151
151
|
within_construct do |c|
|
152
|
-
c.file
|
152
|
+
c.file 'assets/main.js'
|
153
153
|
|
154
|
-
context.asset_path(
|
155
|
-
context.asset_path(
|
154
|
+
context.asset_path('main', :ext => 'js').should == '/assets/main.js'
|
155
|
+
context.asset_path('main', :ext => 'js', :digest => true).should =~ %r(/assets/main-[0-9a-f]+.js)
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
it
|
159
|
+
it 'returns a body parameter' do
|
160
160
|
within_construct do |c|
|
161
|
-
c.file
|
161
|
+
c.file 'assets/main.js'
|
162
162
|
|
163
|
-
context.asset_path(
|
163
|
+
context.asset_path('main', :ext => 'js', :body => true).should == '/assets/main.js?body=1'
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
if defined?(::Sprockets::Manifest)
|
169
|
+
context 'with a manifest' do
|
170
|
+
it 'reads path from a manifest file' do
|
171
|
+
within_construct do |c|
|
172
|
+
asset_file = c.file 'assets/application.js'
|
173
|
+
manifest_file = c.join 'manifest.json'
|
174
|
+
|
175
|
+
manifest = Sprockets::Manifest.new(env, manifest_file)
|
176
|
+
manifest.compile 'application.js'
|
177
|
+
|
178
|
+
Sprockets::Helpers.configure do |config|
|
179
|
+
config.digest = true
|
180
|
+
config.prefix = '/assets'
|
181
|
+
config.manifest = Sprockets::Manifest.new(env, manifest_file)
|
182
|
+
end
|
183
|
+
|
184
|
+
asset_file.delete
|
185
|
+
context.asset_path('application.js').should =~ %r(/assets/application-[0-9a-f]+.js)
|
186
|
+
|
187
|
+
Sprockets::Helpers.digest = nil
|
188
|
+
Sprockets::Helpers.prefix = nil
|
189
|
+
end
|
164
190
|
end
|
165
191
|
end
|
166
192
|
end
|
167
193
|
end
|
168
194
|
|
169
|
-
describe
|
170
|
-
context
|
171
|
-
it
|
172
|
-
context.javascript_path(
|
195
|
+
describe '#javascript_path' do
|
196
|
+
context 'with regular files' do
|
197
|
+
it 'appends the js extension' do
|
198
|
+
context.javascript_path('/path/to/file').should == '/path/to/file.js'
|
173
199
|
end
|
174
200
|
|
175
|
-
it
|
176
|
-
context.javascript_path(
|
201
|
+
it 'prepends the javascripts dir' do
|
202
|
+
context.javascript_path('main').should == '/javascripts/main.js'
|
177
203
|
end
|
178
204
|
end
|
179
205
|
end
|
180
206
|
|
181
|
-
describe
|
182
|
-
context
|
183
|
-
it
|
184
|
-
context.stylesheet_path(
|
207
|
+
describe '#stylesheet_path' do
|
208
|
+
context 'with regular files' do
|
209
|
+
it 'appends the css extension' do
|
210
|
+
context.stylesheet_path('/path/to/file').should == '/path/to/file.css'
|
185
211
|
end
|
186
212
|
|
187
|
-
it
|
188
|
-
context.stylesheet_path(
|
213
|
+
it 'prepends the stylesheets dir' do
|
214
|
+
context.stylesheet_path('main').should == '/stylesheets/main.css'
|
189
215
|
end
|
190
216
|
end
|
191
217
|
end
|
192
218
|
|
193
|
-
describe
|
194
|
-
context
|
195
|
-
it
|
196
|
-
context.image_path(
|
219
|
+
describe '#image_path' do
|
220
|
+
context 'with regular files' do
|
221
|
+
it 'prepends the images dir' do
|
222
|
+
context.image_path('logo.jpg').should == '/images/logo.jpg'
|
197
223
|
end
|
198
224
|
end
|
199
225
|
end
|
data/sprockets-helpers.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'sprockets/helpers/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
6
|
+
s.name = 'sprockets-helpers'
|
7
7
|
s.version = Sprockets::Helpers::VERSION
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
8
|
+
s.authors = ['Pete Browne']
|
9
|
+
s.email = ['me@petebrowne.com']
|
10
|
+
s.homepage = 'https://github.com/petebrowne/sprockets-helpers'
|
11
|
+
s.summary = 'Asset path helpers for Sprockets 2.x applications'
|
12
|
+
s.description = 'Asset path helpers for Sprockets 2.x applications'
|
13
13
|
|
14
|
-
s.rubyforge_project =
|
14
|
+
s.rubyforge_project = 'sprockets-helpers'
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split(
|
19
|
-
s.require_paths = [
|
18
|
+
s.executables = `git ls-files -- bin/*`.split('\n').map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
s.add_dependency
|
22
|
-
s.add_development_dependency
|
23
|
-
s.add_development_dependency
|
24
|
-
s.add_development_dependency
|
25
|
-
s.add_development_dependency
|
21
|
+
s.add_dependency 'sprockets', '~> 2.0'
|
22
|
+
s.add_development_dependency 'appraisal', '~> 0.4'
|
23
|
+
s.add_development_dependency 'rspec', '~> 2.6'
|
24
|
+
s.add_development_dependency 'test-construct', '~> 1.2'
|
25
|
+
s.add_development_dependency 'rake'
|
26
26
|
end
|
metadata
CHANGED
@@ -1,106 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-helpers
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 0.3.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Pete Browne
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
type: :runtime
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 2
|
30
|
-
- 0
|
31
|
-
version: "2.0"
|
32
|
-
prerelease: false
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
33
15
|
name: sprockets
|
34
|
-
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
type: :development
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70151392212820 !ruby/object:Gem::Requirement
|
38
17
|
none: false
|
39
|
-
requirements:
|
18
|
+
requirements:
|
40
19
|
- - ~>
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
|
44
|
-
- 0
|
45
|
-
- 4
|
46
|
-
version: "0.4"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
22
|
+
type: :runtime
|
47
23
|
prerelease: false
|
24
|
+
version_requirements: *70151392212820
|
25
|
+
- !ruby/object:Gem::Dependency
|
48
26
|
name: appraisal
|
49
|
-
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
type: :development
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70151392211980 !ruby/object:Gem::Requirement
|
53
28
|
none: false
|
54
|
-
requirements:
|
29
|
+
requirements:
|
55
30
|
- - ~>
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
- 2
|
60
|
-
- 6
|
61
|
-
version: "2.6"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.4'
|
33
|
+
type: :development
|
62
34
|
prerelease: false
|
35
|
+
version_requirements: *70151392211980
|
36
|
+
- !ruby/object:Gem::Dependency
|
63
37
|
name: rspec
|
64
|
-
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
type: :development
|
67
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70151392210640 !ruby/object:Gem::Requirement
|
68
39
|
none: false
|
69
|
-
requirements:
|
40
|
+
requirements:
|
70
41
|
- - ~>
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
|
74
|
-
- 1
|
75
|
-
- 2
|
76
|
-
version: "1.2"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.6'
|
44
|
+
type: :development
|
77
45
|
prerelease: false
|
46
|
+
version_requirements: *70151392210640
|
47
|
+
- !ruby/object:Gem::Dependency
|
78
48
|
name: test-construct
|
79
|
-
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
type: :development
|
82
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70151392209760 !ruby/object:Gem::Requirement
|
83
50
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
89
|
-
- 0
|
90
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
type: :development
|
91
56
|
prerelease: false
|
57
|
+
version_requirements: *70151392209760
|
58
|
+
- !ruby/object:Gem::Dependency
|
92
59
|
name: rake
|
93
|
-
|
94
|
-
|
95
|
-
|
60
|
+
requirement: &70151392208960 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70151392208960
|
69
|
+
description: Asset path helpers for Sprockets 2.x applications
|
70
|
+
email:
|
96
71
|
- me@petebrowne.com
|
97
72
|
executables: []
|
98
|
-
|
99
73
|
extensions: []
|
100
|
-
|
101
74
|
extra_rdoc_files: []
|
102
|
-
|
103
|
-
files:
|
75
|
+
files:
|
104
76
|
- .gitignore
|
105
77
|
- Appraisals
|
106
78
|
- Gemfile
|
@@ -109,47 +81,48 @@ files:
|
|
109
81
|
- Rakefile
|
110
82
|
- gemfiles/sprockets-2.0.gemfile
|
111
83
|
- gemfiles/sprockets-2.1.gemfile
|
84
|
+
- gemfiles/sprockets-2.2.gemfile
|
85
|
+
- gemfiles/sprockets-2.3.gemfile
|
86
|
+
- gemfiles/sprockets-2.4.gemfile
|
112
87
|
- lib/sprockets-helpers.rb
|
113
88
|
- lib/sprockets/helpers.rb
|
114
89
|
- lib/sprockets/helpers/asset_path.rb
|
115
90
|
- lib/sprockets/helpers/file_path.rb
|
91
|
+
- lib/sprockets/helpers/manifest_path.rb
|
116
92
|
- lib/sprockets/helpers/version.rb
|
117
93
|
- spec/spec_helper.rb
|
118
94
|
- spec/sprockets-helpers_spec.rb
|
119
95
|
- sprockets-helpers.gemspec
|
120
|
-
homepage: https://github.com/petebrowne/sprockets-
|
96
|
+
homepage: https://github.com/petebrowne/sprockets-helpers
|
121
97
|
licenses: []
|
122
|
-
|
123
98
|
post_install_message:
|
124
99
|
rdoc_options: []
|
125
|
-
|
126
|
-
require_paths:
|
100
|
+
require_paths:
|
127
101
|
- lib
|
128
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
103
|
none: false
|
130
|
-
requirements:
|
131
|
-
- -
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
|
134
|
-
segments:
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
135
109
|
- 0
|
136
|
-
|
137
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
hash: -2985089145650135547
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
112
|
none: false
|
139
|
-
requirements:
|
140
|
-
- -
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
|
143
|
-
segments:
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
segments:
|
144
118
|
- 0
|
145
|
-
|
119
|
+
hash: -2985089145650135547
|
146
120
|
requirements: []
|
147
|
-
|
148
121
|
rubyforge_project: sprockets-helpers
|
149
122
|
rubygems_version: 1.8.11
|
150
123
|
signing_key:
|
151
124
|
specification_version: 3
|
152
|
-
summary: Asset path helpers for Sprockets 2.
|
153
|
-
test_files:
|
125
|
+
summary: Asset path helpers for Sprockets 2.x applications
|
126
|
+
test_files:
|
154
127
|
- spec/spec_helper.rb
|
155
128
|
- spec/sprockets-helpers_spec.rb
|