sprockets 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +68 -0
- data/README.md +397 -408
- data/bin/sprockets +12 -7
- data/lib/rake/sprocketstask.rb +3 -2
- data/lib/sprockets/add_source_map_comment_to_asset_processor.rb +60 -0
- data/lib/sprockets/asset.rb +19 -23
- data/lib/sprockets/autoload/babel.rb +8 -0
- data/lib/sprockets/autoload/closure.rb +1 -0
- data/lib/sprockets/autoload/coffee_script.rb +1 -0
- data/lib/sprockets/autoload/eco.rb +1 -0
- data/lib/sprockets/autoload/ejs.rb +1 -0
- data/lib/sprockets/autoload/jsminc.rb +8 -0
- data/lib/sprockets/autoload/sass.rb +1 -0
- data/lib/sprockets/autoload/sassc.rb +8 -0
- data/lib/sprockets/autoload/uglifier.rb +1 -0
- data/lib/sprockets/autoload/yui.rb +1 -0
- data/lib/sprockets/autoload/zopfli.rb +7 -0
- data/lib/sprockets/autoload.rb +5 -0
- data/lib/sprockets/babel_processor.rb +66 -0
- data/lib/sprockets/base.rb +59 -11
- data/lib/sprockets/bower.rb +5 -2
- data/lib/sprockets/bundle.rb +44 -4
- data/lib/sprockets/cache/file_store.rb +32 -7
- data/lib/sprockets/cache/memory_store.rb +9 -0
- data/lib/sprockets/cache/null_store.rb +8 -0
- data/lib/sprockets/cache.rb +42 -5
- data/lib/sprockets/cached_environment.rb +14 -19
- data/lib/sprockets/closure_compressor.rb +6 -11
- data/lib/sprockets/coffee_script_processor.rb +19 -5
- data/lib/sprockets/compressing.rb +62 -2
- data/lib/sprockets/configuration.rb +3 -7
- data/lib/sprockets/context.rb +98 -23
- data/lib/sprockets/dependencies.rb +9 -8
- data/lib/sprockets/digest_utils.rb +104 -60
- data/lib/sprockets/directive_processor.rb +45 -35
- data/lib/sprockets/eco_processor.rb +3 -2
- data/lib/sprockets/ejs_processor.rb +3 -2
- data/lib/sprockets/encoding_utils.rb +8 -4
- data/lib/sprockets/environment.rb +9 -4
- data/lib/sprockets/erb_processor.rb +28 -21
- data/lib/sprockets/errors.rb +1 -1
- data/lib/sprockets/exporters/base.rb +72 -0
- data/lib/sprockets/exporters/file_exporter.rb +24 -0
- data/lib/sprockets/exporters/zlib_exporter.rb +33 -0
- data/lib/sprockets/exporters/zopfli_exporter.rb +14 -0
- data/lib/sprockets/exporting.rb +73 -0
- data/lib/sprockets/file_reader.rb +1 -0
- data/lib/sprockets/http_utils.rb +26 -6
- data/lib/sprockets/jsminc_compressor.rb +32 -0
- data/lib/sprockets/jst_processor.rb +11 -10
- data/lib/sprockets/loader.rb +236 -69
- data/lib/sprockets/manifest.rb +97 -44
- data/lib/sprockets/manifest_utils.rb +9 -6
- data/lib/sprockets/mime.rb +8 -42
- data/lib/sprockets/npm.rb +52 -0
- data/lib/sprockets/path_dependency_utils.rb +3 -11
- data/lib/sprockets/path_digest_utils.rb +2 -1
- data/lib/sprockets/path_utils.rb +106 -21
- data/lib/sprockets/paths.rb +1 -0
- data/lib/sprockets/preprocessors/default_source_map.rb +49 -0
- data/lib/sprockets/processing.rb +31 -51
- data/lib/sprockets/processor_utils.rb +81 -15
- data/lib/sprockets/resolve.rb +182 -95
- data/lib/sprockets/sass_cache_store.rb +1 -0
- data/lib/sprockets/sass_compressor.rb +21 -17
- data/lib/sprockets/sass_functions.rb +1 -0
- data/lib/sprockets/sass_importer.rb +1 -0
- data/lib/sprockets/sass_processor.rb +45 -17
- data/lib/sprockets/sassc_compressor.rb +56 -0
- data/lib/sprockets/sassc_processor.rb +297 -0
- data/lib/sprockets/server.rb +57 -34
- data/lib/sprockets/source_map_processor.rb +66 -0
- data/lib/sprockets/source_map_utils.rb +483 -0
- data/lib/sprockets/transformers.rb +63 -35
- data/lib/sprockets/uglifier_compressor.rb +23 -20
- data/lib/sprockets/unloaded_asset.rb +139 -0
- data/lib/sprockets/uri_tar.rb +99 -0
- data/lib/sprockets/uri_utils.rb +15 -14
- data/lib/sprockets/utils/gzip.rb +99 -0
- data/lib/sprockets/utils.rb +43 -59
- data/lib/sprockets/version.rb +2 -1
- data/lib/sprockets/yui_compressor.rb +5 -14
- data/lib/sprockets.rb +103 -33
- metadata +151 -22
- data/LICENSE +0 -21
- data/lib/sprockets/coffee_script_template.rb +0 -6
- data/lib/sprockets/eco_template.rb +0 -6
- data/lib/sprockets/ejs_template.rb +0 -6
- data/lib/sprockets/engines.rb +0 -81
- data/lib/sprockets/erb_template.rb +0 -6
- data/lib/sprockets/legacy.rb +0 -314
- data/lib/sprockets/legacy_proc_processor.rb +0 -35
- data/lib/sprockets/legacy_tilt_processor.rb +0 -29
- data/lib/sprockets/sass_template.rb +0 -7
data/lib/sprockets/mime.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/encoding_utils'
|
2
3
|
require 'sprockets/http_utils'
|
3
4
|
require 'sprockets/utils'
|
@@ -36,29 +37,18 @@ module Sprockets
|
|
36
37
|
|
37
38
|
# Public: Register a new mime type.
|
38
39
|
#
|
39
|
-
# mime_type
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# See EncodingUtils.
|
40
|
+
# mime_type - String MIME Type
|
41
|
+
# extensions - Array of String extnames
|
42
|
+
# charset - Proc/Method that detects the charset of a file.
|
43
|
+
# See EncodingUtils.
|
44
44
|
#
|
45
45
|
# Returns nothing.
|
46
|
-
def register_mime_type(mime_type,
|
47
|
-
|
48
|
-
if options.is_a?(String)
|
49
|
-
options = { extensions: [options] }
|
50
|
-
end
|
51
|
-
|
52
|
-
extnames = Array(options[:extensions]).map { |extname|
|
53
|
-
Sprockets::Utils.normalize_extension(extname)
|
54
|
-
}
|
46
|
+
def register_mime_type(mime_type, extensions: [], charset: nil)
|
47
|
+
extnames = Array(extensions)
|
55
48
|
|
56
|
-
charset = options[:charset]
|
57
49
|
charset ||= :default if mime_type.start_with?('text/')
|
58
50
|
charset = EncodingUtils::CHARSET_DETECT[charset] if charset.is_a?(Symbol)
|
59
51
|
|
60
|
-
self.computed_config = {}
|
61
|
-
|
62
52
|
self.config = hash_reassoc(config, :mime_exts) do |mime_exts|
|
63
53
|
extnames.each do |extname|
|
64
54
|
mime_exts[extname] = mime_type
|
@@ -97,34 +87,10 @@ module Sprockets
|
|
97
87
|
data = File.binread(filename)
|
98
88
|
|
99
89
|
if detect = mime_type_charset_detecter(content_type)
|
100
|
-
detect.call(data).encode(Encoding::UTF_8, :
|
90
|
+
detect.call(data).encode(Encoding::UTF_8, universal_newline: true)
|
101
91
|
else
|
102
92
|
data
|
103
93
|
end
|
104
94
|
end
|
105
|
-
|
106
|
-
private
|
107
|
-
def extname_map
|
108
|
-
self.computed_config[:_extnames] ||= compute_extname_map
|
109
|
-
end
|
110
|
-
|
111
|
-
def compute_extname_map
|
112
|
-
graph = {}
|
113
|
-
|
114
|
-
([nil] + pipelines.keys.map(&:to_s)).each do |pipeline|
|
115
|
-
pipeline_extname = ".#{pipeline}" if pipeline
|
116
|
-
([[nil, nil]] + config[:mime_exts].to_a).each do |format_extname, format_type|
|
117
|
-
4.times do |n|
|
118
|
-
config[:engines].keys.permutation(n).each do |engine_extnames|
|
119
|
-
key = "#{pipeline_extname}#{format_extname}#{engine_extnames.join}"
|
120
|
-
type = format_type || config[:engine_mime_types][engine_extnames.first]
|
121
|
-
graph[key] = {type: type, engines: engine_extnames, pipeline: pipeline}
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
graph
|
128
|
-
end
|
129
95
|
end
|
130
96
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Sprockets
|
5
|
+
module Npm
|
6
|
+
# Internal: Override resolve_alternates to install package.json behavior.
|
7
|
+
#
|
8
|
+
# load_path - String environment path
|
9
|
+
# logical_path - String path relative to base
|
10
|
+
#
|
11
|
+
# Returns candiate filenames.
|
12
|
+
def resolve_alternates(load_path, logical_path)
|
13
|
+
candidates, deps = super
|
14
|
+
|
15
|
+
dirname = File.join(load_path, logical_path)
|
16
|
+
|
17
|
+
if directory?(dirname)
|
18
|
+
filename = File.join(dirname, 'package.json')
|
19
|
+
|
20
|
+
if self.file?(filename)
|
21
|
+
deps << build_file_digest_uri(filename)
|
22
|
+
read_package_directives(dirname, filename) do |path|
|
23
|
+
if file?(path)
|
24
|
+
candidates << path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
return candidates, deps
|
31
|
+
end
|
32
|
+
|
33
|
+
# Internal: Read package.json's main and style directives.
|
34
|
+
#
|
35
|
+
# dirname - String path to component directory.
|
36
|
+
# filename - String path to package.json.
|
37
|
+
#
|
38
|
+
# Returns nothing.
|
39
|
+
def read_package_directives(dirname, filename)
|
40
|
+
package = JSON.parse(File.read(filename), create_additions: false)
|
41
|
+
|
42
|
+
case package['main']
|
43
|
+
when String
|
44
|
+
yield File.expand_path(package['main'], dirname)
|
45
|
+
when nil
|
46
|
+
yield File.expand_path('index.js', dirname)
|
47
|
+
end
|
48
|
+
|
49
|
+
yield File.expand_path(package['style'], dirname) if package['style']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'set'
|
2
3
|
require 'sprockets/path_utils'
|
3
4
|
require 'sprockets/uri_utils'
|
@@ -41,7 +42,7 @@ module Sprockets
|
|
41
42
|
#
|
42
43
|
# Returns an Array of entry names and a Set of dependency URIs.
|
43
44
|
def entries_with_dependencies(path)
|
44
|
-
return entries(path),
|
45
|
+
return entries(path), Set.new([build_file_digest_uri(path)])
|
45
46
|
end
|
46
47
|
|
47
48
|
# Internal: List directory filenames and associated Stats under a
|
@@ -53,16 +54,7 @@ module Sprockets
|
|
53
54
|
#
|
54
55
|
# Returns an Array of filenames and a Set of dependency URIs.
|
55
56
|
def stat_directory_with_dependencies(dir)
|
56
|
-
return stat_directory(dir).to_a,
|
57
|
-
end
|
58
|
-
|
59
|
-
# Internal: Returns a set of dependencies for a particular path.
|
60
|
-
#
|
61
|
-
# path - String directory path
|
62
|
-
#
|
63
|
-
# Returns a Set of dependency URIs.
|
64
|
-
def file_digest_dependency_set(path)
|
65
|
-
Set.new([build_file_digest_uri(path)])
|
57
|
+
return stat_directory(dir).to_a, Set.new([build_file_digest_uri(dir)])
|
66
58
|
end
|
67
59
|
|
68
60
|
# Internal: List directory filenames and associated Stats under an entire
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/digest_utils'
|
2
3
|
require 'sprockets/path_utils'
|
3
4
|
|
@@ -15,7 +16,7 @@ module Sprockets
|
|
15
16
|
def stat_digest(path, stat)
|
16
17
|
if stat.directory?
|
17
18
|
# If its a directive, digest the list of filenames
|
18
|
-
digest_class.digest(self.entries(path).join(','))
|
19
|
+
digest_class.digest(self.entries(path).join(','.freeze))
|
19
20
|
elsif stat.file?
|
20
21
|
# If its a file, digest the contents
|
21
22
|
digest_class.file(path.to_s).digest
|
data/lib/sprockets/path_utils.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
3
2
|
module Sprockets
|
4
3
|
# Internal: File and path related utilities. Mixed into Environment.
|
5
4
|
#
|
@@ -7,6 +6,7 @@ module Sprockets
|
|
7
6
|
# when code actually wants to reference ::FileUtils.
|
8
7
|
module PathUtils
|
9
8
|
extend self
|
9
|
+
require 'pathname'
|
10
10
|
|
11
11
|
# Public: Like `File.stat`.
|
12
12
|
#
|
@@ -55,9 +55,14 @@ module Sprockets
|
|
55
55
|
# Returns an empty `Array` if the directory does not exist.
|
56
56
|
def entries(path)
|
57
57
|
if File.directory?(path)
|
58
|
-
Dir.entries(path, :
|
59
|
-
|
60
|
-
|
58
|
+
entries = Dir.entries(path, encoding: Encoding.default_internal)
|
59
|
+
entries.reject! { |entry|
|
60
|
+
entry.start_with?(".".freeze) ||
|
61
|
+
(entry.start_with?("#".freeze) && entry.end_with?("#".freeze)) ||
|
62
|
+
entry.end_with?("~".freeze)
|
63
|
+
}
|
64
|
+
entries.sort!
|
65
|
+
entries
|
61
66
|
else
|
62
67
|
[]
|
63
68
|
end
|
@@ -69,8 +74,6 @@ module Sprockets
|
|
69
74
|
#
|
70
75
|
# Returns true if path is absolute, otherwise false.
|
71
76
|
if File::ALT_SEPARATOR
|
72
|
-
require 'pathname'
|
73
|
-
|
74
77
|
# On Windows, ALT_SEPARATOR is \
|
75
78
|
# Delegate to Pathname since the logic gets complex.
|
76
79
|
def absolute_path?(path)
|
@@ -78,7 +81,7 @@ module Sprockets
|
|
78
81
|
end
|
79
82
|
else
|
80
83
|
def absolute_path?(path)
|
81
|
-
path
|
84
|
+
path.start_with?(File::SEPARATOR)
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
@@ -95,7 +98,58 @@ module Sprockets
|
|
95
98
|
#
|
96
99
|
# Returns true if path is relative, otherwise false.
|
97
100
|
def relative_path?(path)
|
98
|
-
path
|
101
|
+
path.match?(/^\.\.?($|#{SEPARATOR_PATTERN})/) ? true : false
|
102
|
+
end
|
103
|
+
|
104
|
+
# Public: Get relative path from `start` to `dest`.
|
105
|
+
#
|
106
|
+
# start - String start path (file or dir)
|
107
|
+
# dest - String destination path
|
108
|
+
#
|
109
|
+
# Returns relative String path from `start` to `dest`
|
110
|
+
def relative_path_from(start, dest)
|
111
|
+
start, dest = Pathname.new(start), Pathname.new(dest)
|
112
|
+
start = start.dirname unless start.directory?
|
113
|
+
dest.relative_path_from(start).to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
# Public: Joins path to base path.
|
117
|
+
#
|
118
|
+
# base - Root path
|
119
|
+
# path - Extending path
|
120
|
+
#
|
121
|
+
# Example
|
122
|
+
#
|
123
|
+
# join('base/path/', '../file.js')
|
124
|
+
# # => 'base/file.js'
|
125
|
+
#
|
126
|
+
# Returns string path starting from base and ending at path
|
127
|
+
def join(base, path)
|
128
|
+
(Pathname.new(base) + path).to_s
|
129
|
+
end
|
130
|
+
|
131
|
+
# Public: Sets pipeline for path
|
132
|
+
#
|
133
|
+
# path - String path
|
134
|
+
# extensions - List of file extensions
|
135
|
+
# pipeline - Pipeline
|
136
|
+
#
|
137
|
+
# Examples
|
138
|
+
#
|
139
|
+
# set_pipeline('path/file.js.erb', config[:mime_exts], config[:pipeline_exts], :source)
|
140
|
+
# # => 'path/file.source.js.erb'
|
141
|
+
#
|
142
|
+
# set_pipeline('path/some.file.source.js.erb', config[:mime_exts], config[:pipeline_exts], :debug)
|
143
|
+
# # => 'path/some.file.debug.js.erb'
|
144
|
+
#
|
145
|
+
# Returns string path with pipeline parsed in
|
146
|
+
def set_pipeline(path, mime_exts, pipeline_exts, pipeline)
|
147
|
+
extension, _ = match_path_extname(path, mime_exts)
|
148
|
+
path.chomp!(extension)
|
149
|
+
pipeline_old, _ = match_path_extname(path, pipeline_exts)
|
150
|
+
path.chomp!(pipeline_old)
|
151
|
+
|
152
|
+
"#{path}.#{pipeline}#{extension}"
|
99
153
|
end
|
100
154
|
|
101
155
|
# Internal: Get relative path for root path and subpath.
|
@@ -107,7 +161,7 @@ module Sprockets
|
|
107
161
|
# subpath is outside of path.
|
108
162
|
def split_subpath(path, subpath)
|
109
163
|
return "" if path == subpath
|
110
|
-
path = File.join(path, '')
|
164
|
+
path = File.join(path, ''.freeze)
|
111
165
|
if subpath.start_with?(path)
|
112
166
|
subpath[path.length..-1]
|
113
167
|
else
|
@@ -146,16 +200,47 @@ module Sprockets
|
|
146
200
|
#
|
147
201
|
# Returns [String extname, Object value] or nil nothing matched.
|
148
202
|
def match_path_extname(path, extensions)
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
203
|
+
basename = File.basename(path)
|
204
|
+
|
205
|
+
i = basename.index('.'.freeze)
|
206
|
+
while i && i < basename.length - 1
|
207
|
+
extname = basename[i..-1]
|
208
|
+
if value = extensions[extname]
|
209
|
+
return extname, value
|
210
|
+
end
|
211
|
+
|
212
|
+
i = basename.index('.'.freeze, i+1)
|
213
|
+
end
|
214
|
+
|
215
|
+
nil
|
216
|
+
end
|
217
|
+
|
218
|
+
# Internal: Match paths in a directory against available extensions.
|
219
|
+
#
|
220
|
+
# path - String directory
|
221
|
+
# basename - String basename of target file
|
222
|
+
# extensions - Hash of String extnames to values
|
223
|
+
#
|
224
|
+
# Examples
|
225
|
+
#
|
226
|
+
# exts = { ".js" => "application/javascript" }
|
227
|
+
# find_matching_path_for_extensions("app/assets", "application", exts)
|
228
|
+
# # => ["app/assets/application.js", "application/javascript"]
|
229
|
+
#
|
230
|
+
# Returns an Array of [String path, Object value] matches.
|
231
|
+
def find_matching_path_for_extensions(path, basename, extensions)
|
232
|
+
matches = []
|
233
|
+
entries(path).each do |entry|
|
234
|
+
next unless File.basename(entry).start_with?(basename)
|
235
|
+
extname, value = match_path_extname(entry, extensions)
|
236
|
+
if basename == entry.chomp(extname)
|
237
|
+
filename = File.join(path, entry)
|
238
|
+
if file?(filename)
|
239
|
+
matches << [filename, value]
|
240
|
+
end
|
156
241
|
end
|
157
242
|
end
|
158
|
-
|
243
|
+
matches
|
159
244
|
end
|
160
245
|
|
161
246
|
# Internal: Returns all parents for path
|
@@ -267,16 +352,16 @@ module Sprockets
|
|
267
352
|
Thread.current.object_id,
|
268
353
|
Process.pid,
|
269
354
|
rand(1000000)
|
270
|
-
].join('.')
|
355
|
+
].join('.'.freeze)
|
271
356
|
tmpname = File.join(dirname, basename)
|
272
357
|
|
273
358
|
File.open(tmpname, 'wb+') do |f|
|
274
359
|
yield f
|
275
360
|
end
|
276
361
|
|
277
|
-
|
362
|
+
File.rename(tmpname, filename)
|
278
363
|
ensure
|
279
|
-
|
364
|
+
File.delete(tmpname) if File.exist?(tmpname)
|
280
365
|
end
|
281
366
|
end
|
282
367
|
end
|
data/lib/sprockets/paths.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Sprockets
|
3
|
+
module Preprocessors
|
4
|
+
# Private: Adds a default map to assets when one is not present
|
5
|
+
#
|
6
|
+
# If the input file already has a source map, it effectively returns the original
|
7
|
+
# result. Otherwise it maps 1 for 1 lines original to generated. This is needed
|
8
|
+
# Because other generators run after might depend on having a valid source map
|
9
|
+
# available.
|
10
|
+
class DefaultSourceMap
|
11
|
+
def call(input)
|
12
|
+
result = { data: input[:data] }
|
13
|
+
map = input[:metadata][:map]
|
14
|
+
filename = input[:filename]
|
15
|
+
load_path = input[:load_path]
|
16
|
+
lines = input[:data].lines.length
|
17
|
+
basename = File.basename(filename)
|
18
|
+
mime_exts = input[:environment].config[:mime_exts]
|
19
|
+
pipeline_exts = input[:environment].config[:pipeline_exts]
|
20
|
+
if map.nil? || map.empty?
|
21
|
+
result[:map] = {
|
22
|
+
"version" => 3,
|
23
|
+
"file" => PathUtils.split_subpath(load_path, filename),
|
24
|
+
"mappings" => default_mappings(lines),
|
25
|
+
"sources" => [PathUtils.set_pipeline(basename, mime_exts, pipeline_exts, :source)],
|
26
|
+
"names" => []
|
27
|
+
}
|
28
|
+
else
|
29
|
+
result[:map] = map
|
30
|
+
end
|
31
|
+
|
32
|
+
result[:map]["x_sprockets_linecount"] = lines
|
33
|
+
return result
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def default_mappings(lines)
|
39
|
+
if (lines == 0)
|
40
|
+
""
|
41
|
+
elsif (lines == 1)
|
42
|
+
"AAAA"
|
43
|
+
else
|
44
|
+
"AAAA;" + "AACA;"*(lines - 2) + "AACA"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/sprockets/processing.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
require 'sprockets/file_reader'
|
3
|
-
require 'sprockets/legacy_proc_processor'
|
4
|
-
require 'sprockets/legacy_tilt_processor'
|
5
3
|
require 'sprockets/mime'
|
6
4
|
require 'sprockets/processor_utils'
|
7
5
|
require 'sprockets/uri_utils'
|
@@ -17,9 +15,14 @@ module Sprockets
|
|
17
15
|
config[:pipelines]
|
18
16
|
end
|
19
17
|
|
18
|
+
# Registers a pipeline that will be called by `call_processor` method.
|
20
19
|
def register_pipeline(name, proc = nil, &block)
|
21
20
|
proc ||= block
|
22
21
|
|
22
|
+
self.config = hash_reassoc(config, :pipeline_exts) do |pipeline_exts|
|
23
|
+
pipeline_exts.merge(".#{name}".freeze => name.to_sym)
|
24
|
+
end
|
25
|
+
|
23
26
|
self.config = hash_reassoc(config, :pipelines) do |pipelines|
|
24
27
|
pipelines.merge(name.to_sym => proc)
|
25
28
|
end
|
@@ -43,12 +46,13 @@ module Sprockets
|
|
43
46
|
#
|
44
47
|
# A block can be passed for to create a shorthand processor.
|
45
48
|
#
|
46
|
-
# register_preprocessor 'text/css'
|
47
|
-
# data.gsub(...)
|
49
|
+
# register_preprocessor 'text/css' do |input|
|
50
|
+
# input[:data].gsub(...)
|
48
51
|
# end
|
49
52
|
#
|
50
53
|
def register_preprocessor(*args, &block)
|
51
54
|
register_config_processor(:preprocessors, *args, &block)
|
55
|
+
compute_transformers!(self.config[:registered_transformers])
|
52
56
|
end
|
53
57
|
alias_method :register_processor, :register_preprocessor
|
54
58
|
|
@@ -58,12 +62,13 @@ module Sprockets
|
|
58
62
|
#
|
59
63
|
# A block can be passed for to create a shorthand processor.
|
60
64
|
#
|
61
|
-
# register_postprocessor 'application/javascript'
|
62
|
-
# data.gsub(...)
|
65
|
+
# register_postprocessor 'application/javascript' do |input|
|
66
|
+
# input[:data].gsub(...)
|
63
67
|
# end
|
64
68
|
#
|
65
69
|
def register_postprocessor(*args, &block)
|
66
70
|
register_config_processor(:postprocessors, *args, &block)
|
71
|
+
compute_transformers!(self.config[:registered_transformers])
|
67
72
|
end
|
68
73
|
|
69
74
|
# Remove Preprocessor `klass` for `mime_type`.
|
@@ -72,6 +77,7 @@ module Sprockets
|
|
72
77
|
#
|
73
78
|
def unregister_preprocessor(*args)
|
74
79
|
unregister_config_processor(:preprocessors, *args)
|
80
|
+
compute_transformers!(self.config[:registered_transformers])
|
75
81
|
end
|
76
82
|
alias_method :unregister_processor, :unregister_preprocessor
|
77
83
|
|
@@ -81,6 +87,7 @@ module Sprockets
|
|
81
87
|
#
|
82
88
|
def unregister_postprocessor(*args)
|
83
89
|
unregister_config_processor(:postprocessors, *args)
|
90
|
+
compute_transformers!(self.config[:registered_transformers])
|
84
91
|
end
|
85
92
|
|
86
93
|
# Bundle Processors are ran on concatenated assets rather than
|
@@ -95,8 +102,8 @@ module Sprockets
|
|
95
102
|
#
|
96
103
|
# A block can be passed for to create a shorthand processor.
|
97
104
|
#
|
98
|
-
# register_bundle_processor 'application/javascript'
|
99
|
-
# data.gsub(...)
|
105
|
+
# register_bundle_processor 'application/javascript' do |input|
|
106
|
+
# input[:data].gsub(...)
|
100
107
|
# end
|
101
108
|
#
|
102
109
|
def register_bundle_processor(*args, &block)
|
@@ -154,46 +161,44 @@ module Sprockets
|
|
154
161
|
protected
|
155
162
|
def resolve_processors_cache_key_uri(uri)
|
156
163
|
params = parse_uri_query_params(uri[11..-1])
|
157
|
-
|
158
|
-
processors = processors_for(params[:type], params[:file_type], params[:engine_extnames], params[:pipeline])
|
164
|
+
processors = processors_for(params[:type], params[:file_type], params[:pipeline])
|
159
165
|
processors_cache_keys(processors)
|
160
166
|
end
|
161
167
|
|
162
|
-
def build_processors_uri(type, file_type,
|
163
|
-
engines = engine_extnames.join(',') if engine_extnames.any?
|
168
|
+
def build_processors_uri(type, file_type, pipeline)
|
164
169
|
query = encode_uri_query_params(
|
165
170
|
type: type,
|
166
171
|
file_type: file_type,
|
167
|
-
engines: engines,
|
168
172
|
pipeline: pipeline
|
169
173
|
)
|
170
174
|
"processors:#{query}"
|
171
175
|
end
|
172
176
|
|
173
|
-
def processors_for(type, file_type,
|
177
|
+
def processors_for(type, file_type, pipeline)
|
174
178
|
pipeline ||= :default
|
175
|
-
config[:pipelines][pipeline.to_sym]
|
179
|
+
if fn = config[:pipelines][pipeline.to_sym]
|
180
|
+
fn.call(self, type, file_type)
|
181
|
+
else
|
182
|
+
raise Error, "no pipeline: #{pipeline}"
|
183
|
+
end
|
176
184
|
end
|
177
185
|
|
178
|
-
def default_processors_for(type, file_type
|
186
|
+
def default_processors_for(type, file_type)
|
179
187
|
bundled_processors = config[:bundle_processors][type]
|
180
188
|
if bundled_processors.any?
|
181
189
|
bundled_processors
|
182
190
|
else
|
183
|
-
self_processors_for(type, file_type
|
191
|
+
self_processors_for(type, file_type)
|
184
192
|
end
|
185
193
|
end
|
186
194
|
|
187
|
-
def self_processors_for(type, file_type
|
195
|
+
def self_processors_for(type, file_type)
|
188
196
|
processors = []
|
189
197
|
|
190
198
|
processors.concat config[:postprocessors][type]
|
191
|
-
|
192
199
|
if type != file_type && processor = config[:transformers][file_type][type]
|
193
200
|
processors << processor
|
194
201
|
end
|
195
|
-
|
196
|
-
processors.concat engine_extnames.map { |ext| engines[ext] }
|
197
202
|
processors.concat config[:preprocessors][file_type]
|
198
203
|
|
199
204
|
if processors.any? || mime_type_charset_detecter(type)
|
@@ -204,45 +209,20 @@ module Sprockets
|
|
204
209
|
end
|
205
210
|
|
206
211
|
private
|
207
|
-
def register_config_processor(type, mime_type,
|
208
|
-
|
209
|
-
processor = wrap_processor(klass, proc)
|
212
|
+
def register_config_processor(type, mime_type, processor = nil, &block)
|
213
|
+
processor ||= block
|
210
214
|
|
211
215
|
self.config = hash_reassoc(config, type, mime_type) do |processors|
|
212
216
|
processors.unshift(processor)
|
213
217
|
processors
|
214
218
|
end
|
215
|
-
|
216
|
-
compute_transformers!
|
217
219
|
end
|
218
220
|
|
219
|
-
def unregister_config_processor(type, mime_type,
|
220
|
-
if klass.is_a?(String) || klass.is_a?(Symbol)
|
221
|
-
klass = config[type][mime_type].detect do |cls|
|
222
|
-
cls.respond_to?(:name) && cls.name == "Sprockets::LegacyProcProcessor (#{klass})"
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
221
|
+
def unregister_config_processor(type, mime_type, processor)
|
226
222
|
self.config = hash_reassoc(config, type, mime_type) do |processors|
|
227
|
-
processors.
|
223
|
+
processors.delete_if { |p| p == processor || p.class == processor }
|
228
224
|
processors
|
229
225
|
end
|
230
|
-
|
231
|
-
compute_transformers!
|
232
|
-
end
|
233
|
-
|
234
|
-
def wrap_processor(klass, proc)
|
235
|
-
if !proc
|
236
|
-
if klass.respond_to?(:call)
|
237
|
-
klass
|
238
|
-
else
|
239
|
-
LegacyTiltProcessor.new(klass)
|
240
|
-
end
|
241
|
-
elsif proc.respond_to?(:arity) && proc.arity == 2
|
242
|
-
LegacyProcProcessor.new(klass.to_s, proc)
|
243
|
-
else
|
244
|
-
proc
|
245
|
-
end
|
246
226
|
end
|
247
227
|
end
|
248
228
|
end
|