sprockets 3.7.2 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -267
  3. data/README.md +477 -321
  4. data/bin/sprockets +11 -7
  5. data/lib/rake/sprocketstask.rb +3 -2
  6. data/lib/sprockets.rb +99 -39
  7. data/lib/sprockets/add_source_map_comment_to_asset_processor.rb +60 -0
  8. data/lib/sprockets/asset.rb +31 -23
  9. data/lib/sprockets/autoload.rb +5 -0
  10. data/lib/sprockets/autoload/babel.rb +8 -0
  11. data/lib/sprockets/autoload/closure.rb +1 -0
  12. data/lib/sprockets/autoload/coffee_script.rb +1 -0
  13. data/lib/sprockets/autoload/eco.rb +1 -0
  14. data/lib/sprockets/autoload/ejs.rb +1 -0
  15. data/lib/sprockets/autoload/jsminc.rb +8 -0
  16. data/lib/sprockets/autoload/sass.rb +1 -0
  17. data/lib/sprockets/autoload/sassc.rb +8 -0
  18. data/lib/sprockets/autoload/uglifier.rb +1 -0
  19. data/lib/sprockets/autoload/yui.rb +1 -0
  20. data/lib/sprockets/autoload/zopfli.rb +7 -0
  21. data/lib/sprockets/babel_processor.rb +66 -0
  22. data/lib/sprockets/base.rb +49 -12
  23. data/lib/sprockets/bower.rb +5 -2
  24. data/lib/sprockets/bundle.rb +40 -4
  25. data/lib/sprockets/cache.rb +36 -1
  26. data/lib/sprockets/cache/file_store.rb +25 -3
  27. data/lib/sprockets/cache/memory_store.rb +9 -0
  28. data/lib/sprockets/cache/null_store.rb +8 -0
  29. data/lib/sprockets/cached_environment.rb +14 -19
  30. data/lib/sprockets/closure_compressor.rb +1 -0
  31. data/lib/sprockets/coffee_script_processor.rb +18 -4
  32. data/lib/sprockets/compressing.rb +43 -3
  33. data/lib/sprockets/configuration.rb +3 -7
  34. data/lib/sprockets/context.rb +97 -24
  35. data/lib/sprockets/dependencies.rb +1 -0
  36. data/lib/sprockets/digest_utils.rb +25 -5
  37. data/lib/sprockets/directive_processor.rb +45 -35
  38. data/lib/sprockets/eco_processor.rb +1 -0
  39. data/lib/sprockets/ejs_processor.rb +1 -0
  40. data/lib/sprockets/encoding_utils.rb +1 -0
  41. data/lib/sprockets/environment.rb +9 -4
  42. data/lib/sprockets/erb_processor.rb +28 -21
  43. data/lib/sprockets/errors.rb +1 -0
  44. data/lib/sprockets/exporters/base.rb +71 -0
  45. data/lib/sprockets/exporters/file_exporter.rb +24 -0
  46. data/lib/sprockets/exporters/zlib_exporter.rb +33 -0
  47. data/lib/sprockets/exporters/zopfli_exporter.rb +14 -0
  48. data/lib/sprockets/exporting.rb +73 -0
  49. data/lib/sprockets/file_reader.rb +1 -0
  50. data/lib/sprockets/http_utils.rb +25 -7
  51. data/lib/sprockets/jsminc_compressor.rb +32 -0
  52. data/lib/sprockets/jst_processor.rb +11 -10
  53. data/lib/sprockets/loader.rb +87 -67
  54. data/lib/sprockets/manifest.rb +64 -62
  55. data/lib/sprockets/manifest_utils.rb +9 -6
  56. data/lib/sprockets/mime.rb +8 -42
  57. data/lib/sprockets/npm.rb +52 -0
  58. data/lib/sprockets/path_dependency_utils.rb +3 -11
  59. data/lib/sprockets/path_digest_utils.rb +2 -1
  60. data/lib/sprockets/path_utils.rb +87 -7
  61. data/lib/sprockets/paths.rb +1 -0
  62. data/lib/sprockets/preprocessors/default_source_map.rb +49 -0
  63. data/lib/sprockets/processing.rb +31 -61
  64. data/lib/sprockets/processor_utils.rb +24 -35
  65. data/lib/sprockets/resolve.rb +177 -93
  66. data/lib/sprockets/sass_cache_store.rb +2 -6
  67. data/lib/sprockets/sass_compressor.rb +13 -1
  68. data/lib/sprockets/sass_functions.rb +1 -0
  69. data/lib/sprockets/sass_importer.rb +1 -0
  70. data/lib/sprockets/sass_processor.rb +30 -9
  71. data/lib/sprockets/sassc_compressor.rb +56 -0
  72. data/lib/sprockets/sassc_processor.rb +297 -0
  73. data/lib/sprockets/server.rb +26 -23
  74. data/lib/sprockets/source_map_processor.rb +66 -0
  75. data/lib/sprockets/source_map_utils.rb +483 -0
  76. data/lib/sprockets/transformers.rb +63 -35
  77. data/lib/sprockets/uglifier_compressor.rb +21 -11
  78. data/lib/sprockets/unloaded_asset.rb +13 -11
  79. data/lib/sprockets/uri_tar.rb +1 -0
  80. data/lib/sprockets/uri_utils.rb +11 -8
  81. data/lib/sprockets/utils.rb +41 -74
  82. data/lib/sprockets/utils/gzip.rb +46 -14
  83. data/lib/sprockets/version.rb +2 -1
  84. data/lib/sprockets/yui_compressor.rb +1 -0
  85. metadata +127 -23
  86. data/LICENSE +0 -21
  87. data/lib/sprockets/coffee_script_template.rb +0 -17
  88. data/lib/sprockets/deprecation.rb +0 -90
  89. data/lib/sprockets/eco_template.rb +0 -17
  90. data/lib/sprockets/ejs_template.rb +0 -17
  91. data/lib/sprockets/engines.rb +0 -92
  92. data/lib/sprockets/erb_template.rb +0 -11
  93. data/lib/sprockets/legacy.rb +0 -330
  94. data/lib/sprockets/legacy_proc_processor.rb +0 -35
  95. data/lib/sprockets/legacy_tilt_processor.rb +0 -29
  96. data/lib/sprockets/sass_template.rb +0 -19
