sprockets 2.12.5 → 3.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +296 -0
- data/LICENSE +2 -2
- data/README.md +235 -262
- data/bin/sprockets +1 -0
- data/lib/rake/sprocketstask.rb +5 -4
- data/lib/sprockets/asset.rb +143 -212
- data/lib/sprockets/autoload/closure.rb +7 -0
- data/lib/sprockets/autoload/coffee_script.rb +7 -0
- data/lib/sprockets/autoload/eco.rb +7 -0
- data/lib/sprockets/autoload/ejs.rb +7 -0
- data/lib/sprockets/autoload/sass.rb +7 -0
- data/lib/sprockets/autoload/uglifier.rb +7 -0
- data/lib/sprockets/autoload/yui.rb +7 -0
- data/lib/sprockets/autoload.rb +11 -0
- data/lib/sprockets/base.rb +56 -393
- data/lib/sprockets/bower.rb +58 -0
- data/lib/sprockets/bundle.rb +69 -0
- data/lib/sprockets/cache/file_store.rb +168 -14
- data/lib/sprockets/cache/memory_store.rb +66 -0
- data/lib/sprockets/cache/null_store.rb +46 -0
- data/lib/sprockets/cache.rb +236 -0
- data/lib/sprockets/cached_environment.rb +69 -0
- data/lib/sprockets/closure_compressor.rb +35 -10
- data/lib/sprockets/coffee_script_processor.rb +25 -0
- data/lib/sprockets/coffee_script_template.rb +17 -0
- data/lib/sprockets/compressing.rb +44 -23
- data/lib/sprockets/configuration.rb +83 -0
- data/lib/sprockets/context.rb +86 -144
- data/lib/sprockets/dependencies.rb +73 -0
- data/lib/sprockets/deprecation.rb +90 -0
- data/lib/sprockets/digest_utils.rb +180 -0
- data/lib/sprockets/directive_processor.rb +207 -211
- data/lib/sprockets/eco_processor.rb +32 -0
- data/lib/sprockets/eco_template.rb +9 -30
- data/lib/sprockets/ejs_processor.rb +31 -0
- data/lib/sprockets/ejs_template.rb +9 -29
- data/lib/sprockets/encoding_utils.rb +261 -0
- data/lib/sprockets/engines.rb +53 -35
- data/lib/sprockets/environment.rb +17 -64
- data/lib/sprockets/erb_processor.rb +30 -0
- data/lib/sprockets/erb_template.rb +11 -0
- data/lib/sprockets/errors.rb +4 -13
- data/lib/sprockets/file_reader.rb +15 -0
- data/lib/sprockets/http_utils.rb +117 -0
- data/lib/sprockets/jst_processor.rb +35 -15
- data/lib/sprockets/legacy.rb +330 -0
- data/lib/sprockets/legacy_proc_processor.rb +35 -0
- data/lib/sprockets/legacy_tilt_processor.rb +29 -0
- data/lib/sprockets/loader.rb +325 -0
- data/lib/sprockets/manifest.rb +202 -127
- data/lib/sprockets/manifest_utils.rb +45 -0
- data/lib/sprockets/mime.rb +112 -31
- data/lib/sprockets/path_dependency_utils.rb +85 -0
- data/lib/sprockets/path_digest_utils.rb +47 -0
- data/lib/sprockets/path_utils.rb +287 -0
- data/lib/sprockets/paths.rb +42 -19
- data/lib/sprockets/processing.rb +178 -126
- data/lib/sprockets/processor_utils.rb +180 -0
- data/lib/sprockets/resolve.rb +211 -0
- data/lib/sprockets/sass_cache_store.rb +22 -17
- data/lib/sprockets/sass_compressor.rb +39 -15
- data/lib/sprockets/sass_functions.rb +2 -70
- data/lib/sprockets/sass_importer.rb +2 -30
- data/lib/sprockets/sass_processor.rb +292 -0
- data/lib/sprockets/sass_template.rb +12 -59
- data/lib/sprockets/server.rb +129 -84
- data/lib/sprockets/transformers.rb +145 -0
- data/lib/sprockets/uglifier_compressor.rb +39 -12
- data/lib/sprockets/unloaded_asset.rb +137 -0
- data/lib/sprockets/uri_tar.rb +98 -0
- data/lib/sprockets/uri_utils.rb +188 -0
- data/lib/sprockets/utils/gzip.rb +67 -0
- data/lib/sprockets/utils.rb +210 -44
- data/lib/sprockets/version.rb +1 -1
- data/lib/sprockets/yui_compressor.rb +39 -11
- data/lib/sprockets.rb +142 -81
- metadata +96 -90
- data/lib/sprockets/asset_attributes.rb +0 -137
- data/lib/sprockets/bundled_asset.rb +0 -78
- data/lib/sprockets/caching.rb +0 -96
- data/lib/sprockets/charset_normalizer.rb +0 -41
- data/lib/sprockets/index.rb +0 -100
- 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/scss_template.rb +0 -13
- data/lib/sprockets/static_asset.rb +0 -60
data/lib/sprockets/utils.rb
CHANGED
@@ -1,55 +1,125 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
module Sprockets
|
2
|
-
#
|
4
|
+
# Internal: Utils, we didn't know where else to put it! Functions may
|
5
|
+
# eventually be shuffled into more specific drawers.
|
3
6
|
module Utils
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# If the file is UTF-8 and theres a BOM, strip it for safe concatenation.
|
23
|
-
elsif data.encoding.name == "UTF-8" && data =~ UTF8_BOM_PATTERN
|
24
|
-
data.sub!(UTF8_BOM_PATTERN, "")
|
25
|
-
end
|
26
|
-
end
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# Internal: Check if object can safely be .dup'd.
|
10
|
+
#
|
11
|
+
# Similar to ActiveSupport #duplicable? check.
|
12
|
+
#
|
13
|
+
# obj - Any Object
|
14
|
+
#
|
15
|
+
# Returns false if .dup would raise a TypeError, otherwise true.
|
16
|
+
def duplicable?(obj)
|
17
|
+
if RUBY_VERSION >= "2.4.0"
|
18
|
+
true
|
19
|
+
else
|
20
|
+
case obj
|
21
|
+
when NilClass, FalseClass, TrueClass, Symbol, Numeric
|
22
|
+
false
|
23
|
+
else
|
24
|
+
true
|
27
25
|
end
|
28
26
|
end
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
29
|
+
# Internal: Duplicate and store key/value on new frozen hash.
|
30
|
+
#
|
31
|
+
# Seperated for recursive calls, always use hash_reassoc(hash, *keys).
|
32
|
+
#
|
33
|
+
# hash - Hash
|
34
|
+
# key - Object key
|
35
|
+
#
|
36
|
+
# Returns Hash.
|
37
|
+
def hash_reassoc1(hash, key)
|
38
|
+
hash = hash.dup if hash.frozen?
|
39
|
+
old_value = hash[key]
|
40
|
+
old_value = old_value.dup if duplicable?(old_value)
|
41
|
+
new_value = yield old_value
|
42
|
+
new_value.freeze if duplicable?(new_value)
|
43
|
+
hash.store(key, new_value)
|
44
|
+
hash.freeze
|
45
|
+
end
|
46
|
+
|
47
|
+
# Internal: Duplicate and store key/value on new frozen hash.
|
48
|
+
#
|
49
|
+
# Similar to Hash#store for nested frozen hashes.
|
50
|
+
#
|
51
|
+
# hash - Hash
|
52
|
+
# key - Object keys. Use multiple keys for nested hashes.
|
53
|
+
# block - Receives current value at key.
|
54
|
+
#
|
55
|
+
# Examples
|
56
|
+
#
|
57
|
+
# config = {paths: ["/bin", "/sbin"]}.freeze
|
58
|
+
# new_config = hash_reassoc(config, :paths) do |paths|
|
59
|
+
# paths << "/usr/local/bin"
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# Returns duplicated frozen Hash.
|
63
|
+
def hash_reassoc(hash, *keys, &block)
|
64
|
+
if keys.size == 1
|
65
|
+
hash_reassoc1(hash, keys[0], &block)
|
66
|
+
else
|
67
|
+
hash_reassoc1(hash, keys[0]) do |value|
|
68
|
+
hash_reassoc(value, *keys[1..-1], &block)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Internal: Check if string has a trailing semicolon.
|
74
|
+
#
|
75
|
+
# str - String
|
76
|
+
#
|
77
|
+
# Returns true or false.
|
78
|
+
def string_end_with_semicolon?(str)
|
79
|
+
i = str.size - 1
|
80
|
+
while i >= 0
|
81
|
+
c = str[i].ord
|
82
|
+
i -= 1
|
83
|
+
|
84
|
+
# Need to compare against the ordinals because the string can be UTF_8 or UTF_32LE encoded
|
85
|
+
# 0x0A == "\n"
|
86
|
+
# 0x20 == " "
|
87
|
+
# 0x09 == "\t"
|
88
|
+
# 0x3B == ";"
|
89
|
+
unless c == 0x0A || c == 0x20 || c == 0x09
|
90
|
+
return c === 0x3B
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
97
|
+
# Internal: Accumulate asset source to buffer and append a trailing
|
98
|
+
# semicolon if necessary.
|
99
|
+
#
|
100
|
+
# buf - String buffer to append to
|
101
|
+
# source - String source to append
|
102
|
+
#
|
103
|
+
# Returns buf String.
|
104
|
+
def concat_javascript_sources(buf, source)
|
105
|
+
if source.bytesize > 0
|
106
|
+
buf << source
|
107
|
+
|
108
|
+
# If the source contains non-ASCII characters, indexing on it becomes O(N).
|
109
|
+
# This will lead to O(N^2) performance in string_end_with_semicolon?, so we should use 32 bit encoding to make sure indexing stays O(1)
|
110
|
+
source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
|
111
|
+
|
112
|
+
if !string_end_with_semicolon?(source)
|
113
|
+
buf << ";\n"
|
114
|
+
elsif source[source.size - 1].ord != 0x0A
|
115
|
+
buf << "\n"
|
48
116
|
end
|
49
117
|
end
|
118
|
+
|
119
|
+
buf
|
50
120
|
end
|
51
121
|
|
52
|
-
# Prepends a leading "." to an extension if its missing.
|
122
|
+
# Internal: Prepends a leading "." to an extension if its missing.
|
53
123
|
#
|
54
124
|
# normalize_extension("js")
|
55
125
|
# # => ".js"
|
@@ -57,7 +127,7 @@ module Sprockets
|
|
57
127
|
# normalize_extension(".css")
|
58
128
|
# # => ".css"
|
59
129
|
#
|
60
|
-
def
|
130
|
+
def normalize_extension(extension)
|
61
131
|
extension = extension.to_s
|
62
132
|
if extension[/^\./]
|
63
133
|
extension
|
@@ -65,5 +135,101 @@ module Sprockets
|
|
65
135
|
".#{extension}"
|
66
136
|
end
|
67
137
|
end
|
138
|
+
|
139
|
+
# Internal: Feature detect if UnboundMethods can #bind to any Object or
|
140
|
+
# just Objects that share the same super class.
|
141
|
+
# Basically if RUBY_VERSION >= 2.
|
142
|
+
UNBOUND_METHODS_BIND_TO_ANY_OBJECT = begin
|
143
|
+
foo = Module.new { def bar; end }
|
144
|
+
foo.instance_method(:bar).bind(Object.new)
|
145
|
+
true
|
146
|
+
rescue TypeError
|
147
|
+
false
|
148
|
+
end
|
149
|
+
|
150
|
+
# Internal: Inject into target module for the duration of the block.
|
151
|
+
#
|
152
|
+
# mod - Module
|
153
|
+
#
|
154
|
+
# Returns result of block.
|
155
|
+
def module_include(base, mod)
|
156
|
+
old_methods = {}
|
157
|
+
|
158
|
+
mod.instance_methods.each do |sym|
|
159
|
+
old_methods[sym] = base.instance_method(sym) if base.method_defined?(sym)
|
160
|
+
end
|
161
|
+
|
162
|
+
unless UNBOUND_METHODS_BIND_TO_ANY_OBJECT
|
163
|
+
base.send(:include, mod) unless base < mod
|
164
|
+
end
|
165
|
+
|
166
|
+
mod.instance_methods.each do |sym|
|
167
|
+
method = mod.instance_method(sym)
|
168
|
+
base.send(:define_method, sym, method)
|
169
|
+
end
|
170
|
+
|
171
|
+
yield
|
172
|
+
ensure
|
173
|
+
mod.instance_methods.each do |sym|
|
174
|
+
base.send(:undef_method, sym) if base.method_defined?(sym)
|
175
|
+
end
|
176
|
+
old_methods.each do |sym, method|
|
177
|
+
base.send(:define_method, sym, method)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# Internal: Post-order Depth-First search algorithm.
|
182
|
+
#
|
183
|
+
# Used for resolving asset dependencies.
|
184
|
+
#
|
185
|
+
# initial - Initial Array of nodes to traverse.
|
186
|
+
# block -
|
187
|
+
# node - Current node to get children of
|
188
|
+
#
|
189
|
+
# Returns a Set of nodes.
|
190
|
+
def dfs(initial)
|
191
|
+
nodes, seen = Set.new, Set.new
|
192
|
+
stack = Array(initial).reverse
|
193
|
+
|
194
|
+
while node = stack.pop
|
195
|
+
if seen.include?(node)
|
196
|
+
nodes.add(node)
|
197
|
+
else
|
198
|
+
seen.add(node)
|
199
|
+
stack.push(node)
|
200
|
+
stack.concat(Array(yield node).reverse)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
nodes
|
205
|
+
end
|
206
|
+
|
207
|
+
# Internal: Post-order Depth-First search algorithm that gathers all paths
|
208
|
+
# along the way.
|
209
|
+
#
|
210
|
+
# TODO: Rename function.
|
211
|
+
#
|
212
|
+
# path - Initial Array node path
|
213
|
+
# block -
|
214
|
+
# node - Current node to get children of
|
215
|
+
#
|
216
|
+
# Returns an Array of node Arrays.
|
217
|
+
def dfs_paths(path)
|
218
|
+
paths = []
|
219
|
+
stack, seen = [path], Set.new
|
220
|
+
|
221
|
+
while path = stack.pop
|
222
|
+
if !seen.include?(path.last)
|
223
|
+
seen.add(path.last)
|
224
|
+
paths << path if path.size > 1
|
225
|
+
|
226
|
+
Array(yield path.last).reverse_each do |node|
|
227
|
+
stack.push(path + [node])
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
paths
|
233
|
+
end
|
68
234
|
end
|
69
235
|
end
|
data/lib/sprockets/version.rb
CHANGED
@@ -1,24 +1,52 @@
|
|
1
|
-
require '
|
1
|
+
require 'sprockets/autoload'
|
2
|
+
require 'sprockets/digest_utils'
|
2
3
|
|
3
4
|
module Sprockets
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
# Public: YUI compressor.
|
6
|
+
#
|
7
|
+
# To accept the default options
|
8
|
+
#
|
9
|
+
# environment.register_bundle_processor 'application/javascript',
|
10
|
+
# Sprockets::YUICompressor
|
11
|
+
#
|
12
|
+
# Or to pass options to the YUI::JavaScriptCompressor class.
|
13
|
+
#
|
14
|
+
# environment.register_bundle_processor 'application/javascript',
|
15
|
+
# Sprockets::YUICompressor.new(munge: true)
|
16
|
+
#
|
17
|
+
class YUICompressor
|
18
|
+
VERSION = '1'
|
19
|
+
|
20
|
+
# Public: Return singleton instance with default options.
|
21
|
+
#
|
22
|
+
# Returns YUICompressor object.
|
23
|
+
def self.instance
|
24
|
+
@instance ||= new
|
7
25
|
end
|
8
26
|
|
9
|
-
def
|
10
|
-
|
27
|
+
def self.call(input)
|
28
|
+
instance.call(input)
|
11
29
|
end
|
12
30
|
|
13
|
-
def
|
31
|
+
def self.cache_key
|
32
|
+
instance.cache_key
|
14
33
|
end
|
15
34
|
|
16
|
-
|
17
|
-
|
35
|
+
attr_reader :cache_key
|
36
|
+
|
37
|
+
def initialize(options = {})
|
38
|
+
@options = options
|
39
|
+
@cache_key = "#{self.class.name}:#{Autoload::YUI::Compressor::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
|
40
|
+
end
|
41
|
+
|
42
|
+
def call(input)
|
43
|
+
data = input[:data]
|
44
|
+
|
45
|
+
case input[:content_type]
|
18
46
|
when 'application/javascript'
|
19
|
-
YUI::JavaScriptCompressor.new.compress(data)
|
47
|
+
Autoload::YUI::JavaScriptCompressor.new(@options).compress(data)
|
20
48
|
when 'text/css'
|
21
|
-
YUI::CssCompressor.new.compress(data)
|
49
|
+
Autoload::YUI::CssCompressor.new(@options).compress(data)
|
22
50
|
else
|
23
51
|
data
|
24
52
|
end
|
data/lib/sprockets.rb
CHANGED
@@ -1,108 +1,169 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'sprockets/version'
|
3
|
+
require 'sprockets/cache'
|
4
|
+
require 'sprockets/environment'
|
5
|
+
require 'sprockets/errors'
|
6
|
+
require 'sprockets/manifest'
|
7
|
+
require 'sprockets/deprecation'
|
2
8
|
|
3
9
|
module Sprockets
|
4
|
-
|
5
|
-
|
6
|
-
autoload :Environment, "sprockets/environment"
|
7
|
-
autoload :Index, "sprockets/index"
|
8
|
-
autoload :Manifest, "sprockets/manifest"
|
9
|
-
|
10
|
-
# Assets
|
11
|
-
autoload :Asset, "sprockets/asset"
|
12
|
-
autoload :BundledAsset, "sprockets/bundled_asset"
|
13
|
-
autoload :ProcessedAsset, "sprockets/processed_asset"
|
14
|
-
autoload :StaticAsset, "sprockets/static_asset"
|
15
|
-
|
16
|
-
# Processing
|
17
|
-
autoload :Context, "sprockets/context"
|
18
|
-
autoload :EcoTemplate, "sprockets/eco_template"
|
19
|
-
autoload :EjsTemplate, "sprockets/ejs_template"
|
20
|
-
autoload :JstProcessor, "sprockets/jst_processor"
|
21
|
-
autoload :Processor, "sprockets/processor"
|
22
|
-
autoload :SassCacheStore, "sprockets/sass_cache_store"
|
23
|
-
autoload :SassFunctions, "sprockets/sass_functions"
|
24
|
-
autoload :SassImporter, "sprockets/sass_importer"
|
25
|
-
autoload :SassTemplate, "sprockets/sass_template"
|
26
|
-
autoload :ScssTemplate, "sprockets/scss_template"
|
27
|
-
|
28
|
-
# Internal utilities
|
29
|
-
autoload :ArgumentError, "sprockets/errors"
|
30
|
-
autoload :AssetAttributes, "sprockets/asset_attributes"
|
31
|
-
autoload :CircularDependencyError, "sprockets/errors"
|
32
|
-
autoload :ContentTypeMismatch, "sprockets/errors"
|
33
|
-
autoload :EngineError, "sprockets/errors"
|
34
|
-
autoload :Error, "sprockets/errors"
|
35
|
-
autoload :FileNotFound, "sprockets/errors"
|
36
|
-
autoload :Utils, "sprockets/utils"
|
37
|
-
|
38
|
-
module Cache
|
39
|
-
autoload :FileStore, "sprockets/cache/file_store"
|
40
|
-
end
|
10
|
+
require 'sprockets/processor_utils'
|
11
|
+
extend ProcessorUtils
|
41
12
|
|
42
13
|
# Extend Sprockets module to provide global registry
|
43
|
-
require '
|
44
|
-
require 'sprockets/
|
45
|
-
require '
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
14
|
+
require 'sprockets/configuration'
|
15
|
+
require 'sprockets/context'
|
16
|
+
require 'digest/sha2'
|
17
|
+
extend Configuration
|
18
|
+
|
19
|
+
self.config = {
|
20
|
+
bundle_processors: Hash.new { |h, k| [].freeze }.freeze,
|
21
|
+
bundle_reducers: Hash.new { |h, k| {}.freeze }.freeze,
|
22
|
+
compressors: Hash.new { |h, k| {}.freeze }.freeze,
|
23
|
+
dependencies: Set.new.freeze,
|
24
|
+
dependency_resolvers: {}.freeze,
|
25
|
+
digest_class: Digest::SHA256,
|
26
|
+
engine_mime_types: {}.freeze,
|
27
|
+
engines: {}.freeze,
|
28
|
+
mime_exts: {}.freeze,
|
29
|
+
mime_types: {}.freeze,
|
30
|
+
paths: [].freeze,
|
31
|
+
pipelines: {}.freeze,
|
32
|
+
postprocessors: Hash.new { |h, k| [].freeze }.freeze,
|
33
|
+
preprocessors: Hash.new { |h, k| [].freeze }.freeze,
|
34
|
+
registered_transformers: Hash.new { |h, k| {}.freeze }.freeze,
|
35
|
+
root: File.expand_path('..', __FILE__).freeze,
|
36
|
+
transformers: Hash.new { |h, k| {}.freeze }.freeze,
|
37
|
+
version: "",
|
38
|
+
gzip_enabled: true
|
39
|
+
}.freeze
|
40
|
+
self.computed_config = {}
|
41
|
+
|
42
|
+
@context_class = Context
|
43
|
+
|
44
|
+
require 'logger'
|
45
|
+
@logger = Logger.new($stderr)
|
46
|
+
@logger.level = Logger::FATAL
|
47
|
+
|
48
|
+
# Common asset text types
|
49
|
+
register_mime_type 'application/javascript', extensions: ['.js'], charset: :unicode
|
50
|
+
register_mime_type 'application/json', extensions: ['.json'], charset: :unicode
|
51
|
+
register_mime_type 'application/xml', extensions: ['.xml']
|
52
|
+
register_mime_type 'text/css', extensions: ['.css'], charset: :css
|
53
|
+
register_mime_type 'text/html', extensions: ['.html', '.htm'], charset: :html
|
54
|
+
register_mime_type 'text/plain', extensions: ['.txt', '.text']
|
55
|
+
register_mime_type 'text/yaml', extensions: ['.yml', '.yaml'], charset: :unicode
|
56
|
+
|
57
|
+
# Common image types
|
58
|
+
register_mime_type 'image/x-icon', extensions: ['.ico']
|
59
|
+
register_mime_type 'image/bmp', extensions: ['.bmp']
|
60
|
+
register_mime_type 'image/gif', extensions: ['.gif']
|
61
|
+
register_mime_type 'image/webp', extensions: ['.webp']
|
62
|
+
register_mime_type 'image/png', extensions: ['.png']
|
63
|
+
register_mime_type 'image/jpeg', extensions: ['.jpg', '.jpeg']
|
64
|
+
register_mime_type 'image/tiff', extensions: ['.tiff', '.tif']
|
65
|
+
register_mime_type 'image/svg+xml', extensions: ['.svg']
|
66
|
+
|
67
|
+
# Common audio/video types
|
68
|
+
register_mime_type 'video/webm', extensions: ['.webm']
|
69
|
+
register_mime_type 'audio/basic', extensions: ['.snd', '.au']
|
70
|
+
register_mime_type 'audio/aiff', extensions: ['.aiff']
|
71
|
+
register_mime_type 'audio/mpeg', extensions: ['.mp3', '.mp2', '.m2a', '.m3a']
|
72
|
+
register_mime_type 'application/ogg', extensions: ['.ogx']
|
73
|
+
register_mime_type 'audio/midi', extensions: ['.midi', '.mid']
|
74
|
+
register_mime_type 'video/avi', extensions: ['.avi']
|
75
|
+
register_mime_type 'audio/wave', extensions: ['.wav', '.wave']
|
76
|
+
register_mime_type 'video/mp4', extensions: ['.mp4', '.m4v']
|
77
|
+
|
78
|
+
# Common font types
|
79
|
+
register_mime_type 'application/vnd.ms-fontobject', extensions: ['.eot']
|
80
|
+
register_mime_type 'application/x-font-opentype', extensions: ['.otf']
|
81
|
+
register_mime_type 'application/x-font-ttf', extensions: ['.ttf']
|
82
|
+
register_mime_type 'application/font-woff', extensions: ['.woff']
|
83
|
+
|
84
|
+
register_pipeline :source do |env|
|
85
|
+
[]
|
86
|
+
end
|
87
|
+
|
88
|
+
register_pipeline :self do |env, type, file_type, engine_extnames|
|
89
|
+
env.self_processors_for(type, file_type, engine_extnames)
|
90
|
+
end
|
91
|
+
|
92
|
+
register_pipeline :default do |env, type, file_type, engine_extnames|
|
93
|
+
env.default_processors_for(type, file_type, engine_extnames)
|
94
|
+
end
|
61
95
|
|
62
96
|
require 'sprockets/directive_processor'
|
63
|
-
register_preprocessor 'text/css',
|
64
|
-
|
97
|
+
register_preprocessor 'text/css', DirectiveProcessor.new(
|
98
|
+
comments: ["//", ["/*", "*/"]]
|
99
|
+
)
|
100
|
+
register_preprocessor 'application/javascript', DirectiveProcessor.new(
|
101
|
+
comments: ["//", ["/*", "*/"]] + ["#", ["###", "###"]]
|
102
|
+
)
|
65
103
|
|
66
|
-
require 'sprockets/
|
67
|
-
|
104
|
+
require 'sprockets/bundle'
|
105
|
+
register_bundle_processor 'application/javascript', Bundle
|
106
|
+
register_bundle_processor 'text/css', Bundle
|
68
107
|
|
69
|
-
|
70
|
-
|
108
|
+
register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
|
109
|
+
register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
|
110
|
+
register_bundle_metadata_reducer '*/*', :links, :+
|
71
111
|
|
112
|
+
require 'sprockets/closure_compressor'
|
72
113
|
require 'sprockets/sass_compressor'
|
114
|
+
require 'sprockets/uglifier_compressor'
|
115
|
+
require 'sprockets/yui_compressor'
|
73
116
|
register_compressor 'text/css', :sass, SassCompressor
|
74
117
|
register_compressor 'text/css', :scss, SassCompressor
|
75
|
-
|
76
|
-
require 'sprockets/yui_compressor'
|
77
118
|
register_compressor 'text/css', :yui, YUICompressor
|
78
|
-
|
79
|
-
require 'sprockets/closure_compressor'
|
80
119
|
register_compressor 'application/javascript', :closure, ClosureCompressor
|
81
|
-
|
82
|
-
require 'sprockets/uglifier_compressor'
|
83
120
|
register_compressor 'application/javascript', :uglifier, UglifierCompressor
|
84
121
|
register_compressor 'application/javascript', :uglify, UglifierCompressor
|
85
|
-
|
86
|
-
require 'sprockets/yui_compressor'
|
87
122
|
register_compressor 'application/javascript', :yui, YUICompressor
|
88
123
|
|
89
|
-
# Cherry pick the default Tilt engines that make sense for
|
90
|
-
# Sprockets. We don't need ones that only generate html like HAML.
|
91
|
-
|
92
124
|
# Mmm, CoffeeScript
|
93
|
-
|
125
|
+
require 'sprockets/coffee_script_processor'
|
126
|
+
Deprecation.silence do
|
127
|
+
register_engine '.coffee', CoffeeScriptProcessor, mime_type: 'application/javascript', silence_deprecation: true
|
128
|
+
end
|
94
129
|
|
95
130
|
# JST engines
|
96
|
-
|
97
|
-
|
98
|
-
|
131
|
+
require 'sprockets/eco_processor'
|
132
|
+
require 'sprockets/ejs_processor'
|
133
|
+
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
|
99
139
|
|
100
140
|
# CSS engines
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
146
|
+
register_bundle_metadata_reducer 'text/css', :sass_dependencies, Set.new, :+
|
104
147
|
|
105
148
|
# Other
|
106
|
-
|
107
|
-
register_engine '.
|
149
|
+
require 'sprockets/erb_processor'
|
150
|
+
register_engine '.erb', ERBProcessor, mime_type: 'text/plain', silence_deprecation: true
|
151
|
+
|
152
|
+
register_dependency_resolver 'environment-version' do |env|
|
153
|
+
env.version
|
154
|
+
end
|
155
|
+
register_dependency_resolver 'environment-paths' do |env|
|
156
|
+
env.paths.map {|path| env.compress_from_root(path) }
|
157
|
+
end
|
158
|
+
register_dependency_resolver 'file-digest' do |env, str|
|
159
|
+
env.file_digest(env.parse_file_digest_uri(str))
|
160
|
+
end
|
161
|
+
register_dependency_resolver 'processors' do |env, str|
|
162
|
+
env.resolve_processors_cache_key_uri(str)
|
163
|
+
end
|
164
|
+
|
165
|
+
depend_on 'environment-version'
|
166
|
+
depend_on 'environment-paths'
|
108
167
|
end
|
168
|
+
|
169
|
+
require 'sprockets/legacy'
|