jekyll-sass-converter 2.1.0 → 2.2.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 +4 -4
- data/lib/jekyll/converters/scss.rb +94 -33
- data/lib/jekyll/source_map_page.rb +4 -0
- data/lib/jekyll-sass-converter/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8210a4fb569272e154c0f114f04ec1a3d71ae306c9c4f2afc1fa19d96437f0c7
|
4
|
+
data.tar.gz: 02be36d0eef40d451be28efb65396093de0e1cee3b44843bb41cc19fb0e5a02b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e5420795ee103377c6562ec3e9435991af4a85981f96605f6e2c99e8ec203182ed9b21ea0a5ceabc4a7e5335fc4558fd53920f1958efafac22c0d3da4783c64
|
7
|
+
data.tar.gz: 2da5d0b5f96885c5e3357d1790679c62d129bb2cfa261578ead2e9dc5be562a7baf488118b441effd3c6619adebe7a10698c756d4a7e2eac92c2560d63fd2518
|
@@ -35,6 +35,7 @@ module Jekyll
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
ALLOWED_IMPLEMENTATIONS = %w(sassc sass-embedded).freeze
|
38
39
|
ALLOWED_STYLES = %w(nested expanded compact compressed).freeze
|
39
40
|
|
40
41
|
# Associate this Converter with the "page" object that manages input and output files for
|
@@ -91,16 +92,11 @@ module Jekyll
|
|
91
92
|
end
|
92
93
|
|
93
94
|
def sass_build_configuration_options(overrides)
|
94
|
-
if safe?
|
95
|
-
|
96
|
-
|
97
|
-
Jekyll::Utils.
|
98
|
-
|
99
|
-
jekyll_sass_configuration,
|
100
|
-
overrides
|
101
|
-
)
|
102
|
-
)
|
103
|
-
end
|
95
|
+
return overrides if safe?
|
96
|
+
|
97
|
+
Jekyll::Utils.symbolize_hash_keys(
|
98
|
+
Jekyll::Utils.deep_merge_hashes(jekyll_sass_configuration, overrides)
|
99
|
+
)
|
104
100
|
end
|
105
101
|
|
106
102
|
def syntax
|
@@ -113,9 +109,17 @@ module Jekyll
|
|
113
109
|
jekyll_sass_configuration["sass_dir"]
|
114
110
|
end
|
115
111
|
|
112
|
+
def sass_implementation
|
113
|
+
implementation = jekyll_sass_configuration["implementation"]
|
114
|
+
ALLOWED_IMPLEMENTATIONS.include?(implementation) ? implementation : "sassc"
|
115
|
+
end
|
116
|
+
|
116
117
|
def sass_style
|
117
|
-
style
|
118
|
-
|
118
|
+
# `:expanded` is the default output style for newer sass implementations.
|
119
|
+
# For backward compatibility, `:compact` is kept as the default output style for sassc.
|
120
|
+
default = sass_implementation == "sassc" ? :compact : :expanded
|
121
|
+
style = jekyll_sass_configuration.fetch("style", default)
|
122
|
+
ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : default
|
119
123
|
end
|
120
124
|
|
121
125
|
def user_sass_load_paths
|
@@ -132,22 +136,16 @@ module Jekyll
|
|
132
136
|
def sass_load_paths
|
133
137
|
paths = user_sass_load_paths + [sass_dir_relative_to_site_source]
|
134
138
|
|
135
|
-
|
136
|
-
|
137
|
-
paths.map! { |path| Jekyll.sanitized_path(site_source, path) }
|
138
|
-
end
|
139
|
+
# Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
|
140
|
+
paths.map! { |path| Jekyll.sanitized_path(site_source, path) } if safe?
|
139
141
|
|
140
142
|
# Expand file globs (e.g. `node_modules/*/node_modules` )
|
141
143
|
Dir.chdir(site_source) do
|
142
144
|
paths = paths.flat_map { |path| Dir.glob(path) }
|
143
145
|
|
144
146
|
paths.map! do |path|
|
145
|
-
|
146
|
-
|
147
|
-
Jekyll.sanitized_path(site_source, path)
|
148
|
-
else
|
149
|
-
File.expand_path(path)
|
150
|
-
end
|
147
|
+
# Sanitize again in case globbing was able to do something crazy.
|
148
|
+
safe? ? Jekyll.sanitized_path(site_source, path) : File.expand_path(path)
|
151
149
|
end
|
152
150
|
end
|
153
151
|
|
@@ -180,17 +178,50 @@ module Jekyll
|
|
180
178
|
end
|
181
179
|
|
182
180
|
def convert(content)
|
181
|
+
case sass_implementation
|
182
|
+
when "sass-embedded"
|
183
|
+
Jekyll::External.require_with_graceful_fail("sass-embedded")
|
184
|
+
sass_embedded_convert(content)
|
185
|
+
when "sassc"
|
186
|
+
sass_convert(content)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def sass_convert(content)
|
183
193
|
config = sass_configs
|
184
194
|
engine = SassC::Engine.new(content.dup, config)
|
185
195
|
output = engine.render
|
186
|
-
|
196
|
+
sass_generate_source_map(engine) if sourcemap_required?
|
187
197
|
replacement = add_charset? ? '@charset "UTF-8";' : ""
|
188
198
|
output.sub(BYTE_ORDER_MARK, replacement)
|
189
199
|
rescue SassC::SyntaxError => e
|
190
200
|
raise SyntaxError, e.to_s
|
191
201
|
end
|
192
202
|
|
193
|
-
|
203
|
+
def sass_embedded_config
|
204
|
+
{
|
205
|
+
:load_paths => sass_load_paths,
|
206
|
+
:source_map => sourcemap_required?,
|
207
|
+
:source_map_include_sources => true,
|
208
|
+
:style => sass_style,
|
209
|
+
:syntax => syntax == :sass ? :indented : syntax,
|
210
|
+
:url => sass_file_url,
|
211
|
+
}
|
212
|
+
end
|
213
|
+
|
214
|
+
def sass_embedded_convert(content)
|
215
|
+
output = ::Sass.compile_string(content, **sass_embedded_config)
|
216
|
+
sass_embedded_generate_source_map(output.source_map) if sourcemap_required?
|
217
|
+
replacement = add_charset? ? '@charset "UTF-8";' : ""
|
218
|
+
source_mapping_url = Addressable::URI.encode(File.basename(source_map_file))
|
219
|
+
eof = sourcemap_required? ? "\n\n/*# sourceMappingURL=#{source_mapping_url} */" : "\n"
|
220
|
+
output.css.sub(BYTE_ORDER_MARK, replacement) + eof
|
221
|
+
rescue ::Sass::CompileError => e
|
222
|
+
Jekyll.logger.error e.full_message
|
223
|
+
raise SyntaxError, e.message
|
224
|
+
end
|
194
225
|
|
195
226
|
# The Page instance for which this object acts as a converter.
|
196
227
|
attr_reader :sass_page
|
@@ -206,7 +237,14 @@ module Jekyll
|
|
206
237
|
def filename
|
207
238
|
return "stdin" if associate_page_failed?
|
208
239
|
|
209
|
-
sass_page.name
|
240
|
+
File.join(site_source_relative_from_pwd, sass_page.name)
|
241
|
+
end
|
242
|
+
|
243
|
+
# The URL of the input scss (or sass) file. This information will be used for error reporting.
|
244
|
+
def sass_file_url
|
245
|
+
return if associate_page_failed?
|
246
|
+
|
247
|
+
file_url_from_path(File.join(site_source, sass_page.relative_path))
|
210
248
|
end
|
211
249
|
|
212
250
|
# The value of the `line_comments` option.
|
@@ -244,7 +282,7 @@ module Jekyll
|
|
244
282
|
def output_path
|
245
283
|
return "stdin.css" if associate_page_failed?
|
246
284
|
|
247
|
-
sass_page.basename + ".css"
|
285
|
+
File.join(site_source_relative_from_pwd, sass_page.basename + ".css")
|
248
286
|
end
|
249
287
|
|
250
288
|
# The name of the generated source map file. This information will be written into the
|
@@ -254,7 +292,7 @@ module Jekyll
|
|
254
292
|
def source_map_file
|
255
293
|
return "" if associate_page_failed?
|
256
294
|
|
257
|
-
sass_page.basename + ".css.map"
|
295
|
+
File.join(site_source_relative_from_pwd, sass_page.basename + ".css.map")
|
258
296
|
end
|
259
297
|
|
260
298
|
def source_map_page
|
@@ -266,7 +304,7 @@ module Jekyll
|
|
266
304
|
# Reads the source-map from the engine and adds it to the source-map-page.
|
267
305
|
#
|
268
306
|
# @param [::SassC::Engine] engine The sass Compiler engine.
|
269
|
-
def
|
307
|
+
def sass_generate_source_map(engine)
|
270
308
|
return if associate_page_failed?
|
271
309
|
|
272
310
|
source_map_page.source_map(engine.source_map)
|
@@ -275,17 +313,40 @@ module Jekyll
|
|
275
313
|
Jekyll.logger.warn "Could not generate source map #{e.message} => #{e.cause}"
|
276
314
|
end
|
277
315
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
316
|
+
# Reads the source-map and adds it to the source-map-page.
|
317
|
+
def sass_embedded_generate_source_map(source_map)
|
318
|
+
return if associate_page_failed?
|
319
|
+
|
320
|
+
map_data = JSON.parse(source_map)
|
321
|
+
map_data["file"] = Addressable::URI.encode(File.basename(output_path))
|
322
|
+
map_data["sources"].map! do |s|
|
323
|
+
s.start_with?("file:") ? Addressable::URI.parse(s).route_from(site_source_url) : s
|
283
324
|
end
|
325
|
+
|
326
|
+
source_map_page.source_map(JSON.generate(map_data))
|
327
|
+
site.pages << source_map_page
|
328
|
+
end
|
329
|
+
|
330
|
+
def site
|
331
|
+
associate_page_failed? ? Jekyll.sites.last : sass_page.site
|
284
332
|
end
|
285
333
|
|
286
334
|
def site_source
|
287
335
|
site.source
|
288
336
|
end
|
337
|
+
|
338
|
+
def site_source_relative_from_pwd
|
339
|
+
@site_source_relative_from_pwd ||=
|
340
|
+
Pathname.new(site_source).relative_path_from(Pathname.new(Dir.pwd)).to_s
|
341
|
+
end
|
342
|
+
|
343
|
+
def site_source_url
|
344
|
+
@site_source_url ||= file_url_from_path("#{site_source}/")
|
345
|
+
end
|
346
|
+
|
347
|
+
def file_url_from_path(path)
|
348
|
+
Addressable::URI.encode("file://#{path.start_with?("/") ? "" : "/"}#{path}")
|
349
|
+
end
|
289
350
|
end
|
290
351
|
end
|
291
352
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-sass-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sassc
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 0.12.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 0.12.0
|
89
89
|
description:
|
90
90
|
email:
|
91
91
|
- parkrmoore@gmail.com
|
@@ -110,14 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: 2.
|
113
|
+
version: 2.5.0
|
114
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.1.6
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: A basic Sass converter for Jekyll.
|