sprockets 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprockets might be problematic. Click here for more details.

Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +2 -2
  3. data/README.md +332 -115
  4. data/bin/sprockets +8 -0
  5. data/lib/rake/sprocketstask.rb +25 -13
  6. data/lib/sprockets/asset.rb +143 -205
  7. data/lib/sprockets/autoload/closure.rb +7 -0
  8. data/lib/sprockets/autoload/coffee_script.rb +7 -0
  9. data/lib/sprockets/autoload/eco.rb +7 -0
  10. data/lib/sprockets/autoload/ejs.rb +7 -0
  11. data/lib/sprockets/autoload/sass.rb +7 -0
  12. data/lib/sprockets/autoload/uglifier.rb +7 -0
  13. data/lib/sprockets/autoload/yui.rb +7 -0
  14. data/lib/sprockets/autoload.rb +11 -0
  15. data/lib/sprockets/base.rb +49 -257
  16. data/lib/sprockets/bower.rb +58 -0
  17. data/lib/sprockets/bundle.rb +65 -0
  18. data/lib/sprockets/cache/file_store.rb +165 -14
  19. data/lib/sprockets/cache/memory_store.rb +66 -0
  20. data/lib/sprockets/cache/null_store.rb +46 -0
  21. data/lib/sprockets/cache.rb +234 -0
  22. data/lib/sprockets/cached_environment.rb +69 -0
  23. data/lib/sprockets/closure_compressor.rb +53 -0
  24. data/lib/sprockets/coffee_script_processor.rb +25 -0
  25. data/lib/sprockets/coffee_script_template.rb +6 -0
  26. data/lib/sprockets/compressing.rb +74 -0
  27. data/lib/sprockets/configuration.rb +83 -0
  28. data/lib/sprockets/context.rb +125 -131
  29. data/lib/sprockets/dependencies.rb +73 -0
  30. data/lib/sprockets/digest_utils.rb +156 -0
  31. data/lib/sprockets/directive_processor.rb +209 -211
  32. data/lib/sprockets/eco_processor.rb +32 -0
  33. data/lib/sprockets/eco_template.rb +3 -35
  34. data/lib/sprockets/ejs_processor.rb +31 -0
  35. data/lib/sprockets/ejs_template.rb +3 -34
  36. data/lib/sprockets/encoding_utils.rb +258 -0
  37. data/lib/sprockets/engines.rb +45 -38
  38. data/lib/sprockets/environment.rb +17 -67
  39. data/lib/sprockets/erb_processor.rb +30 -0
  40. data/lib/sprockets/erb_template.rb +6 -0
  41. data/lib/sprockets/errors.rb +6 -13
  42. data/lib/sprockets/file_reader.rb +15 -0
  43. data/lib/sprockets/http_utils.rb +115 -0
  44. data/lib/sprockets/jst_processor.rb +35 -19
  45. data/lib/sprockets/legacy.rb +314 -0
  46. data/lib/sprockets/legacy_proc_processor.rb +35 -0
  47. data/lib/sprockets/legacy_tilt_processor.rb +29 -0
  48. data/lib/sprockets/loader.rb +176 -0
  49. data/lib/sprockets/manifest.rb +179 -98
  50. data/lib/sprockets/manifest_utils.rb +45 -0
  51. data/lib/sprockets/mime.rb +114 -32
  52. data/lib/sprockets/path_dependency_utils.rb +85 -0
  53. data/lib/sprockets/path_digest_utils.rb +47 -0
  54. data/lib/sprockets/path_utils.rb +282 -0
  55. data/lib/sprockets/paths.rb +81 -0
  56. data/lib/sprockets/processing.rb +157 -189
  57. data/lib/sprockets/processor_utils.rb +103 -0
  58. data/lib/sprockets/resolve.rb +208 -0
  59. data/lib/sprockets/sass_cache_store.rb +19 -15
  60. data/lib/sprockets/sass_compressor.rb +59 -0
  61. data/lib/sprockets/sass_functions.rb +2 -0
  62. data/lib/sprockets/sass_importer.rb +2 -29
  63. data/lib/sprockets/sass_processor.rb +285 -0
  64. data/lib/sprockets/sass_template.rb +4 -44
  65. data/lib/sprockets/server.rb +109 -84
  66. data/lib/sprockets/transformers.rb +145 -0
  67. data/lib/sprockets/uglifier_compressor.rb +63 -0
  68. data/lib/sprockets/uri_utils.rb +190 -0
  69. data/lib/sprockets/utils.rb +193 -44
  70. data/lib/sprockets/version.rb +1 -1
  71. data/lib/sprockets/yui_compressor.rb +65 -0
  72. data/lib/sprockets.rb +144 -53
  73. metadata +248 -238
  74. data/lib/sprockets/asset_attributes.rb +0 -126
  75. data/lib/sprockets/bundled_asset.rb +0 -79
  76. data/lib/sprockets/caching.rb +0 -96
  77. data/lib/sprockets/charset_normalizer.rb +0 -41
  78. data/lib/sprockets/index.rb +0 -99
  79. data/lib/sprockets/processed_asset.rb +0 -152
  80. data/lib/sprockets/processor.rb +0 -32
  81. data/lib/sprockets/safety_colons.rb +0 -28
  82. data/lib/sprockets/scss_template.rb +0 -13
  83. data/lib/sprockets/static_asset.rb +0 -57
  84. data/lib/sprockets/trail.rb +0 -90