@@ -12,7 +12,7 @@ unless ARGV.delete("--noenv")
12
12
  end
13
13
  end
14
14
 
15
- filenames = []
15
+ paths = []
16
16
  environment = Sprockets::Environment.new(Dir.pwd)
17
17
  manifest = nil
18
18
 
@@ -52,6 +52,10 @@ OptionParser.new do |opts|
52
52
  opts.on("--noenv", "Disables .sprocketsrc file") do
53
53
  end
54
54
 
55
+ opts.on("--cache=DIRECTORY", "Enables the FileStore cache using the specified directory") do |directory|
56
+ environment.cache = Sprockets::Cache::FileStore.new(directory)
57
+ end
58
+
55
59
  opts.on_tail("-h", "--help", "Shows this help message") do
56
60
  opts.show_usage
57
61
  end
@@ -64,8 +68,8 @@ OptionParser.new do |opts|
64
68
  opts.show_usage if ARGV.empty?
65
69
 
66
70
  begin
67
- opts.order(ARGV) do |filename|
68
- filenames << File.expand_path(filename)
71
+ opts.order(ARGV) do |path|
72
+ paths << path
69
73
  end
70
74
  rescue OptionParser::ParseError => e
71
75
  opts.warn e.message
@@ -75,14 +79,14 @@ end
75
79
 
76
80
  if environment.paths.empty?
77
81
  warn "No load paths given"
78
- warn "Usage: sprockets -Ijavascripts/ filename"
82
+ warn "Usage: sprockets -Ijavascripts/ path"
79
83
  exit 1
80
84
  end
81
85
 
82
86
  if manifest
