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
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'fileutils'
|
2
3
|
require 'logger'
|
3
4
|
require 'sprockets/encoding_utils'
|
@@ -19,7 +20,9 @@ module Sprockets
|
|
19
20
|
class FileStore
|
20
21
|
# Internal: Default key limit for store.
|
21
22
|
DEFAULT_MAX_SIZE = 25 * 1024 * 1024
|
22
|
-
|
23
|
+
EXCLUDED_DIRS = ['.', '..'].freeze
|
24
|
+
GITKEEP_FILES = ['.gitkeep', '.keep'].freeze
|
25
|
+
|
23
26
|
# Internal: Default standard error fatal logger.
|
24
27
|
#
|
25
28
|
# Returns a Logger.
|
@@ -32,11 +35,12 @@ module Sprockets
|
|
32
35
|
# Public: Initialize the cache store.
|
33
36
|
#
|
34
37
|
# root - A String path to a directory to persist cached values to.
|
35
|
-
# max_size - A Integer of the maximum
|
36
|
-
# (default:
|
38
|
+
# max_size - A Integer of the maximum size the store will hold (in bytes).
|
39
|
+
# (default: 25MB).
|
40
|
+
# logger - The logger to which some info will be printed.
|
41
|
+
# (default logger level is FATAL and won't output anything).
|
37
42
|
def initialize(root, max_size = DEFAULT_MAX_SIZE, logger = self.class.default_logger)
|
38
43
|
@root = root
|
39
|
-
@size = find_caches.inject(0) { |n, (_, stat)| n + stat.size }
|
40
44
|
@max_size = max_size
|
41
45
|
@gc_size = max_size * 0.75
|
42
46
|
@logger = logger
|
@@ -107,11 +111,11 @@ module Sprockets
|
|
107
111
|
# Write data
|
108
112
|
PathUtils.atomic_write(path) do |f|
|
109
113
|
f.write(raw)
|
110
|
-
@size
|
114
|
+
@size = size + f.size unless exists
|
111
115
|
end
|
112
116
|
|
113
117
|
# GC if necessary
|
114
|
-
gc! if
|
118
|
+
gc! if size > @max_size
|
115
119
|
|
116
120
|
value
|
117
121
|
end
|
@@ -120,7 +124,24 @@ module Sprockets
|
|
120
124
|
#
|
121
125
|
# Returns String.
|
122
126
|
def inspect
|
123
|
-
"#<#{self.class} size=#{
|
127
|
+
"#<#{self.class} size=#{size}/#{@max_size}>"
|
128
|
+
end
|
129
|
+
|
130
|
+
# Public: Clear the cache
|
131
|
+
#
|
132
|
+
# adapted from ActiveSupport::Cache::FileStore#clear
|
133
|
+
#
|
134
|
+
# Deletes all items from the cache. In this case it deletes all the entries in the specified
|
135
|
+
# file store directory except for .keep or .gitkeep. Be careful which directory is specified
|
136
|
+
# as @root because everything in that directory will be deleted.
|
137
|
+
#
|
138
|
+
# Returns true
|
139
|
+
def clear(options=nil)
|
140
|
+
if File.exist?(@root)
|
141
|
+
root_dirs = Dir.entries(@root).reject { |f| (EXCLUDED_DIRS + GITKEEP_FILES).include?(f) }
|
142
|
+
FileUtils.rm_r(root_dirs.collect{ |f| File.join(@root, f) })
|
143
|
+
end
|
144
|
+
true
|
124
145
|
end
|
125
146
|
|
126
147
|
private
|
@@ -138,6 +159,10 @@ module Sprockets
|
|
138
159
|
}.sort_by { |_, stat| stat.mtime.to_i }
|
139
160
|
end
|
140
161
|
|
162
|
+
def size
|
163
|
+
@size ||= compute_size(find_caches)
|
164
|
+
end
|
165
|
+
|
141
166
|
def compute_size(caches)
|
142
167
|
caches.inject(0) { |sum, (_, stat)| sum + stat.size }
|
143
168
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Sprockets
|
2
3
|
class Cache
|
3
4
|
# Public: Basic in memory LRU cache.
|
@@ -61,6 +62,14 @@ module Sprockets
|
|
61
62
|
def inspect
|
62
63
|
"#<#{self.class} size=#{@cache.size}/#{@max_size}>"
|
63
64
|
end
|
65
|
+
|
66
|
+
# Public: Clear the cache
|
67
|
+
#
|
68
|
+
# Returns true
|
69
|
+
def clear(options=nil)
|
70
|
+
@cache.clear
|
71
|
+
true
|
72
|
+
end
|
64
73
|
end
|
65
74
|
end
|
66
75
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Sprockets
|
2
3
|
class Cache
|
3
4
|
# Public: A compatible cache store that doesn't store anything. Used by
|
@@ -41,6 +42,13 @@ module Sprockets
|
|
41
42
|
def inspect
|
42
43
|
"#<#{self.class}>"
|
43
44
|
end
|
45
|
+
|
46
|
+
# Public: Simulate clearing the cache
|
47
|
+
#
|
48
|
+
# Returns true
|
49
|
+
def clear(options=nil)
|
50
|
+
true
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|
46
54
|
end
|
data/lib/sprockets/cache.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'logger'
|
2
3
|
require 'sprockets/digest_utils'
|
3
4
|
|
@@ -35,6 +36,12 @@ module Sprockets
|
|
35
36
|
#
|
36
37
|
# Returns argument value.
|
37
38
|
#
|
39
|
+
# clear(options)
|
40
|
+
#
|
41
|
+
# Clear the entire cache. Be careful with this method since it could
|
42
|
+
# affect other processes if shared cache is being used.
|
43
|
+
#
|
44
|
+
# The options hash is passed to the underlying cache implementation.
|
38
45
|
class Cache
|
39
46
|
# Builtin cache stores.
|
40
47
|
autoload :FileStore, 'sprockets/cache/file_store'
|
@@ -44,7 +51,7 @@ module Sprockets
|
|
44
51
|
# Internal: Cache key version for this class. Rarely should have to change
|
45
52
|
# unless the cache format radically changes. Will be bump on major version
|
46
53
|
# releases though.
|
47
|
-
VERSION = '
|
54
|
+
VERSION = '4.0.0'
|
48
55
|
|
49
56
|
def self.default_logger
|
50
57
|
logger = Logger.new($stderr)
|
@@ -60,7 +67,7 @@ module Sprockets
|
|
60
67
|
# cache - A compatible backend cache store instance.
|
61
68
|
def initialize(cache = nil, logger = self.class.default_logger)
|
62
69
|
@cache_wrapper = get_cache_wrapper(cache)
|
63
|
-
@fetch_cache = Cache::MemoryStore.new(
|
70
|
+
@fetch_cache = Cache::MemoryStore.new(1024)
|
64
71
|
@logger = logger
|
65
72
|
end
|
66
73
|
|
@@ -97,7 +104,7 @@ module Sprockets
|
|
97
104
|
# Public: Low level API to retrieve item directly from the backend cache
|
98
105
|
# store.
|
99
106
|
#
|
100
|
-
# This API may be used
|
107
|
+
# This API may be used publicly, but may have undefined behavior
|
101
108
|
# depending on the backend store being used. Prefer the
|
102
109
|
# Cache#fetch API over using this.
|
103
110
|
#
|
@@ -120,7 +127,7 @@ module Sprockets
|
|
120
127
|
|
121
128
|
# Public: Low level API to set item directly to the backend cache store.
|
122
129
|
#
|
123
|
-
# This API may be used
|
130
|
+
# This API may be used publicly, but may have undefined behavior
|
124
131
|
# depending on the backend store being used. Prefer the
|
125
132
|
# Cache#fetch API over using this.
|
126
133
|
#
|
@@ -143,6 +150,14 @@ module Sprockets
|
|
143
150
|
"#<#{self.class} local=#{@fetch_cache.inspect} store=#{@cache_wrapper.cache.inspect}>"
|
144
151
|
end
|
145
152
|
|
153
|
+
# Public: Clear cache
|
154
|
+
#
|
155
|
+
# Returns truthy on success, potentially raises exception on failure
|
156
|
+
def clear(options=nil)
|
157
|
+
@cache_wrapper.clear
|
158
|
+
@fetch_cache.clear
|
159
|
+
end
|
160
|
+
|
146
161
|
private
|
147
162
|
# Internal: Expand object cache key into a short String key.
|
148
163
|
#
|
@@ -153,7 +168,9 @@ module Sprockets
|
|
153
168
|
#
|
154
169
|
# Returns a String with a length less than 250 characters.
|
155
170
|
def expand_key(key)
|
156
|
-
|
171
|
+
digest_key = DigestUtils.pack_urlsafe_base64digest(DigestUtils.digest(key))
|
172
|
+
namespace = digest_key[0, 2]
|
173
|
+
"sprockets/v#{VERSION}/#{namespace}/#{digest_key}"
|
157
174
|
end
|
158
175
|
|
159
176
|
PEEK_SIZE = 100
|
@@ -209,6 +226,16 @@ module Sprockets
|
|
209
226
|
def set(key, value)
|
210
227
|
cache.set(key, value)
|
211
228
|
end
|
229
|
+
|
230
|
+
def clear(options=nil)
|
231
|
+
# dalli has a #flush method so try it
|
232
|
+
if cache.respond_to?(:flush)
|
233
|
+
cache.flush(options)
|
234
|
+
else
|
235
|
+
cache.clear(options)
|
236
|
+
end
|
237
|
+
true
|
238
|
+
end
|
212
239
|
end
|
213
240
|
|
214
241
|
class HashWrapper < Wrapper
|
@@ -219,6 +246,11 @@ module Sprockets
|
|
219
246
|
def set(key, value)
|
220
247
|
cache[key] = value
|
221
248
|
end
|
249
|
+
|
250
|
+
def clear(options=nil)
|
251
|
+
cache.clear
|
252
|
+
true
|
253
|
+
end
|
222
254
|
end
|
223
255
|
|
224
256
|
class ReadWriteWrapper < Wrapper
|
@@ -229,6 +261,11 @@ module Sprockets
|
|
229
261
|
def set(key, value)
|
230
262
|
cache.write(key, value)
|
231
263
|
end
|
264
|
+
|
265
|
+
def clear(options=nil)
|
266
|
+
cache.clear(options)
|
267
|
+
true
|
268
|
+
end
|
232
269
|
end
|
233
270
|
end
|
234
271
|
end
|
@@ -1,26 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/base'
|
2
3
|
|
3
4
|
module Sprockets
|
4
|
-
# `
|
5
|
+
# `CachedEnvironment` is a special cached version of `Environment`.
|
5
6
|
#
|
6
7
|
# The expection is that all of its file system methods are cached
|
7
|
-
# for the instances lifetime. This makes `
|
8
|
+
# for the instances lifetime. This makes `CachedEnvironment` much faster. This
|
8
9
|
# behavior is ideal in production environments where the file system
|
9
10
|
# is immutable.
|
10
11
|
#
|
11
|
-
# `
|
12
|
+
# `CachedEnvironment` should not be initialized directly. Instead use
|
12
13
|
# `Environment#cached`.
|
13
14
|
class CachedEnvironment < Base
|
14
15
|
def initialize(environment)
|
15
16
|
initialize_configuration(environment)
|
16
17
|
|
17
18
|
@cache = environment.cache
|
18
|
-
@stats =
|
19
|
-
@entries =
|
20
|
-
@uris =
|
21
|
-
|
22
|
-
@
|
23
|
-
@resolved_dependencies = Hash.new { |h, k| h[k] = _resolve_dependency(k) }
|
19
|
+
@stats = {}
|
20
|
+
@entries = {}
|
21
|
+
@uris = {}
|
22
|
+
@processor_cache_keys = {}
|
23
|
+
@resolved_dependencies = {}
|
24
24
|
end
|
25
25
|
|
26
26
|
# No-op return self as cached environment.
|
@@ -30,33 +30,28 @@ module Sprockets
|
|
30
30
|
alias_method :index, :cached
|
31
31
|
|
32
32
|
# Internal: Cache Environment#entries
|
33
|
-
alias_method :_entries, :entries
|
34
33
|
def entries(path)
|
35
|
-
@entries[path]
|
34
|
+
@entries[path] ||= super(path)
|
36
35
|
end
|
37
36
|
|
38
37
|
# Internal: Cache Environment#stat
|
39
|
-
alias_method :_stat, :stat
|
40
38
|
def stat(path)
|
41
|
-
@stats[path]
|
39
|
+
@stats[path] ||= super(path)
|
42
40
|
end
|
43
41
|
|
44
42
|
# Internal: Cache Environment#load
|
45
|
-
alias_method :_load, :load
|
46
43
|
def load(uri)
|
47
|
-
@uris[uri]
|
44
|
+
@uris[uri] ||= super(uri)
|
48
45
|
end
|
49
46
|
|
50
47
|
# Internal: Cache Environment#processor_cache_key
|
51
|
-
alias_method :_processor_cache_key, :processor_cache_key
|
52
48
|
def processor_cache_key(str)
|
53
|
-
@processor_cache_keys[str]
|
49
|
+
@processor_cache_keys[str] ||= super(str)
|
54
50
|
end
|
55
51
|
|
56
52
|
# Internal: Cache Environment#resolve_dependency
|
57
|
-
alias_method :_resolve_dependency, :resolve_dependency
|
58
53
|
def resolve_dependency(str)
|
59
|
-
@resolved_dependencies[str]
|
54
|
+
@resolved_dependencies[str] ||= super(str)
|
60
55
|
end
|
61
56
|
|
62
57
|
private
|
@@ -1,4 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/autoload'
|
3
|
+
require 'sprockets/digest_utils'
|
2
4
|
|
3
5
|
module Sprockets
|
4
6
|
# Public: Closure Compiler minifier.
|
@@ -34,20 +36,13 @@ module Sprockets
|
|
34
36
|
attr_reader :cache_key
|
35
37
|
|
36
38
|
def initialize(options = {})
|
37
|
-
@
|
38
|
-
@cache_key =
|
39
|
-
self.class.name,
|
40
|
-
Autoload::Closure::VERSION,
|
41
|
-
Autoload::Closure::COMPILER_VERSION,
|
42
|
-
VERSION,
|
43
|
-
options
|
44
|
-
].freeze
|
39
|
+
@options = options
|
40
|
+
@cache_key = "#{self.class.name}:#{Autoload::Closure::VERSION}:#{Autoload::Closure::COMPILER_VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
|
45
41
|
end
|
46
42
|
|
47
43
|
def call(input)
|
48
|
-
|
49
|
-
|
50
|
-
end
|
44
|
+
@compiler ||= Autoload::Closure::Compiler.new(@options)
|
45
|
+
@compiler.compile(input[:data])
|
51
46
|
end
|
52
47
|
end
|
53
48
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/autoload'
|
3
|
+
require 'sprockets/source_map_utils'
|
2
4
|
|
3
5
|
module Sprockets
|
4
6
|
# Processor engine class for the CoffeeScript compiler.
|
@@ -6,20 +8,32 @@ module Sprockets
|
|
6
8
|
#
|
7
9
|
# For more infomation see:
|
8
10
|
#
|
9
|
-
# https://github.com/
|
11
|
+
# https://github.com/rails/ruby-coffee-script
|
10
12
|
#
|
11
13
|
module CoffeeScriptProcessor
|
12
|
-
VERSION = '
|
14
|
+
VERSION = '2'
|
13
15
|
|
14
16
|
def self.cache_key
|
15
|
-
@cache_key ||=
|
17
|
+
@cache_key ||= "#{name}:#{Autoload::CoffeeScript::Source.version}:#{VERSION}".freeze
|
16
18
|
end
|
17
19
|
|
18
20
|
def self.call(input)
|
19
21
|
data = input[:data]
|
20
|
-
|
21
|
-
|
22
|
+
|
23
|
+
js, map = input[:cache].fetch([self.cache_key, data]) do
|
24
|
+
result = Autoload::CoffeeScript.compile(
|
25
|
+
data,
|
26
|
+
sourceMap: "v3",
|
27
|
+
sourceFiles: [File.basename(input[:filename])],
|
28
|
+
generatedFile: input[:filename]
|
29
|
+
)
|
30
|
+
[result['js'], JSON.parse(result['v3SourceMap'])]
|
22
31
|
end
|
32
|
+
|
33
|
+
map = SourceMapUtils.format_source_map(map, input)
|
34
|
+
map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
|
35
|
+
|
36
|
+
{ data: js, map: map }
|
23
37
|
end
|
24
38
|
end
|
25
39
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/utils'
|
2
3
|
|
3
4
|
module Sprockets
|
@@ -10,6 +11,24 @@ module Sprockets
|
|
10
11
|
config[:compressors]
|
11
12
|
end
|
12
13
|
|
14
|
+
# Public: Register a new compressor `klass` at `sym` for `mime_type`.
|
15
|
+
#
|
16
|
+
# Registering a processor allows it to be looked up by `sym` later when
|
17
|
+
# assigning a JavaScript or CSS compressor.
|
18
|
+
#
|
19
|
+
# Compressors only operate on JavaScript and CSS. If you want to compress a
|
20
|
+
# different type of asset, use a processor instead.
|
21
|
+
#
|
22
|
+
# Examples
|
23
|
+
#
|
24
|
+
# register_compressor 'text/css', :my_sass, MySassCompressor
|
25
|
+
# css_compressor = :my_sass
|
26
|
+
#
|
27
|
+
# mime_type - String MIME Type (one of: 'test/css' or 'application/javascript').
|
28
|
+
# sym - Symbol registration address.
|
29
|
+
# klass - The compressor class.
|
30
|
+
#
|
31
|
+
# Returns nothing.
|
13
32
|
def register_compressor(mime_type, sym, klass)
|
14
33
|
self.config = hash_reassoc(config, :compressors, mime_type) do |compressors|
|
15
34
|
compressors[sym] = klass
|
@@ -35,7 +54,7 @@ module Sprockets
|
|
35
54
|
if compressor.is_a?(Symbol)
|
36
55
|
@css_compressor = klass = config[:compressors]['text/css'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
37
56
|
elsif compressor.respond_to?(:compress)
|
38
|
-
klass =
|
57
|
+
klass = proc { |input| compressor.compress(input[:data]) }
|
39
58
|
@css_compressor = :css_compressor
|
40
59
|
else
|
41
60
|
@css_compressor = klass = compressor
|
@@ -62,7 +81,7 @@ module Sprockets
|
|
62
81
|
if compressor.is_a?(Symbol)
|
63
82
|
@js_compressor = klass = config[:compressors]['application/javascript'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
64
83
|
elsif compressor.respond_to?(:compress)
|
65
|
-
klass =
|
84
|
+
klass = proc { |input| compressor.compress(input[:data]) }
|
66
85
|
@js_compressor = :js_compressor
|
67
86
|
else
|
68
87
|
@js_compressor = klass = compressor
|
@@ -70,5 +89,46 @@ module Sprockets
|
|
70
89
|
|
71
90
|
register_bundle_processor 'application/javascript', klass
|
72
91
|
end
|
92
|
+
|
93
|
+
# Public: Checks if Gzip is enabled.
|
94
|
+
def gzip?
|
95
|
+
config[:gzip_enabled]
|
96
|
+
end
|
97
|
+
|
98
|
+
# Public: Checks if Gzip is disabled.
|
99
|
+
def skip_gzip?
|
100
|
+
!gzip?
|
101
|
+
end
|
102
|
+
|
103
|
+
# Public: Enable or disable the creation of Gzip files.
|
104
|
+
#
|
105
|
+
# To disable gzip generation set to a falsey value:
|
106
|
+
#
|
107
|
+
# environment.gzip = false
|
108
|
+
#
|
109
|
+
# To enable set to a truthy value. By default zlib wil
|
110
|
+
# be used to gzip assets. If you have the Zopfli gem
|
111
|
+
# installed you can specify the zopfli algorithm to be used
|
112
|
+
# instead:
|
113
|
+
#
|
114
|
+
# environment.gzip = :zopfli
|
115
|
+
#
|
116
|
+
def gzip=(gzip)
|
117
|
+
self.config = config.merge(gzip_enabled: gzip).freeze
|
118
|
+
|
119
|
+
case gzip
|
120
|
+
when false, nil
|
121
|
+
self.unregister_exporter Exporters::ZlibExporter
|
122
|
+
self.unregister_exporter Exporters::ZopfliExporter
|
123
|
+
when :zopfli
|
124
|
+
self.unregister_exporter Exporters::ZlibExporter
|
125
|
+
self.register_exporter '*/*', Exporters::ZopfliExporter
|
126
|
+
else
|
127
|
+
self.unregister_exporter Exporters::ZopfliExporter
|
128
|
+
self.register_exporter '*/*', Exporters::ZlibExporter
|
129
|
+
end
|
130
|
+
|
131
|
+
gzip
|
132
|
+
end
|
73
133
|
end
|
74
134
|
end
|
@@ -1,27 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/compressing'
|
2
3
|
require 'sprockets/dependencies'
|
3
|
-
require 'sprockets/engines'
|
4
4
|
require 'sprockets/mime'
|
5
5
|
require 'sprockets/paths'
|
6
6
|
require 'sprockets/processing'
|
7
|
+
require 'sprockets/exporting'
|
7
8
|
require 'sprockets/transformers'
|
8
9
|
require 'sprockets/utils'
|
9
10
|
|
10
11
|
module Sprockets
|
11
12
|
module Configuration
|
12
|
-
include Paths, Mime,
|
13
|
+
include Paths, Mime, Transformers, Processing, Exporting, Compressing, Dependencies, Utils
|
13
14
|
|
14
15
|
def initialize_configuration(parent)
|
15
16
|
@config = parent.config
|
16
|
-
@computed_config = parent.computed_config
|
17
17
|
@logger = parent.logger
|
18
18
|
@context_class = Class.new(parent.context_class)
|
19
19
|
end
|
20
20
|
|
21
21
|
attr_reader :config
|
22
22
|
|
23
|
-
attr_accessor :computed_config
|
24
|
-
|
25
23
|
def config=(config)
|
26
24
|
raise TypeError, "can't assign mutable config" unless config.frozen?
|
27
25
|
@config = config
|
@@ -69,8 +67,6 @@ module Sprockets
|
|
69
67
|
self.config = config.merge(digest_class: klass).freeze
|
70
68
|
end
|
71
69
|
|
72
|
-
# Deprecated: Get `Context` class.
|
73
|
-
#
|
74
70
|
# This class maybe mutated and mixed in with custom helpers.
|
75
71
|
#
|
76
72
|
# environment.context_class.instance_eval do
|