metadata CHANGED
@@ -1,305 +1,315 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
6
- segments:
7
- - 2
8
- - 3
9
- - 2
10
- version: 2.3.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Sam Stephenson
14
8
  - Joshua Peek
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2012-03-26 00:00:00 -05:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- name: hike
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 11
31
- segments:
32
- - 1
33
- - 2
34
- version: "1.2"
35
- type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: multi_json
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 15
46
- segments:
47
- - 1
48
- - 0
49
- version: "1.0"
50
- type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
12
+ date: 2015-04-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
53
15
  name: rack
54
- prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 15
61
- segments:
62
- - 1
63
- - 0
64
- version: "1.0"
65
- type: :runtime
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: tilt
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 13
76
- segments:
77
- - 1
78
- - 1
79
- version: "1.1"
80
- - - "!="
81
- - !ruby/object:Gem::Version
82
- hash: 27
83
- segments:
84
- - 1
85
- - 3
86
- - 0
87
- version: 1.3.0
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
88
21
  type: :runtime
89
- version_requirements: *id004
90
- - !ruby/object:Gem::Dependency
91
- name: coffee-script
92
22
  prerelease: false
93
- requirement: &id005 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ~>
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 2
101
- - 0
102
- version: "2.0"
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: closure-compiler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.1'
103
35
  type: :development
104
- version_requirements: *id005
105
- - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.1'
42
+ - !ruby/object:Gem::Dependency
106
43
  name: coffee-script-source
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.6'
49
+ type: :development
107
50
  prerelease: false
108
- requirement: &id006 !ruby/object:Gem::Requirement
109
- none: false
110
- requirements:
111
- - - ~>
112
- - !ruby/object:Gem::Version
113
- hash: 31
114
- segments:
115
- - 1
116
- - 2
117
- - 0
118
- version: 1.2.0
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.6'
56
+ - !ruby/object:Gem::Dependency
57
+ name: coffee-script
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.2'
119
63
  type: :development
120
- version_requirements: *id006
121
- - !ruby/object:Gem::Dependency
122
- name: eco
123
64
  prerelease: false
124
- requirement: &id007 !ruby/object:Gem::Requirement
125
- none: false
126
- requirements:
127
- - - ~>
128
- - !ruby/object:Gem::Version
129
- hash: 15
130
- segments:
131
- - 1
132
- - 0
133
- version: "1.0"
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.2'
70
+ - !ruby/object:Gem::Dependency
71
+ name: eco
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.0'
134
77
  type: :development
135
- version_requirements: *id007
136
- - !ruby/object:Gem::Dependency
137
- name: ejs
138
78
  prerelease: false
139
- requirement: &id008 !ruby/object:Gem::Requirement
140
- none: false
141
- requirements:
142
- - - ~>
143
- - !ruby/object:Gem::Version
144
- hash: 15
145
- segments:
146
- - 1
147
- - 0
148
- version: "1.0"
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: ejs
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.0'
149
91
  type: :development
150
- version_requirements: *id008
151
- - !ruby/object:Gem::Dependency
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.0'
98
+ - !ruby/object:Gem::Dependency
152
99
  name: execjs
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '2.0'
105
+ type: :development
153
106
  prerelease: false
154
- requirement: &id009 !ruby/object:Gem::Requirement
155
- none: false
156
- requirements:
157
- - - ~>
158
- - !ruby/object:Gem::Version
159
- hash: 15
160
- segments:
161
- - 1
162
- - 0
163
- version: "1.0"
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: minitest
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '5.0'
164
119
  type: :development