83
- manifest.compile(filenames)
84
- elsif filenames.length == 1
85
- puts environment.find_asset(filenames.first).to_s
87
+ manifest.compile(paths)
88
+ elsif paths.length == 1
89
+ puts environment.find_asset(paths.first).to_s
86
90
  else
87
91
  warn "Only one file can be compiled to stdout at a time"
88
92
  exit 1
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rake'
2
3
  require 'rake/tasklib'
3
4
 
@@ -124,7 +125,7 @@ module Rake
124
125
  end
125
126
  end
126
127
 
127
- task :clobber => ["clobber_#{name}"]
128
+ task clobber: ["clobber_#{name}"]
128
129
 
129
130
  desc name == :assets ? "Clean old assets" : "Clean old #{name} assets"
130
131
  task "clean_#{name}" do
@@ -133,7 +134,7 @@ module Rake
133
134
  end
134
135
  end
135
136
 
136
- task :clean => ["clean_#{name}"]
137
+ task clean: ["clean_#{name}"]
137
138
  end
138
139
 
139
140
  private
@@ -1,10 +1,11 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'sprockets/version'
3
5
  require 'sprockets/cache'
4
6
  require 'sprockets/environment'
5
7
  require 'sprockets/errors'
6
8
  require 'sprockets/manifest'
7
- require 'sprockets/deprecation'
8
9
 
9
10
  module Sprockets
10
11
  require 'sprockets/processor_utils'
@@ -23,21 +24,21 @@ module Sprockets
23
24
  dependencies: Set.new.freeze,
24
25
  dependency_resolvers: {}.freeze,
25
26
  digest_class: Digest::SHA256,
26
- engine_mime_types: {}.freeze,
27
- engines: {}.freeze,
28
27
  mime_exts: {}.freeze,
29
28
  mime_types: {}.freeze,
30
29
  paths: [].freeze,
31
30
  pipelines: {}.freeze,
31
+ pipeline_exts: {}.freeze,
32
32
  postprocessors: Hash.new { |h, k| [].freeze }.freeze,
33
33
  preprocessors: Hash.new { |h, k| [].freeze }.freeze,
34
- registered_transformers: Hash.new { |h, k| {}.freeze }.freeze,
35
- root: File.expand_path('..', __FILE__).freeze,
34
+ registered_transformers: [].freeze,
35
+ root: __dir__.dup.freeze,
36
36
  transformers: Hash.new { |h, k| {}.freeze }.freeze,
37
+ exporters: Hash.new { |h, k| Set.new.freeze }.freeze,
37
38
  version: "",
38
- gzip_enabled: true
39
+ gzip_enabled: true,
40
+ export_concurrent: true
39
41
  }.freeze
40
- self.computed_config = {}
41
42
 
42
43
  @context_class = Context
43
44
 
@@ -48,6 +49,7 @@ module Sprockets
48
49
  # Common asset text types
49
50
  register_mime_type 'application/javascript', extensions: ['.js'], charset: :unicode
50
51
  register_mime_type 'application/json', extensions: ['.json'], charset: :unicode
52
+ register_mime_type 'application/ruby', extensions: ['.rb']
51
53
  register_mime_type 'application/xml', extensions: ['.xml']
52
54
  register_mime_type 'text/css', extensions: ['.css'], charset: :css
53
55
  register_mime_type 'text/html', extensions: ['.html', '.htm'], charset: :html
@@ -70,84 +72,133 @@ module Sprockets
70
72
  register_mime_type 'audio/aiff', extensions: ['.aiff']
71
73
  register_mime_type 'audio/mpeg', extensions: ['.mp3', '.mp2', '.m2a', '.m3a']
72
74
  register_mime_type 'application/ogg', extensions: ['.ogx']
75
+ register_mime_type 'audio/ogg', extensions: ['.ogg', '.oga']
73
76
  register_mime_type 'audio/midi', extensions: ['.midi', '.mid']
74
77
  register_mime_type 'video/avi', extensions: ['.avi']
