sprockets 2.2.3 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +68 -0
- data/README.md +482 -255
- data/bin/sprockets +20 -7
- data/lib/rake/sprocketstask.rb +28 -15
- data/lib/sprockets/add_source_map_comment_to_asset_processor.rb +60 -0
- data/lib/sprockets/asset.rb +142 -207
- data/lib/sprockets/autoload/babel.rb +8 -0
- data/lib/sprockets/autoload/closure.rb +8 -0
- data/lib/sprockets/autoload/coffee_script.rb +8 -0
- data/lib/sprockets/autoload/eco.rb +8 -0
- data/lib/sprockets/autoload/ejs.rb +8 -0
- data/lib/sprockets/autoload/jsminc.rb +8 -0
- data/lib/sprockets/autoload/sass.rb +8 -0
- data/lib/sprockets/autoload/sassc.rb +8 -0
- data/lib/sprockets/autoload/uglifier.rb +8 -0
- data/lib/sprockets/autoload/yui.rb +8 -0
- data/lib/sprockets/autoload/zopfli.rb +7 -0
- data/lib/sprockets/autoload.rb +16 -0
- data/lib/sprockets/babel_processor.rb +66 -0
- data/lib/sprockets/base.rb +89 -249
- data/lib/sprockets/bower.rb +61 -0
- data/lib/sprockets/bundle.rb +105 -0
- data/lib/sprockets/cache/file_store.rb +190 -14
- data/lib/sprockets/cache/memory_store.rb +75 -0
- data/lib/sprockets/cache/null_store.rb +54 -0
- data/lib/sprockets/cache.rb +271 -0
- data/lib/sprockets/cached_environment.rb +64 -0
- data/lib/sprockets/closure_compressor.rb +48 -0
- data/lib/sprockets/coffee_script_processor.rb +39 -0
- data/lib/sprockets/compressing.rb +134 -0
- data/lib/sprockets/configuration.rb +79 -0
- data/lib/sprockets/context.rb +204 -135
- data/lib/sprockets/dependencies.rb +74 -0
- data/lib/sprockets/digest_utils.rb +200 -0
- data/lib/sprockets/directive_processor.rb +224 -216
- data/lib/sprockets/eco_processor.rb +33 -0
- data/lib/sprockets/ejs_processor.rb +32 -0
- data/lib/sprockets/encoding_utils.rb +262 -0
- data/lib/sprockets/environment.rb +23 -68
- data/lib/sprockets/erb_processor.rb +37 -0
- data/lib/sprockets/errors.rb +6 -13
- 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 +16 -0
- data/lib/sprockets/http_utils.rb +135 -0
- data/lib/sprockets/jsminc_compressor.rb +32 -0
- data/lib/sprockets/jst_processor.rb +36 -19
- data/lib/sprockets/loader.rb +343 -0
- data/lib/sprockets/manifest.rb +231 -96
- data/lib/sprockets/manifest_utils.rb +48 -0
- data/lib/sprockets/mime.rb +80 -32
- data/lib/sprockets/npm.rb +52 -0
- data/lib/sprockets/path_dependency_utils.rb +77 -0
- data/lib/sprockets/path_digest_utils.rb +48 -0
- data/lib/sprockets/path_utils.rb +367 -0
- data/lib/sprockets/paths.rb +82 -0
- data/lib/sprockets/preprocessors/default_source_map.rb +49 -0
- data/lib/sprockets/processing.rb +140 -192
- data/lib/sprockets/processor_utils.rb +169 -0
- data/lib/sprockets/resolve.rb +295 -0
- data/lib/sprockets/sass_cache_store.rb +30 -0
- data/lib/sprockets/sass_compressor.rb +63 -0
- data/lib/sprockets/sass_functions.rb +3 -0
- data/lib/sprockets/sass_importer.rb +3 -0
- data/lib/sprockets/sass_processor.rb +313 -0
- data/lib/sprockets/sassc_compressor.rb +56 -0
- data/lib/sprockets/sassc_processor.rb +297 -0
- data/lib/sprockets/server.rb +138 -90
- data/lib/sprockets/source_map_processor.rb +66 -0
- data/lib/sprockets/source_map_utils.rb +483 -0
- data/lib/sprockets/transformers.rb +173 -0
- data/lib/sprockets/uglifier_compressor.rb +66 -0
- data/lib/sprockets/unloaded_asset.rb +139 -0
- data/lib/sprockets/uri_tar.rb +99 -0
- data/lib/sprockets/uri_utils.rb +191 -0
- data/lib/sprockets/utils/gzip.rb +99 -0
- data/lib/sprockets/utils.rb +186 -53
- data/lib/sprockets/version.rb +2 -1
- data/lib/sprockets/yui_compressor.rb +56 -0
- data/lib/sprockets.rb +217 -52
- metadata +250 -59
- data/LICENSE +0 -21
- data/lib/sprockets/asset_attributes.rb +0 -126
- data/lib/sprockets/bundled_asset.rb +0 -79
- data/lib/sprockets/caching.rb +0 -96
- data/lib/sprockets/charset_normalizer.rb +0 -41
- data/lib/sprockets/eco_template.rb +0 -38
- data/lib/sprockets/ejs_template.rb +0 -37
- data/lib/sprockets/engines.rb +0 -74
- data/lib/sprockets/index.rb +0 -99
- data/lib/sprockets/processed_asset.rb +0 -152
- data/lib/sprockets/processor.rb +0 -32
- data/lib/sprockets/safety_colons.rb +0 -28
- data/lib/sprockets/static_asset.rb +0 -57
- data/lib/sprockets/trail.rb +0 -90
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'sprockets/autoload'
|
3
|
+
require 'sprockets/digest_utils'
|
4
|
+
|
5
|
+
module Sprockets
|
6
|
+
# Public: Closure Compiler minifier.
|
7
|
+
#
|
8
|
+
# To accept the default options
|
9
|
+
#
|
10
|
+
# environment.register_bundle_processor 'application/javascript',
|
11
|
+
# Sprockets::ClosureCompressor
|
12
|
+
#
|
13
|
+
# Or to pass options to the Closure::Compiler class.
|
14
|
+
#
|
15
|
+
# environment.register_bundle_processor 'application/javascript',
|
16
|
+
# Sprockets::ClosureCompressor.new({ ... })
|
17
|
+
#
|
18
|
+
class ClosureCompressor
|
19
|
+
VERSION = '1'
|
20
|
+
|
21
|
+
# Public: Return singleton instance with default options.
|
22
|
+
#
|
23
|
+
# Returns ClosureCompressor object.
|
24
|
+
def self.instance
|
25
|
+
@instance ||= new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.call(input)
|
29
|
+
instance.call(input)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.cache_key
|
33
|
+
instance.cache_key
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :cache_key
|
37
|
+
|
38
|
+
def initialize(options = {})
|
39
|
+
@options = options
|
40
|
+
@cache_key = "#{self.class.name}:#{Autoload::Closure::VERSION}:#{Autoload::Closure::COMPILER_VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
|
41
|
+
end
|
42
|
+
|
43
|
+
def call(input)
|
44
|
+
@compiler ||= Autoload::Closure::Compiler.new(@options)
|
45
|
+
@compiler.compile(input[:data])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'sprockets/autoload'
|
3
|
+
require 'sprockets/source_map_utils'
|
4
|
+
|
5
|
+
module Sprockets
|
6
|
+
# Processor engine class for the CoffeeScript compiler.
|
7
|
+
# Depends on the `coffee-script` and `coffee-script-source` gems.
|
8
|
+
#
|
9
|
+
# For more infomation see:
|
10
|
+
#
|
11
|
+
# https://github.com/rails/ruby-coffee-script
|
12
|
+
#
|
13
|
+
module CoffeeScriptProcessor
|
14
|
+
VERSION = '2'
|
15
|
+
|
16
|
+
def self.cache_key
|
17
|
+
@cache_key ||= "#{name}:#{Autoload::CoffeeScript::Source.version}:#{VERSION}".freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.call(input)
|
21
|
+
data = input[:data]
|
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'])]
|
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 }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'sprockets/utils'
|
3
|
+
|
4
|
+
module Sprockets
|
5
|
+
# `Compressing` is an internal mixin whose public methods are exposed on
|
6
|
+
# the `Environment` and `CachedEnvironment` classes.
|
7
|
+
module Compressing
|
8
|
+
include Utils
|
9
|
+
|
10
|
+
def compressors
|
11
|
+
config[:compressors]
|
12
|
+
end
|
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.
|
32
|
+
def register_compressor(mime_type, sym, klass)
|
33
|
+
self.config = hash_reassoc(config, :compressors, mime_type) do |compressors|
|
34
|
+
compressors[sym] = klass
|
35
|
+
compressors
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Return CSS compressor or nil if none is set
|
40
|
+
def css_compressor
|
41
|
+
if defined? @css_compressor
|
42
|
+
@css_compressor
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Assign a compressor to run on `text/css` assets.
|
47
|
+
#
|
48
|
+
# The compressor object must respond to `compress`.
|
49
|
+
def css_compressor=(compressor)
|
50
|
+
unregister_bundle_processor 'text/css', @css_compressor if defined? @css_compressor
|
51
|
+
@css_compressor = nil
|
52
|
+
return unless compressor
|
53
|
+
|
54
|
+
if compressor.is_a?(Symbol)
|
55
|
+
@css_compressor = klass = config[:compressors]['text/css'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
56
|
+
elsif compressor.respond_to?(:compress)
|
57
|
+
klass = proc { |input| compressor.compress(input[:data]) }
|
58
|
+
@css_compressor = :css_compressor
|
59
|
+
else
|
60
|
+
@css_compressor = klass = compressor
|
61
|
+
end
|
62
|
+
|
63
|
+
register_bundle_processor 'text/css', klass
|
64
|
+
end
|
65
|
+
|
66
|
+
# Return JS compressor or nil if none is set
|
67
|
+
def js_compressor
|
68
|
+
if defined? @js_compressor
|
69
|
+
@js_compressor
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Assign a compressor to run on `application/javascript` assets.
|
74
|
+
#
|
75
|
+
# The compressor object must respond to `compress`.
|
76
|
+
def js_compressor=(compressor)
|
77
|
+
unregister_bundle_processor 'application/javascript', @js_compressor if defined? @js_compressor
|
78
|
+
@js_compressor = nil
|
79
|
+
return unless compressor
|
80
|
+
|
81
|
+
if compressor.is_a?(Symbol)
|
82
|
+
@js_compressor = klass = config[:compressors]['application/javascript'][compressor] || raise(Error, "unknown compressor: #{compressor}")
|
83
|
+
elsif compressor.respond_to?(:compress)
|
84
|
+
klass = proc { |input| compressor.compress(input[:data]) }
|
85
|
+
@js_compressor = :js_compressor
|
86
|
+
else
|
87
|
+
@js_compressor = klass = compressor
|
88
|
+
end
|
89
|
+
|
90
|
+
register_bundle_processor 'application/javascript', klass
|
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
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'sprockets/compressing'
|
3
|
+
require 'sprockets/dependencies'
|
4
|
+
require 'sprockets/mime'
|
5
|
+
require 'sprockets/paths'
|
6
|
+
require 'sprockets/processing'
|
7
|
+
require 'sprockets/exporting'
|
8
|
+
require 'sprockets/transformers'
|
9
|
+
require 'sprockets/utils'
|
10
|
+
|
11
|
+
module Sprockets
|
12
|
+
module Configuration
|
13
|
+
include Paths, Mime, Transformers, Processing, Exporting, Compressing, Dependencies, Utils
|
14
|
+
|
15
|
+
def initialize_configuration(parent)
|
16
|
+
@config = parent.config
|
17
|
+
@logger = parent.logger
|
18
|
+
@context_class = Class.new(parent.context_class)
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :config
|
22
|
+
|
23
|
+
def config=(config)
|
24
|
+
raise TypeError, "can't assign mutable config" unless config.frozen?
|
25
|
+
@config = config
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get and set `Logger` instance.
|
29
|
+
attr_accessor :logger
|
30
|
+
|
31
|
+
# The `Environment#version` is a custom value used for manually
|
32
|
+
# expiring all asset caches.
|
33
|
+
#
|
34
|
+
# Sprockets is able to track most file and directory changes and
|
35
|
+
# will take care of expiring the cache for you. However, its
|
36
|
+
# impossible to know when any custom helpers change that you mix
|
37
|
+
# into the `Context`.
|
38
|
+
#
|
39
|
+
# It would be wise to increment this value anytime you make a
|
40
|
+
# configuration change to the `Environment` object.
|
41
|
+
def version
|
42
|
+
config[:version]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Assign an environment version.
|
46
|
+
#
|
47
|
+
# environment.version = '2.0'
|
48
|
+
#
|
49
|
+
def version=(version)
|
50
|
+
self.config = hash_reassoc(config, :version) { version.dup }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Public: Returns a `Digest` implementation class.
|
54
|
+
#
|
55
|
+
# Defaults to `Digest::SHA256`.
|
56
|
+
def digest_class
|
57
|
+
config[:digest_class]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Deprecated: Assign a `Digest` implementation class. This maybe any Ruby
|
61
|
+
# `Digest::` implementation such as `Digest::SHA256` or
|
62
|
+
# `Digest::MD5`.
|
63
|
+
#
|
64
|
+
# environment.digest_class = Digest::MD5
|
65
|
+
#
|
66
|
+
def digest_class=(klass)
|
67
|
+
self.config = config.merge(digest_class: klass).freeze
|
68
|
+
end
|
69
|
+
|
70
|
+
# This class maybe mutated and mixed in with custom helpers.
|
71
|
+
#
|
72
|
+
# environment.context_class.instance_eval do
|
73
|
+
# include MyHelpers
|
74
|
+
# def asset_url; end
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
attr_reader :context_class
|
78
|
+
end
|
79
|
+
end
|