165
- version_requirements: *id009
166
- - !ruby/object:Gem::Dependency
167
- name: json
168
120
  prerelease: false
169
- requirement: &id010 !ruby/object:Gem::Requirement
170
- none: false
171
- requirements:
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- hash: 3
175
- segments:
176
- - 0
177
- version: "0"
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '5.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: nokogiri
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '1.3'
178
133
  type: :development
179
- version_requirements: *id010
180
- - !ruby/object:Gem::Dependency
181
- name: rack-test
182
134
  prerelease: false
183
- requirement: &id011 !ruby/object:Gem::Requirement
184
- none: false
185
- requirements:
186
- - - ">="
187
- - !ruby/object:Gem::Version
188
- hash: 3
189
- segments:
190
- - 0
191
- version: "0"
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.3'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rack-test
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '0.6'
192
147
  type: :development
193
- version_requirements: *id011
194
- - !ruby/object:Gem::Dependency
195
- name: rake
196
148
  prerelease: false
197
- requirement: &id012 !ruby/object:Gem::Requirement
198
- none: false
199
- requirements:
200
- - - ">="
201
- - !ruby/object:Gem::Version
202
- hash: 3
203
- segments:
204
- - 0
205
- version: "0"
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '0.6'
154
+ - !ruby/object:Gem::Dependency
155
+ name: rake
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '10.0'
206
161
  type: :development
207
- version_requirements: *id012
208
- - !ruby/object:Gem::Dependency
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '10.0'
168
+ - !ruby/object:Gem::Dependency
209
169
  name: sass
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '3.1'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '3.1'
182
+ - !ruby/object:Gem::Dependency
183
+ name: uglifier
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '2.3'
189
+ type: :development
210
190
  prerelease: false
211
- requirement: &id013 !ruby/object:Gem::Requirement
212
- none: false
213
- requirements:
214
- - - ~>
215
- - !ruby/object:Gem::Version
216
- hash: 5
217
- segments:
218
- - 3
219
- - 1
220
- version: "3.1"
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '2.3'
196
+ - !ruby/object:Gem::Dependency
197
+ name: yui-compressor
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - "~>"
201
+ - !ruby/object:Gem::Version
202
+ version: '0.12'
221
203
  type: :development
222
- version_requirements: *id013
223
- description: Sprockets is a Rack-based asset packaging system that concatenates and serves JavaScript, CoffeeScript, CSS, LESS, Sass, and SCSS.
224
- email:
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - "~>"
208
+ - !ruby/object:Gem::Version
209
+ version: '0.12'
210
+ description: Sprockets is a Rack-based asset packaging system that concatenates and
211
+ serves JavaScript, CoffeeScript, CSS, LESS, Sass, and SCSS.
212
+ email:
225
213
  - sstephenson@gmail.com
226
214
  - josh@joshpeek.com
227
- executables:
215
+ executables:
228
216
  - sprockets
229
217
  extensions: []
230
-
231
218
  extra_rdoc_files: []
232
-
233
- files:
234
- - README.md
219
+ files:
235
220
  - LICENSE
221
+ - README.md
222
+ - bin/sprockets
236
223
  - lib/rake/sprocketstask.rb
224
+ - lib/sprockets.rb
237
225
  - lib/sprockets/asset.rb
238
- - lib/sprockets/asset_attributes.rb
226
+ - lib/sprockets/autoload.rb
227
+ - lib/sprockets/autoload/closure.rb
228
+ - lib/sprockets/autoload/coffee_script.rb
229
+ - lib/sprockets/autoload/eco.rb
230
+ - lib/sprockets/autoload/ejs.rb
231
+ - lib/sprockets/autoload/sass.rb
232
+ - lib/sprockets/autoload/uglifier.rb
233
+ - lib/sprockets/autoload/yui.rb
239
234
  - lib/sprockets/base.rb
240
- - lib/sprockets/bundled_asset.rb
235
+ - lib/sprockets/bower.rb
236
+ - lib/sprockets/bundle.rb
237
+ - lib/sprockets/cache.rb
241
238
  - lib/sprockets/cache/file_store.rb
