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,313 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rack/utils'
|
3
|
+
require 'sprockets/autoload'
|
4
|
+
require 'sprockets/source_map_utils'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Sprockets
|
8
|
+
# Processor engine class for the SASS/SCSS compiler. Depends on the `sass` gem.
|
9
|
+
#
|
10
|
+
# For more infomation see:
|
11
|
+
#
|
12
|
+
# https://github.com/sass/sass
|
13
|
+
# https://github.com/rails/sass-rails
|
14
|
+
#
|
15
|
+
class SassProcessor
|
16
|
+
autoload :CacheStore, 'sprockets/sass_cache_store'
|
17
|
+
|
18
|
+
# Internal: Defines default sass syntax to use. Exposed so the ScssProcessor
|
19
|
+
# may override it.
|
20
|
+
def self.syntax
|
21
|
+
:sass
|
22
|
+
end
|
23
|
+
|
24
|
+
# Public: Return singleton instance with default options.
|
25
|
+
#
|
26
|
+
# Returns SassProcessor object.
|
27
|
+
def self.instance
|
28
|
+
@instance ||= new
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.call(input)
|
32
|
+
instance.call(input)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.cache_key
|
36
|
+
instance.cache_key
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :cache_key
|
40
|
+
|
41
|
+
# Public: Initialize template with custom options.
|
42
|
+
#
|
43
|
+
# options - Hash
|
44
|
+
# cache_version - String custom cache version. Used to force a cache
|
45
|
+
# change after code changes are made to Sass Functions.
|
46
|
+
#
|
47
|
+
def initialize(options = {}, &block)
|
48
|
+
@cache_version = options[:cache_version]
|
49
|
+
@cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::Sass::VERSION}:#{@cache_version}".freeze
|
50
|
+
@importer_class = options[:importer] || Sass::Importers::Filesystem
|
51
|
+
@sass_config = options[:sass_config] || {}
|
52
|
+
@functions = Module.new do
|
53
|
+
include Functions
|
54
|
+
include options[:functions] if options[:functions]
|
55
|
+
class_eval(&block) if block_given?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def call(input)
|
60
|
+
context = input[:environment].context_class.new(input)
|
61
|
+
|
62
|
+
engine_options = merge_options({
|
63
|
+
filename: input[:filename],
|
64
|
+
syntax: self.class.syntax,
|
65
|
+
cache_store: build_cache_store(input, @cache_version),
|
66
|
+
load_paths: context.environment.paths.map { |p| @importer_class.new(p.to_s) },
|
67
|
+
importer: @importer_class.new(Pathname.new(context.filename).to_s),
|
68
|
+
sprockets: {
|
69
|
+
context: context,
|
70
|
+
environment: input[:environment],
|
71
|
+
dependencies: context.metadata[:dependencies]
|
72
|
+
}
|
73
|
+
})
|
74
|
+
|
75
|
+
engine = Autoload::Sass::Engine.new(input[:data], engine_options)
|
76
|
+
|
77
|
+
css, map = Utils.module_include(Autoload::Sass::Script::Functions, @functions) do
|
78
|
+
engine.render_with_sourcemap('')
|
79
|
+
end
|
80
|
+
|
81
|
+
css = css.sub("\n/*# sourceMappingURL= */\n", '')
|
82
|
+
|
83
|
+
map = SourceMapUtils.format_source_map(JSON.parse(map.to_json(css_uri: '')), input)
|
84
|
+
map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
|
85
|
+
|
86
|
+
# Track all imported files
|
87
|
+
sass_dependencies = Set.new([input[:filename]])
|
88
|
+
engine.dependencies.map do |dependency|
|
89
|
+
sass_dependencies << dependency.options[:filename]
|
90
|
+
context.metadata[:dependencies] << URIUtils.build_file_digest_uri(dependency.options[:filename])
|
91
|
+
end
|
92
|
+
|
93
|
+
context.metadata.merge(data: css, sass_dependencies: sass_dependencies, map: map)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
# Public: Build the cache store to be used by the Sass engine.
|
99
|
+
#
|
100
|
+
# input - the input hash.
|
101
|
+
# version - the cache version.
|
102
|
+
#
|
103
|
+
# Override this method if you need to use a different cache than the
|
104
|
+
# Sprockets cache.
|
105
|
+
def build_cache_store(input, version)
|
106
|
+
CacheStore.new(input[:cache], version)
|
107
|
+
end
|
108
|
+
|
109
|
+
def merge_options(options)
|
110
|
+
defaults = @sass_config.dup
|
111
|
+
|
112
|
+
if load_paths = defaults.delete(:load_paths)
|
113
|
+
options[:load_paths] += load_paths
|
114
|
+
end
|
115
|
+
|
116
|
+
options.merge!(defaults)
|
117
|
+
options
|
118
|
+
end
|
119
|
+
|
120
|
+
# Public: Functions injected into Sass context during Sprockets evaluation.
|
121
|
+
#
|
122
|
+
# This module may be extended to add global functionality to all Sprockets
|
123
|
+
# Sass environments. Though, scoping your functions to just your environment
|
124
|
+
# is preferred.
|
125
|
+
#
|
126
|
+
# module Sprockets::SassProcessor::Functions
|
127
|
+
# def asset_path(path, options = {})
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
module Functions
|
132
|
+
# Public: Generate a url for asset path.
|
133
|
+
#
|
134
|
+
# Default implementation is deprecated. Currently defaults to
|
135
|
+
# Context#asset_path.
|
136
|
+
#
|
137
|
+
# Will raise NotImplementedError in the future. Users should provide their
|
138
|
+
# own base implementation.
|
139
|
+
#
|
140
|
+
# Returns a Sass::Script::String.
|
141
|
+
def asset_path(path, options = {})
|
142
|
+
path = path.value
|
143
|
+
|
144
|
+
path, _, query, fragment = URI.split(path)[5..8]
|
145
|
+
path = sprockets_context.asset_path(path, options)
|
146
|
+
query = "?#{query}" if query
|
147
|
+
fragment = "##{fragment}" if fragment
|
148
|
+
|
149
|
+
Autoload::Sass::Script::String.new("#{path}#{query}#{fragment}", :string)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Public: Generate a asset url() link.
|
153
|
+
#
|
154
|
+
# path - Sass::Script::String URL path
|
155
|
+
#
|
156
|
+
# Returns a Sass::Script::String.
|
157
|
+
def asset_url(path, options = {})
|
158
|
+
Autoload::Sass::Script::String.new("url(#{asset_path(path, options).value})")
|
159
|
+
end
|
160
|
+
|
161
|
+
# Public: Generate url for image path.
|
162
|
+
#
|
163
|
+
# path - Sass::Script::String URL path
|
164
|
+
#
|
165
|
+
# Returns a Sass::Script::String.
|
166
|
+
def image_path(path)
|
167
|
+
asset_path(path, type: :image)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Public: Generate a image url() link.
|
171
|
+
#
|
172
|
+
# path - Sass::Script::String URL path
|
173
|
+
#
|
174
|
+
# Returns a Sass::Script::String.
|
175
|
+
def image_url(path)
|
176
|
+
asset_url(path, type: :image)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Public: Generate url for video path.
|
180
|
+
#
|
181
|
+
# path - Sass::Script::String URL path
|
182
|
+
#
|
183
|
+
# Returns a Sass::Script::String.
|
184
|
+
def video_path(path)
|
185
|
+
asset_path(path, type: :video)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Public: Generate a video url() link.
|
189
|
+
#
|
190
|
+
# path - Sass::Script::String URL path
|
191
|
+
#
|
192
|
+
# Returns a Sass::Script::String.
|
193
|
+
def video_url(path)
|
194
|
+
asset_url(path, type: :video)
|
195
|
+
end
|
196
|
+
|
197
|
+
# Public: Generate url for audio path.
|
198
|
+
#
|
199
|
+
# path - Sass::Script::String URL path
|
200
|
+
#
|
201
|
+
# Returns a Sass::Script::String.
|
202
|
+
def audio_path(path)
|
203
|
+
asset_path(path, type: :audio)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Public: Generate a audio url() link.
|
207
|
+
#
|
208
|
+
# path - Sass::Script::String URL path
|
209
|
+
#
|
210
|
+
# Returns a Sass::Script::String.
|
211
|
+
def audio_url(path)
|
212
|
+
asset_url(path, type: :audio)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Public: Generate url for font path.
|
216
|
+
#
|
217
|
+
# path - Sass::Script::String URL path
|
218
|
+
#
|
219
|
+
# Returns a Sass::Script::String.
|
220
|
+
def font_path(path)
|
221
|
+
asset_path(path, type: :font)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Public: Generate a font url() link.
|
225
|
+
#
|
226
|
+
# path - Sass::Script::String URL path
|
227
|
+
#
|
228
|
+
# Returns a Sass::Script::String.
|
229
|
+
def font_url(path)
|
230
|
+
asset_url(path, type: :font)
|
231
|
+
end
|
232
|
+
|
233
|
+
# Public: Generate url for javascript path.
|
234
|
+
#
|
235
|
+
# path - Sass::Script::String URL path
|
236
|
+
#
|
237
|
+
# Returns a Sass::Script::String.
|
238
|
+
def javascript_path(path)
|
239
|
+
asset_path(path, type: :javascript)
|
240
|
+
end
|
241
|
+
|
242
|
+
# Public: Generate a javascript url() link.
|
243
|
+
#
|
244
|
+
# path - Sass::Script::String URL path
|
245
|
+
#
|
246
|
+
# Returns a Sass::Script::String.
|
247
|
+
def javascript_url(path)
|
248
|
+
asset_url(path, type: :javascript)
|
249
|
+
end
|
250
|
+
|
251
|
+
# Public: Generate url for stylesheet path.
|
252
|
+
#
|
253
|
+
# path - Sass::Script::String URL path
|
254
|
+
#
|
255
|
+
# Returns a Sass::Script::String.
|
256
|
+
def stylesheet_path(path)
|
257
|
+
asset_path(path, type: :stylesheet)
|
258
|
+
end
|
259
|
+
|
260
|
+
# Public: Generate a stylesheet url() link.
|
261
|
+
#
|
262
|
+
# path - Sass::Script::String URL path
|
263
|
+
#
|
264
|
+
# Returns a Sass::Script::String.
|
265
|
+
def stylesheet_url(path)
|
266
|
+
asset_url(path, type: :stylesheet)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Public: Generate a data URI for asset path.
|
270
|
+
#
|
271
|
+
# path - Sass::Script::String logical asset path
|
272
|
+
#
|
273
|
+
# Returns a Sass::Script::String.
|
274
|
+
def asset_data_url(path)
|
275
|
+
url = sprockets_context.asset_data_uri(path.value)
|
276
|
+
Autoload::Sass::Script::String.new("url(" + url + ")")
|
277
|
+
end
|
278
|
+
|
279
|
+
protected
|
280
|
+
# Public: The Environment.
|
281
|
+
#
|
282
|
+
# Returns Sprockets::Environment.
|
283
|
+
def sprockets_environment
|
284
|
+
options[:sprockets][:environment]
|
285
|
+
end
|
286
|
+
|
287
|
+
# Public: Mutatable set of dependencies.
|
288
|
+
#
|
289
|
+
# Returns a Set.
|
290
|
+
def sprockets_dependencies
|
291
|
+
options[:sprockets][:dependencies]
|
292
|
+
end
|
293
|
+
|
294
|
+
# Deprecated: Get the Context instance. Use APIs on
|
295
|
+
# sprockets_environment or sprockets_dependencies directly.
|
296
|
+
#
|
297
|
+
# Returns a Context instance.
|
298
|
+
def sprockets_context
|
299
|
+
options[:sprockets][:context]
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
class ScssProcessor < SassProcessor
|
306
|
+
def self.syntax
|
307
|
+
:scss
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
# Deprecated: Use Sprockets::SassProcessor::Functions instead.
|
312
|
+
SassFunctions = SassProcessor::Functions
|
313
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'sprockets/autoload'
|
3
|
+
require 'sprockets/source_map_utils'
|
4
|
+
|
5
|
+
module Sprockets
|
6
|
+
# Public: Sass CSS minifier.
|
7
|
+
#
|
8
|
+
# To accept the default options
|
9
|
+
#
|
10
|
+
# environment.register_bundle_processor 'text/css',
|
11
|
+
# Sprockets::SasscCompressor
|
12
|
+
#
|
13
|
+
# Or to pass options to the Sass::Engine class.
|
14
|
+
#
|
15
|
+
# environment.register_bundle_processor 'text/css',
|
16
|
+
# Sprockets::SasscCompressor.new({ ... })
|
17
|
+
#
|
18
|
+
class SasscCompressor
|
19
|
+
# Public: Return singleton instance with default options.
|
20
|
+
#
|
21
|
+
# Returns SasscCompressor object.
|
22
|
+
def self.instance
|
23
|
+
@instance ||= new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.call(input)
|
27
|
+
instance.call(input)
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(options = {})
|
31
|
+
@options = {
|
32
|
+
syntax: :scss,
|
33
|
+
style: :compressed,
|
34
|
+
source_map_contents: false,
|
35
|
+
omit_source_map_url: true,
|
36
|
+
}.merge(options).freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
def call(input)
|
40
|
+
# SassC requires the template to be modifiable
|
41
|
+
input_data = input[:data].frozen? ? input[:data].dup : input[:data]
|
42
|
+
engine = Autoload::SassC::Engine.new(input_data, @options.merge(filename: input[:filename], source_map_file: "#{input[:filename]}.map"))
|
43
|
+
|
44
|
+
css = engine.render.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '')
|
45
|
+
|
46
|
+
begin
|
47
|
+
map = SourceMapUtils.format_source_map(JSON.parse(engine.source_map), input)
|
48
|
+
map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
|
49
|
+
rescue SassC::NotRenderedError
|
50
|
+
map = input[:metadata][:map]
|
51
|
+
end
|
52
|
+
|
53
|
+
{ data: css, map: map }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,297 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rack/utils'
|
3
|
+
require 'sprockets/autoload'
|
4
|
+
require 'sprockets/source_map_utils'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Sprockets
|
8
|
+
# Processor engine class for the SASS/SCSS compiler. Depends on the `sassc` gem.
|
9
|
+
#
|
10
|
+
# For more infomation see:
|
11
|
+
#
|
12
|
+
# https://github.com/sass/sassc-ruby
|
13
|
+
# https://github.com/sass/sassc-rails
|
14
|
+
#
|
15
|
+
class SasscProcessor
|
16
|
+
|
17
|
+
# Internal: Defines default sass syntax to use. Exposed so the ScsscProcessor
|
18
|
+
# may override it.
|
19
|
+
def self.syntax
|
20
|
+
:sass
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Return singleton instance with default options.
|
24
|
+
#
|
25
|
+
# Returns SasscProcessor object.
|
26
|
+
def self.instance
|
27
|
+
@instance ||= new
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.call(input)
|
31
|
+
instance.call(input)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.cache_key
|
35
|
+
instance.cache_key
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :cache_key
|
39
|
+
|
40
|
+
def initialize(options = {}, &block)
|
41
|
+
@cache_version = options[:cache_version]
|
42
|
+
@cache_key = "#{self.class.name}:#{VERSION}:#{Autoload::SassC::VERSION}:#{@cache_version}".freeze
|
43
|
+
@importer_class = options[:importer]
|
44
|
+
@sass_config = options[:sass_config] || {}
|
45
|
+
@functions = Module.new do
|
46
|
+
include Functions
|
47
|
+
include options[:functions] if options[:functions]
|
48
|
+
class_eval(&block) if block_given?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def call(input)
|
53
|
+
context = input[:environment].context_class.new(input)
|
54
|
+
|
55
|
+
options = engine_options(input, context)
|
56
|
+
engine = Autoload::SassC::Engine.new(input[:data], options)
|
57
|
+
|
58
|
+
css = Utils.module_include(Autoload::SassC::Script::Functions, @functions) do
|
59
|
+
engine.render.sub(/^\n^\/\*# sourceMappingURL=.*\*\/$/m, '')
|
60
|
+
end
|
61
|
+
|
62
|
+
begin
|
63
|
+
map = SourceMapUtils.format_source_map(JSON.parse(engine.source_map), input)
|
64
|
+
map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
|
65
|
+
|
66
|
+
engine.dependencies.each do |dependency|
|
67
|
+
context.metadata[:dependencies] << URIUtils.build_file_digest_uri(dependency.filename)
|
68
|
+
end
|
69
|
+
rescue SassC::NotRenderedError
|
70
|
+
map = input[:metadata][:map]
|
71
|
+
end
|
72
|
+
|
73
|
+
context.metadata.merge(data: css, map: map)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def merge_options(options)
|
79
|
+
defaults = @sass_config.dup
|
80
|
+
|
81
|
+
if load_paths = defaults.delete(:load_paths)
|
82
|
+
options[:load_paths] += load_paths
|
83
|
+
end
|
84
|
+
|
85
|
+
options.merge!(defaults)
|
86
|
+
options
|
87
|
+
end
|
88
|
+
|
89
|
+
# Public: Functions injected into Sass context during Sprockets evaluation.
|
90
|
+
#
|
91
|
+
# This module may be extended to add global functionality to all Sprockets
|
92
|
+
# Sass environments. Though, scoping your functions to just your environment
|
93
|
+
# is preferred.
|
94
|
+
#
|
95
|
+
# module Sprockets::SasscProcessor::Functions
|
96
|
+
# def asset_path(path, options = {})
|
97
|
+
# end
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
module Functions
|
101
|
+
# Public: Generate a url for asset path.
|
102
|
+
#
|
103
|
+
# Default implementation is deprecated. Currently defaults to
|
104
|
+
# Context#asset_path.
|
105
|
+
#
|
106
|
+
# Will raise NotImplementedError in the future. Users should provide their
|
107
|
+
# own base implementation.
|
108
|
+
#
|
109
|
+
# Returns a SassC::Script::Value::String.
|
110
|
+
def asset_path(path, options = {})
|
111
|
+
path = path.value
|
112
|
+
|
113
|
+
path, _, query, fragment = URI.split(path)[5..8]
|
114
|
+
path = sprockets_context.asset_path(path, options)
|
115
|
+
query = "?#{query}" if query
|
116
|
+
fragment = "##{fragment}" if fragment
|
117
|
+
|
118
|
+
Autoload::SassC::Script::Value::String.new("#{path}#{query}#{fragment}", :string)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Public: Generate a asset url() link.
|
122
|
+
#
|
123
|
+
# path - SassC::Script::Value::String URL path
|
124
|
+
#
|
125
|
+
# Returns a SassC::Script::Value::String.
|
126
|
+
def asset_url(path, options = {})
|
127
|
+
Autoload::SassC::Script::Value::String.new("url(#{asset_path(path, options).value})")
|
128
|
+
end
|
129
|
+
|
130
|
+
# Public: Generate url for image path.
|
131
|
+
#
|
132
|
+
# path - SassC::Script::Value::String URL path
|
133
|
+
#
|
134
|
+
# Returns a SassC::Script::Value::String.
|
135
|
+
def image_path(path)
|
136
|
+
asset_path(path, type: :image)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Public: Generate a image url() link.
|
140
|
+
#
|
141
|
+
# path - SassC::Script::Value::String URL path
|
142
|
+
#
|
143
|
+
# Returns a SassC::Script::Value::String.
|
144
|
+
def image_url(path)
|
145
|
+
asset_url(path, type: :image)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Public: Generate url for video path.
|
149
|
+
#
|
150
|
+
# path - SassC::Script::Value::String URL path
|
151
|
+
#
|
152
|
+
# Returns a SassC::Script::Value::String.
|
153
|
+
def video_path(path)
|
154
|
+
asset_path(path, type: :video)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Public: Generate a video url() link.
|
158
|
+
#
|
159
|
+
# path - SassC::Script::Value::String URL path
|
160
|
+
#
|
161
|
+
# Returns a SassC::Script::Value::String.
|
162
|
+
def video_url(path)
|
163
|
+
asset_url(path, type: :video)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Public: Generate url for audio path.
|
167
|
+
#
|
168
|
+
# path - SassC::Script::Value::String URL path
|
169
|
+
#
|
170
|
+
# Returns a SassC::Script::Value::String.
|
171
|
+
def audio_path(path)
|
172
|
+
asset_path(path, type: :audio)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Public: Generate a audio url() link.
|
176
|
+
#
|
177
|
+
# path - SassC::Script::Value::String URL path
|
178
|
+
#
|
179
|
+
# Returns a SassC::Script::Value::String.
|
180
|
+
def audio_url(path)
|
181
|
+
asset_url(path, type: :audio)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Public: Generate url for font path.
|
185
|
+
#
|
186
|
+
# path - SassC::Script::Value::String URL path
|
187
|
+
#
|
188
|
+
# Returns a SassC::Script::Value::String.
|
189
|
+
def font_path(path)
|
190
|
+
asset_path(path, type: :font)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Public: Generate a font url() link.
|
194
|
+
#
|
195
|
+
# path - SassC::Script::Value::String URL path
|
196
|
+
#
|
197
|
+
# Returns a SassC::Script::Value::String.
|
198
|
+
def font_url(path)
|
199
|
+
asset_url(path, type: :font)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Public: Generate url for javascript path.
|
203
|
+
#
|
204
|
+
# path - SassC::Script::Value::String URL path
|
205
|
+
#
|
206
|
+
# Returns a SassC::Script::Value::String.
|
207
|
+
def javascript_path(path)
|
208
|
+
asset_path(path, type: :javascript)
|
209
|
+
end
|
210
|
+
|
211
|
+
# Public: Generate a javascript url() link.
|
212
|
+
#
|
213
|
+
# path - SassC::Script::Value::String URL path
|
214
|
+
#
|
215
|
+
# Returns a SassC::Script::Value::String.
|
216
|
+
def javascript_url(path)
|
217
|
+
asset_url(path, type: :javascript)
|
218
|
+
end
|
219
|
+
|
220
|
+
# Public: Generate url for stylesheet path.
|
221
|
+
#
|
222
|
+
# path - SassC::Script::Value::String URL path
|
223
|
+
#
|
224
|
+
# Returns a SassC::Script::Value::String.
|
225
|
+
def stylesheet_path(path)
|
226
|
+
asset_path(path, type: :stylesheet)
|
227
|
+
end
|
228
|
+
|
229
|
+
# Public: Generate a stylesheet url() link.
|
230
|
+
#
|
231
|
+
# path - SassC::Script::Value::String URL path
|
232
|
+
#
|
233
|
+
# Returns a SassC::Script::Value::String.
|
234
|
+
def stylesheet_url(path)
|
235
|
+
asset_url(path, type: :stylesheet)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Public: Generate a data URI for asset path.
|
239
|
+
#
|
240
|
+
# path - SassC::Script::Value::String logical asset path
|
241
|
+
#
|
242
|
+
# Returns a SassC::Script::Value::String.
|
243
|
+
def asset_data_url(path)
|
244
|
+
url = sprockets_context.asset_data_uri(path.value)
|
245
|
+
Autoload::SassC::Script::Value::String.new("url(" + url + ")")
|
246
|
+
end
|
247
|
+
|
248
|
+
protected
|
249
|
+
# Public: The Environment.
|
250
|
+
#
|
251
|
+
# Returns Sprockets::Environment.
|
252
|
+
def sprockets_environment
|
253
|
+
options[:sprockets][:environment]
|
254
|
+
end
|
255
|
+
|
256
|
+
# Public: Mutatable set of dependencies.
|
257
|
+
#
|
258
|
+
# Returns a Set.
|
259
|
+
def sprockets_dependencies
|
260
|
+
options[:sprockets][:dependencies]
|
261
|
+
end
|
262
|
+
|
263
|
+
# Deprecated: Get the Context instance. Use APIs on
|
264
|
+
# sprockets_environment or sprockets_dependencies directly.
|
265
|
+
#
|
266
|
+
# Returns a Context instance.
|
267
|
+
def sprockets_context
|
268
|
+
options[:sprockets][:context]
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
def engine_options(input, context)
|
274
|
+
merge_options({
|
275
|
+
filename: input[:filename],
|
276
|
+
syntax: self.class.syntax,
|
277
|
+
load_paths: input[:environment].paths,
|
278
|
+
importer: @importer_class,
|
279
|
+
source_map_contents: false,
|
280
|
+
source_map_file: "#{input[:filename]}.map",
|
281
|
+
omit_source_map_url: true,
|
282
|
+
sprockets: {
|
283
|
+
context: context,
|
284
|
+
environment: input[:environment],
|
285
|
+
dependencies: context.metadata[:dependencies]
|
286
|
+
}
|
287
|
+
})
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
class ScsscProcessor < SasscProcessor
|
293
|
+
def self.syntax
|
294
|
+
:scss
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|