75
78
  register_mime_type 'audio/wave', extensions: ['.wav', '.wave']
76
79
  register_mime_type 'video/mp4', extensions: ['.mp4', '.m4v']
80
+ register_mime_type 'audio/aac', extensions: ['.aac']
81
+ register_mime_type 'audio/mp4', extensions: ['.m4a']
82
+ register_mime_type 'audio/flac', extensions: ['.flac']
77
83
 
78
84
  # Common font types
79
85
  register_mime_type 'application/vnd.ms-fontobject', extensions: ['.eot']
80
86
  register_mime_type 'application/x-font-opentype', extensions: ['.otf']
81
87
  register_mime_type 'application/x-font-ttf', extensions: ['.ttf']
82
88
  register_mime_type 'application/font-woff', extensions: ['.woff']
89
+ register_mime_type 'application/font-woff2', extensions: ['.woff2']
90
+
91
+ require 'sprockets/source_map_processor'
92
+ register_mime_type 'application/js-sourcemap+json', extensions: ['.js.map']
93
+ register_mime_type 'application/css-sourcemap+json', extensions: ['.css.map']
94
+ register_transformer 'application/javascript', 'application/js-sourcemap+json', SourceMapProcessor
95
+ register_transformer 'text/css', 'application/css-sourcemap+json', SourceMapProcessor
83
96
 
84
97
  register_pipeline :source do |env|
85
98
  []
86
99
  end
87
100
 
88
- register_pipeline :self do |env, type, file_type, engine_extnames|
89
- env.self_processors_for(type, file_type, engine_extnames)
101
+ register_pipeline :self do |env, type, file_type|
102
+ env.self_processors_for(type, file_type)
103
+ end
104
+
105
+ register_pipeline :default do |env, type, file_type|
106
+ env.default_processors_for(type, file_type)
90
107
  end
91
108
 
92
- register_pipeline :default do |env, type, file_type, engine_extnames|
93
- env.default_processors_for(type, file_type, engine_extnames)
109
+ require 'sprockets/add_source_map_comment_to_asset_processor'
110
+ register_pipeline :debug do
111
+ [AddSourceMapCommentToAssetProcessor]
94
112
  end
95
113
 
96
114
  require 'sprockets/directive_processor'
97
- register_preprocessor 'text/css', DirectiveProcessor.new(
98
- comments: ["//", ["/*", "*/"]]
99
- )
100
- register_preprocessor 'application/javascript', DirectiveProcessor.new(
101
- comments: ["//", ["/*", "*/"]] + ["#", ["###", "###"]]
102
- )
115
+ register_preprocessor 'text/css', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
116
+ register_preprocessor 'application/javascript', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
103
117
 
104
118
  require 'sprockets/bundle'
105
119
  register_bundle_processor 'application/javascript', Bundle
106
120
  register_bundle_processor 'text/css', Bundle
107
121
 
108
- register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
109
- register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
122
+ register_bundle_metadata_reducer '*/*', :data, proc { +"" }, :concat
123
+ register_bundle_metadata_reducer 'application/javascript', :data, proc { +"" }, Utils.method(:concat_javascript_sources)
110
124
  register_bundle_metadata_reducer '*/*', :links, :+
125
+ register_bundle_metadata_reducer '*/*', :sources, proc { [] }, :+
111
126
 
112
127
  require 'sprockets/closure_compressor'
113
128
  require 'sprockets/sass_compressor'
129
+ require 'sprockets/sassc_compressor'
130
+ require 'sprockets/jsminc_compressor'
114
131
  require 'sprockets/uglifier_compressor'
115
132
  require 'sprockets/yui_compressor'
116
133
  register_compressor 'text/css', :sass, SassCompressor
134
+ register_compressor 'text/css', :sassc, SasscCompressor
117
135
  register_compressor 'text/css', :scss, SassCompressor
136
+ register_compressor 'text/css', :scssc, SasscCompressor
118
137
  register_compressor 'text/css', :yui, YUICompressor
119
138
  register_compressor 'application/javascript', :closure, ClosureCompressor