242
- - lib/sprockets/caching.rb
243
- - lib/sprockets/charset_normalizer.rb
239
+ - lib/sprockets/cache/memory_store.rb
240
+ - lib/sprockets/cache/null_store.rb
241
+ - lib/sprockets/cached_environment.rb
242
+ - lib/sprockets/closure_compressor.rb
243
+ - lib/sprockets/coffee_script_processor.rb
244
+ - lib/sprockets/coffee_script_template.rb
245
+ - lib/sprockets/compressing.rb
246
+ - lib/sprockets/configuration.rb
244
247
  - lib/sprockets/context.rb
248
+ - lib/sprockets/dependencies.rb
249
+ - lib/sprockets/digest_utils.rb
245
250
  - lib/sprockets/directive_processor.rb
251
+ - lib/sprockets/eco_processor.rb
246
252
  - lib/sprockets/eco_template.rb
253
+ - lib/sprockets/ejs_processor.rb
247
254
  - lib/sprockets/ejs_template.rb
255
+ - lib/sprockets/encoding_utils.rb
248
256
  - lib/sprockets/engines.rb
249
257
  - lib/sprockets/environment.rb
258
+ - lib/sprockets/erb_processor.rb
259
+ - lib/sprockets/erb_template.rb
250
260
  - lib/sprockets/errors.rb
251
- - lib/sprockets/index.rb
261
+ - lib/sprockets/file_reader.rb
262
+ - lib/sprockets/http_utils.rb
252
263
  - lib/sprockets/jst_processor.rb
264
+ - lib/sprockets/legacy.rb
265
+ - lib/sprockets/legacy_proc_processor.rb
266
+ - lib/sprockets/legacy_tilt_processor.rb
267
+ - lib/sprockets/loader.rb
253
268
  - lib/sprockets/manifest.rb
269
+ - lib/sprockets/manifest_utils.rb
254
270
  - lib/sprockets/mime.rb
255
- - lib/sprockets/processed_asset.rb
271
+ - lib/sprockets/path_dependency_utils.rb
272
+ - lib/sprockets/path_digest_utils.rb
273
+ - lib/sprockets/path_utils.rb
274
+ - lib/sprockets/paths.rb
256
275
  - lib/sprockets/processing.rb
257
- - lib/sprockets/processor.rb
258
- - lib/sprockets/safety_colons.rb
276
+ - lib/sprockets/processor_utils.rb
277
+ - lib/sprockets/resolve.rb
259
278
  - lib/sprockets/sass_cache_store.rb
279
+ - lib/sprockets/sass_compressor.rb
280
+ - lib/sprockets/sass_functions.rb
260
281
  - lib/sprockets/sass_importer.rb
282
+ - lib/sprockets/sass_processor.rb
261
283
  - lib/sprockets/sass_template.rb
262
- - lib/sprockets/scss_template.rb
263
284
  - lib/sprockets/server.rb
264
- - lib/sprockets/static_asset.rb
265
- - lib/sprockets/trail.rb
285
+ - lib/sprockets/transformers.rb
286
+ - lib/sprockets/uglifier_compressor.rb
287
+ - lib/sprockets/uri_utils.rb
266
288
  - lib/sprockets/utils.rb
267
289
  - lib/sprockets/version.rb
268
- - lib/sprockets.rb
269
- - bin/sprockets
270
- has_rdoc: true
271
- homepage: http://getsprockets.org/
272
- licenses: []
273
-
290
+ - lib/sprockets/yui_compressor.rb
291
+ homepage: https://github.com/rails/sprockets
292
+ licenses:
293
+ - MIT
294
+ metadata: {}
274
295
  post_install_message:
275
296
  rdoc_options: []
276
-
277
- require_paths:
297
+ require_paths:
278
298
  - lib
279
- required_ruby_version: !ruby/object:Gem::Requirement
280
- none: false
281
- requirements:
299
+ required_ruby_version: !ruby/object:Gem::Requirement
300
+ requirements:
282
301
  - - ">="
283
- - !ruby/object:Gem::Version
284
- hash: 3
285
- segments:
286
- - 0
287
- version: "0"
288
- required_rubygems_version: !ruby/object:Gem::Requirement
289
- none: false
290
- requirements:
302
+ - !ruby/object:Gem::Version
303
+ version: 1.9.3
304
+ required_rubygems_version: !ruby/object:Gem::Requirement
305
+ requirements:
291
306
  - - ">="
292
- - !ruby/object:Gem::Version
293
- hash: 3
294
- segments:
295
- - 0
296
- version: "0"
307
+ - !ruby/object:Gem::Version
308
+ version: '0'
297
309
  requirements: []
298
-
299
310
  rubyforge_project: sprockets
300
- rubygems_version: 1.6.2
311
+ rubygems_version: 2.4.5
301
312
  signing_key:
302
- specification_version: 3
313
+ specification_version: 4
303
314
  summary: Rack-based asset packaging system
304
315
  test_files: []
305
-
@@ -1,126 +0,0 @@
1
- require 'pathname'
2
-
3
- module Sprockets
4
- # `AssetAttributes` is a wrapper similar to `Pathname` that provides
5
- # some helper accessors.
6
- #
7
- # These methods should be considered internalish.
8
- class AssetAttributes
9
- attr_reader :environment, :pathname
10
-
11
- def initialize(environment, path)
12
- @environment = environment
13
- @pathname = path.is_a?(Pathname) ? path : Pathname.new(path.to_s)
14
- end
15
-
16
- # Returns paths search the load path for.
17
- def search_paths
18
- paths = [pathname.to_s]
19
-
20
- if pathname.basename(extensions.join).to_s != 'index'
21
- path_without_extensions = extensions.inject(pathname) { |p, ext| p.sub(ext, '') }
22
- index_path = path_without_extensions.join("index#{extensions.join}").to_s
23
- paths << index_path
24
- end
25
-
26
- paths
27
- end
28
-
29
- # Reverse guess logical path for fully expanded path.
30
- #
31
- # This has some known issues. For an example if a file is
32
- # shaddowed in the path, but is required relatively, its logical
33
- # path will be incorrect.
34
- def logical_path
35
- if root_path = environment.paths.detect { |path| pathname.to_s[path] }
36
- path = pathname.to_s.sub("#{root_path}/", '')
37
- path = pathname.relative_path_from(Pathname.new(root_path)).to_s
38
- path = engine_extensions.inject(path) { |p, ext| p.sub(ext, '') }
39
- path = "#{path}#{engine_format_extension}" unless format_extension
40
- path
41
- else
42
- raise FileOutsidePaths, "#{pathname} isn't in paths: #{environment.paths.join(', ')}"
43
- end
44
- end
45
-
46
- # Returns `Array` of extension `String`s.
47
- #
48
- # "foo.js.coffee"
49
- # # => [".js", ".coffee"]
50
- #
51
- def extensions
52
- @extensions ||= @pathname.basename.to_s.scan(/\.[^.]+/)
53
- end
54
-
55
- # Returns the format extension.
56
- #
57
- # "foo.js.coffee"
58
- # # => ".js"
59
- #
60
- def format_extension
61
- extensions.reverse.detect { |ext|
62
- @environment.mime_types(ext) && !@environment.engines(ext)
63
- }
64
- end
65
-
66
- # Returns an `Array` of engine extensions.
67
- #
68
- # "foo.js.coffee.erb"
69
- # # => [".coffee", ".erb"]
70
- #
71
- def engine_extensions
72
- exts = extensions
73
-
74
- if offset = extensions.index(format_extension)
75
- exts = extensions[offset+1..-1]
76
- end
77
-
78
- exts.select { |ext| @environment.engines(ext) }
79
- end
80
-
81
- # Returns engine classes.
82
- def engines
83
- engine_extensions.map { |ext| @environment.engines(ext) }
84
- end
85
-
86
- # Returns all processors to run on the path.
87
- def processors
88
- environment.preprocessors(content_type) +
89
- engines.reverse +
90
- environment.postprocessors(content_type)
91
- end
92
-
93
- # Returns the content type for the pathname. Falls back to `application/octet-stream`.
94
- def content_type
95
- @content_type ||= begin
96
- if format_extension.nil?
97
- engine_content_type || 'application/octet-stream'
98
- else
99
- @environment.mime_types(format_extension) ||
100
- engine_content_type ||
101
- 'application/octet-stream'
102
- end
103
- end
104
- end
105
-
106
- private
107
- # Returns implicit engine content type.
108
- #
109
- # `.coffee` files carry an implicit `application/javascript`
110
- # content type.
111
- def engine_content_type
112
- engines.reverse.each do |engine|
113
- if engine.respond_to?(:default_mime_type) && engine.default_mime_type
114
- return engine.default_mime_type
115
- end
116
- end
117
- nil
118
- end
119
-
120
- def engine_format_extension
121
- if content_type = engine_content_type
122
- environment.extension_for_mime_type(content_type)
123
- end
124
- end
125
- end
126
- end