139
+ register_compressor 'application/javascript', :jsmin, JSMincCompressor
140
+ register_compressor 'application/javascript', :jsminc, JSMincCompressor
120
141
  register_compressor 'application/javascript', :uglifier, UglifierCompressor
121
142
  register_compressor 'application/javascript', :uglify, UglifierCompressor
122
143
  register_compressor 'application/javascript', :yui, YUICompressor
123
144
 
145
+ # Babel, TheFuture™ is now
146
+ require 'sprockets/babel_processor'
147
+ register_mime_type 'application/ecmascript-6', extensions: ['.es6'], charset: :unicode
148
+ register_transformer 'application/ecmascript-6', 'application/javascript', BabelProcessor
149
+ register_preprocessor 'application/ecmascript-6', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
150
+
124
151
  # Mmm, CoffeeScript
125
152
  require 'sprockets/coffee_script_processor'
126
- Deprecation.silence do
127
- register_engine '.coffee', CoffeeScriptProcessor, mime_type: 'application/javascript', silence_deprecation: true
128
- end
153
+ register_mime_type 'text/coffeescript', extensions: ['.coffee', '.js.coffee']
154
+ register_transformer 'text/coffeescript', 'application/javascript', CoffeeScriptProcessor
155
+ register_preprocessor 'text/coffeescript', DirectiveProcessor.new(comments: ["#", ["###", "###"]])
129
156
 
130
- # JST engines
157
+ # JST processors
131
158
  require 'sprockets/eco_processor'
132
159
  require 'sprockets/ejs_processor'
133
160
  require 'sprockets/jst_processor'
134
- Deprecation.silence do
135
- register_engine '.jst', JstProcessor, mime_type: 'application/javascript', silence_deprecation: true
136
- register_engine '.eco', EcoProcessor, mime_type: 'application/javascript', silence_deprecation: true
137
- register_engine '.ejs', EjsProcessor, mime_type: 'application/javascript', silence_deprecation: true
138
- end
139
-
140
- # CSS engines
141
- require 'sprockets/sass_processor'
142
- Deprecation.silence do
143
- register_engine '.sass', SassProcessor, mime_type: 'text/css', silence_deprecation: true
144
- register_engine '.scss', ScssProcessor, mime_type: 'text/css', silence_deprecation: true
145
- end
161
+ register_mime_type 'text/eco', extensions: ['.eco', '.jst.eco']
162
+ register_mime_type 'text/ejs', extensions: ['.ejs', '.jst.ejs']
163
+ register_transformer 'text/eco', 'application/javascript+function', EcoProcessor
164
+ register_transformer 'text/ejs', 'application/javascript+function', EjsProcessor
165
+ register_transformer 'application/javascript+function', 'application/javascript', JstProcessor
166
+
167
+ # CSS processors
168
+ require 'sprockets/sassc_processor'
169
+ register_mime_type 'text/sass', extensions: ['.sass', '.css.sass']
170
+ register_mime_type 'text/scss', extensions: ['.scss', '.css.scss']
171
+ register_transformer 'text/sass', 'text/css', SasscProcessor
172
+ register_transformer 'text/scss', 'text/css', ScsscProcessor
173
+ register_preprocessor 'text/sass', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
174
+ register_preprocessor 'text/scss', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
146
175
  register_bundle_metadata_reducer 'text/css', :sass_dependencies, Set.new, :+
147
176
 
148
- # Other
177
+ # ERB
149
178
  require 'sprockets/erb_processor'
150
- register_engine '.erb', ERBProcessor, mime_type: 'text/plain', silence_deprecation: true
179
+ register_transformer_suffix(%w(
180
+ application/ecmascript-6
181
+ application/javascript
182
+ application/json
183
+ application/xml
184
+ text/coffeescript
185
+ text/css
186
+ text/html
187
+ text/plain
188
+ text/sass
189
+ text/scss
190
+ text/yaml
191
+ text/eco
192
+ ), 'application/\2+ruby', '.erb', ERBProcessor)
193
+
194
+ register_mime_type 'application/html+ruby', extensions: ['.html.erb', '.erb', '.rhtml'], charset: :html
195
+ register_mime_type 'application/xml+ruby', extensions: ['.xml.erb', '.rxml']
196
+
197
+ require 'sprockets/exporters/file_exporter'
198
+ require 'sprockets/exporters/zlib_exporter'
199
+ require 'sprockets/exporters/zopfli_exporter'
200
+ register_exporter '*/*', Exporters::FileExporter
201
+ register_exporter '*/*', Exporters::ZlibExporter
151
202
 
152
203
  register_dependency_resolver 'environment-version' do |env|
153
204
  env.version
@@ -161,9 +212,18 @@ module Sprockets
161
212
  register_dependency_resolver 'processors' do |env, str|
162
213
  env.resolve_processors_cache_key_uri(str)
163
214
  end
215
+ register_dependency_resolver 'env' do |env, str|
216
+ _, var = str.split(':', 2)
217
+ ENV[var]
218
+ end
164
219
 
165
220
  depend_on 'environment-version'
166
221
  depend_on 'environment-paths'
167
- end
168
222
 
169
- require 'sprockets/legacy'
223
+ require 'sprockets/preprocessors/default_source_map'
224
+ register_preprocessor 'text/css', Preprocessors::DefaultSourceMap.new
225
+ register_preprocessor 'application/javascript', Preprocessors::DefaultSourceMap.new
226
+
227
+ register_bundle_metadata_reducer 'text/css', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps)
228
+ register_bundle_metadata_reducer 'application/javascript', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps)
229
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ require 'sprockets/uri_utils'
3
+ require 'sprockets/path_utils'
4
+
5
+ module Sprockets
6
+ # This is a processor designed to add a source map "comment"
7
+ # to the bottom of a css or JS file that is serving a source
8
+ # map. An example of a comment might look like this
9
+ #
10
+ # //# application.js-80af0efcc960fc2ac93eda2f7b12e3db40ab360bf6ea269ceed3bea3678326f9.map
11
+ #
12
+ # As an asset is built it gets source map information added
13
+ # to the `asset.to_hash[:metadata][:map]` key. This contains all the
14
+ # information that is needed to build a source map file.
15
+ #
16
+ # To add this comment we must have an asset we can link to.
17
+ # To do this we ensure that the original aset is loaded, then
18
+ # we use a use a special mime type. For example `application/js-sourcemap+json`
19
+ # for a JS source map.
20
+ #
21
+ # This will trigger a new asset to be loaded and generated by the
22
+ # `SourceMapProcessor` processor.
23
+ #
24
+ # Finally once we have that file, we can generate a link to it
25
+ # with it's full fingerprint. This is done and then
26
+ # added to the original asset as a comment at the bottom.
27
+ #
28
+ class AddSourceMapCommentToAssetProcessor
29
+ def self.call(input)
30
+
31
+ case input[:content_type]
32
+ when "application/javascript"
33
+ comment = "\n//# sourceMappingURL=%s"
34
+ map_type = "application/js-sourcemap+json"
35
+ when "text/css"
36
+ comment = "\n/*# sourceMappingURL=%s */"
37
+ map_type = "application/css-sourcemap+json"
38
+ else
39
+ fail input[:content_type]
40
+ end
41
+
42
+ env = input[:environment]
43
+
44
+ uri, _ = env.resolve!(input[:filename], accept: input[:content_type])
45
+ asset = env.load(uri)
46
+
47
+ uri, _ = env.resolve!(input[:filename], accept: map_type)
48
+ map = env.load(uri)
49
+
50
+ uri, params = URIUtils.parse_asset_uri(input[:uri])
51
+ uri = env.expand_from_root(params[:index_alias]) if params[:index_alias]
52
+ path = PathUtils.relative_path_from(PathUtils.split_subpath(input[:load_path], uri), map.digest_path)
53
+
54
+ asset.metadata.merge(
55
+ data: asset.source + (comment % path) + "\n",
56
+ links: asset.links + [asset.uri, map.uri]
57
+ )
58
+ end
59
+ end
60
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'fileutils'
2
3
  require 'sprockets/digest_utils'
3
4
 
@@ -13,8 +14,7 @@ module Sprockets
13
14
  # attributes - Hash of ivars
14
15
  #
15
16
  # Returns Asset.
16
- def initialize(environment, attributes = {})
17
- @environment = environment
17
+ def initialize(attributes = {})
18
18
  @attributes = attributes
19
19
  @content_type = attributes[:content_type]
20
20
  @filename = attributes[:filename]
@@ -22,7 +22,6 @@ module Sprockets
22
22
  @load_path = attributes[:load_path]
23
23
  @logical_path = attributes[:logical_path]
24
24
  @metadata = attributes[:metadata]
25
- @mtime = attributes[:mtime]
26
25
  @name = attributes[:name]
27
26
  @source = attributes[:source]
28
27
  @uri = attributes[:uri]
@@ -68,6 +67,13 @@ module Sprockets
68
67
  logical_path.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" }
69
68
  end
70
69
 
70
+ # Public: Return load path + logical path with digest spliced in.
71
+ #
72
+ # Returns String.
73
+ def full_digest_path
74
+ File.join(@load_path, digest_path)
75
+ end
76
+
71
77
  # Public: Returns String MIME type of asset. Returns nil if type is unknown.
72
78
  attr_reader :content_type
73
79
 
@@ -80,14 +86,6 @@ module Sprockets
80
86
  metadata[:links] || Set.new
81
87
  end
82
88
 
83
- # Public: Get all internally required assets that were concated into this
84
- # asset.
85
- #
86
- # Returns Array of String asset URIs.
87
- def included
88
- metadata[:included]
89
- end
90
-
91
89
  # Public: Return `String` of concatenated source.
92
90
  #
93
91
  # Returns String.
@@ -120,27 +118,40 @@ module Sprockets
120
118
  end
121
119
  alias_method :bytesize, :length
122
120
 
121
+ # Public: Returns String byte digest of source.
122
+ def digest
123
+ metadata[:digest]
124
+ end
125
+
126
+ # Private: Return the version of the environment where the asset was generated.
127
+ def environment_version
128
+ metadata[:environment_version]
129
+ end
130
+
123
131
  # Public: Returns String hexdigest of source.
124
132
  def hexdigest
125
- DigestUtils.pack_hexdigest(metadata[:digest])
133
+ DigestUtils.pack_hexdigest(digest)
126
134
  end
127
135
 
128
- # Deprecated: Returns String hexdigest of source.
129
- #
130
- # In 4.x this will be changed to return a raw Digest byte String.
131
- alias_method :digest, :hexdigest
132
-
133
136
  # Pubic: ETag String of Asset.
134
- alias_method :etag, :hexdigest
137
+ def etag
138
+ version = environment_version
139
+
140
+ if version && version != ""
141
+ DigestUtils.hexdigest(version + digest)
142
+ else
143
+ DigestUtils.pack_hexdigest(digest)
144
+ end
145
+ end
135
146
 
136
147
  # Public: Returns String base64 digest of source.
137
148
  def base64digest
138
- DigestUtils.pack_base64digest(metadata[:digest])
149
+ DigestUtils.pack_base64digest(digest)
139
150
  end
140
151
 
141
152
  # Public: A "named information" URL for subresource integrity.
142
153
  def integrity
143
- DigestUtils.integrity_uri(metadata[:digest])
154
+ DigestUtils.integrity_uri(digest)
144
155
  end
145
156
 
146
157
  # Public: Add enumerator to allow `Asset` instances to be used as Rack
@@ -166,9 +177,6 @@ module Sprockets
166
177
  f.write source
167
178
  end
168
179
 
169
- # Set mtime correctly
170
- File.utime(mtime, mtime, filename)
171
-
172
180
  nil
173
181
  end
174
182