jekyll-sass-converter 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/converters/sass.rb +1 -3
- data/lib/jekyll/converters/scss.rb +72 -143
- data/lib/jekyll-sass-converter/version.rb +1 -1
- metadata +8 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 209c38f2d63adbcdca7275d57fa6e967f7adcdc8bd91d5b4b1e789e91d523889
|
4
|
+
data.tar.gz: 81cc00baf45c4d2375dd1b9bbe004b0c76daaaefbfb391e2b3233743704e51e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a35508f75db53b77b32b8d662a29857086b83e9f7d73608d6d25ff0daf56e48b1d43b54be20efe54b4ac1093a292c68f3054bf734d9153b632059d6edd1065c
|
7
|
+
data.tar.gz: d53beb7e645c9da162debcfae72246ead2d2fd71381eb5f2da65e6bd77f41e1cc05902ddb88136e9145674bdf68d6290f83ba42c3f44977bc4b7042eff09b811
|
@@ -1,13 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require "
|
5
|
-
|
3
|
+
# stdlib
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
# 3rd party
|
7
|
+
require "addressable/uri"
|
8
|
+
require "sass-embedded"
|
9
|
+
|
10
|
+
# internal
|
11
|
+
require_relative "../source_map_page"
|
6
12
|
|
7
13
|
module Jekyll
|
8
14
|
module Converters
|
9
15
|
class Scss < Converter
|
10
|
-
BYTE_ORDER_MARK = %r!^\xEF\xBB\xBF!.freeze
|
11
16
|
EXTENSION_PATTERN = %r!^\.scss$!i.freeze
|
12
17
|
|
13
18
|
SyntaxError = Class.new(ArgumentError)
|
@@ -35,8 +40,7 @@ module Jekyll
|
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
38
|
-
|
39
|
-
ALLOWED_STYLES = %w(nested expanded compact compressed).freeze
|
43
|
+
ALLOWED_STYLES = %w(expanded compressed).freeze
|
40
44
|
|
41
45
|
# Associate this Converter with the "page" object that manages input and output files for
|
42
46
|
# this converter.
|
@@ -85,20 +89,12 @@ module Jekyll
|
|
85
89
|
@jekyll_sass_configuration ||= begin
|
86
90
|
options = @config["sass"] || {}
|
87
91
|
unless options["style"].nil?
|
88
|
-
options["style"] = options["style"].to_s.
|
92
|
+
options["style"] = options["style"].to_s.delete_prefix(":").to_sym
|
89
93
|
end
|
90
94
|
options
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
94
|
-
def sass_build_configuration_options(overrides)
|
95
|
-
return overrides if safe?
|
96
|
-
|
97
|
-
Jekyll::Utils.symbolize_hash_keys(
|
98
|
-
Jekyll::Utils.deep_merge_hashes(jekyll_sass_configuration, overrides)
|
99
|
-
)
|
100
|
-
end
|
101
|
-
|
102
98
|
def syntax
|
103
99
|
:scss
|
104
100
|
end
|
@@ -109,17 +105,9 @@ module Jekyll
|
|
109
105
|
jekyll_sass_configuration["sass_dir"]
|
110
106
|
end
|
111
107
|
|
112
|
-
def sass_implementation
|
113
|
-
implementation = jekyll_sass_configuration["implementation"]
|
114
|
-
ALLOWED_IMPLEMENTATIONS.include?(implementation) ? implementation : "sassc"
|
115
|
-
end
|
116
|
-
|
117
108
|
def sass_style
|
118
|
-
|
119
|
-
|
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
|
109
|
+
style = jekyll_sass_configuration["style"]
|
110
|
+
ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : :expanded
|
123
111
|
end
|
124
112
|
|
125
113
|
def user_sass_load_paths
|
@@ -127,9 +115,8 @@ module Jekyll
|
|
127
115
|
end
|
128
116
|
|
129
117
|
def sass_dir_relative_to_site_source
|
130
|
-
@sass_dir_relative_to_site_source ||=
|
118
|
+
@sass_dir_relative_to_site_source ||=
|
131
119
|
Jekyll.sanitized_path(site_source, sass_dir).sub(site.source + "/", "")
|
132
|
-
end
|
133
120
|
end
|
134
121
|
|
135
122
|
# rubocop:disable Metrics/AbcSize
|
@@ -155,74 +142,41 @@ module Jekyll
|
|
155
142
|
end
|
156
143
|
# rubocop:enable Metrics/AbcSize
|
157
144
|
|
158
|
-
def allow_caching?
|
159
|
-
!safe?
|
160
|
-
end
|
161
|
-
|
162
|
-
def add_charset?
|
163
|
-
!!jekyll_sass_configuration["add_charset"]
|
164
|
-
end
|
165
|
-
|
166
145
|
def sass_configs
|
167
|
-
sass_build_configuration_options(
|
168
|
-
:style => sass_style,
|
169
|
-
:syntax => syntax,
|
170
|
-
:filename => filename,
|
171
|
-
:output_path => output_path,
|
172
|
-
:source_map_file => source_map_file,
|
173
|
-
:load_paths => sass_load_paths,
|
174
|
-
:omit_source_map_url => !sourcemap_required?,
|
175
|
-
:source_map_contents => true,
|
176
|
-
:line_comments_option => line_comments_option
|
177
|
-
)
|
178
|
-
end
|
179
|
-
|
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)
|
193
|
-
config = sass_configs
|
194
|
-
engine = SassC::Engine.new(content.dup, config)
|
195
|
-
output = engine.render
|
196
|
-
sass_generate_source_map(engine) if sourcemap_required?
|
197
|
-
replacement = add_charset? ? '@charset "UTF-8";' : ""
|
198
|
-
output.sub(BYTE_ORDER_MARK, replacement)
|
199
|
-
rescue SassC::SyntaxError => e
|
200
|
-
raise SyntaxError, e.to_s
|
201
|
-
end
|
202
|
-
|
203
|
-
def sass_embedded_config
|
204
146
|
{
|
205
147
|
:load_paths => sass_load_paths,
|
148
|
+
:charset => !associate_page_failed?,
|
206
149
|
:source_map => sourcemap_required?,
|
207
150
|
:source_map_include_sources => true,
|
208
151
|
:style => sass_style,
|
209
|
-
:syntax => syntax
|
152
|
+
:syntax => syntax,
|
210
153
|
:url => sass_file_url,
|
154
|
+
:quiet_deps => quiet_deps_option,
|
155
|
+
:verbose => verbose_option,
|
211
156
|
}
|
212
157
|
end
|
213
158
|
|
214
|
-
def
|
215
|
-
output = ::Sass.compile_string(content, **
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
159
|
+
def convert(content)
|
160
|
+
output = ::Sass.compile_string(content, **sass_configs)
|
161
|
+
result = output.css
|
162
|
+
|
163
|
+
if sourcemap_required?
|
164
|
+
source_map = process_source_map(output.source_map)
|
165
|
+
generate_source_map_page(source_map)
|
166
|
+
|
167
|
+
if (sm_url = source_mapping_url)
|
168
|
+
result += "#{sass_style == :compressed ? "" : "\n\n"}/*# sourceMappingURL=#{sm_url} */"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
result
|
221
173
|
rescue ::Sass::CompileError => e
|
222
174
|
Jekyll.logger.error e.full_message
|
223
175
|
raise SyntaxError, e.message
|
224
176
|
end
|
225
177
|
|
178
|
+
private
|
179
|
+
|
226
180
|
# The Page instance for which this object acts as a converter.
|
227
181
|
attr_reader :sass_page
|
228
182
|
|
@@ -230,30 +184,11 @@ module Jekyll
|
|
230
184
|
!sass_page
|
231
185
|
end
|
232
186
|
|
233
|
-
# The name of the input scss (or sass) file. This information will be used for error
|
234
|
-
# reporting and will written into the source map file as main source.
|
235
|
-
#
|
236
|
-
# Returns the name of the input file or "stdin" if #associate_page failed
|
237
|
-
def filename
|
238
|
-
return "stdin" if associate_page_failed?
|
239
|
-
|
240
|
-
File.join(site_source_relative_from_pwd, sass_page.name)
|
241
|
-
end
|
242
|
-
|
243
187
|
# The URL of the input scss (or sass) file. This information will be used for error reporting.
|
244
188
|
def sass_file_url
|
245
189
|
return if associate_page_failed?
|
246
190
|
|
247
|
-
file_url_from_path(
|
248
|
-
end
|
249
|
-
|
250
|
-
# The value of the `line_comments` option.
|
251
|
-
# When set to `true` causes the line number and filename of the source be emitted into the
|
252
|
-
# compiled CSS-file. Useful for debugging when the source-map is not available.
|
253
|
-
#
|
254
|
-
# Returns the value of the `line_comments`-option chosen by the user or 'false' by default.
|
255
|
-
def line_comments_option
|
256
|
-
jekyll_sass_configuration.fetch("line_comments", false)
|
191
|
+
file_url_from_path(Jekyll.sanitized_path(site_source, sass_page.relative_path))
|
257
192
|
end
|
258
193
|
|
259
194
|
# The value of the `sourcemap` option chosen by the user.
|
@@ -275,56 +210,49 @@ module Jekyll
|
|
275
210
|
!(sourcemap_option == :development && Jekyll.env != "development")
|
276
211
|
end
|
277
212
|
|
278
|
-
# The name of the generated css file. This information will be written into the source map
|
279
|
-
# file as a backward reference to the input.
|
280
|
-
#
|
281
|
-
# Returns the name of the css file or "stdin.css" if #associate_page failed
|
282
|
-
def output_path
|
283
|
-
return "stdin.css" if associate_page_failed?
|
284
|
-
|
285
|
-
File.join(site_source_relative_from_pwd, sass_page.basename + ".css")
|
286
|
-
end
|
287
|
-
|
288
|
-
# The name of the generated source map file. This information will be written into the
|
289
|
-
# css file to reference to the source map.
|
290
|
-
#
|
291
|
-
# Returns the name of the css file or "" if #associate_page failed
|
292
|
-
def source_map_file
|
293
|
-
return "" if associate_page_failed?
|
294
|
-
|
295
|
-
File.join(site_source_relative_from_pwd, sass_page.basename + ".css.map")
|
296
|
-
end
|
297
|
-
|
298
213
|
def source_map_page
|
299
214
|
return if associate_page_failed?
|
300
215
|
|
301
216
|
@source_map_page ||= SourceMapPage.new(sass_page)
|
302
217
|
end
|
303
218
|
|
304
|
-
#
|
219
|
+
# Returns the directory that source map sources are relative to.
|
220
|
+
def sass_source_root
|
221
|
+
if associate_page_failed?
|
222
|
+
site_source
|
223
|
+
else
|
224
|
+
Jekyll.sanitized_path(site_source, File.dirname(sass_page.relative_path))
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# Converts file urls in source map to relative paths.
|
305
229
|
#
|
306
|
-
#
|
307
|
-
def
|
230
|
+
# Returns processed source map string.
|
231
|
+
def process_source_map(source_map)
|
232
|
+
map_data = JSON.parse(source_map)
|
233
|
+
unless associate_page_failed?
|
234
|
+
map_data["file"] = Addressable::URI.encode(sass_page.basename + ".css")
|
235
|
+
end
|
236
|
+
source_root_url = Addressable::URI.parse(file_url_from_path("#{sass_source_root}/"))
|
237
|
+
map_data["sources"].map! do |s|
|
238
|
+
s.start_with?("file:") ? Addressable::URI.parse(s).route_from(source_root_url).to_s : s
|
239
|
+
end
|
240
|
+
JSON.generate(map_data)
|
241
|
+
end
|
242
|
+
|
243
|
+
# Adds the source-map to the source-map-page and adds it to `site.pages`.
|
244
|
+
def generate_source_map_page(source_map)
|
308
245
|
return if associate_page_failed?
|
309
246
|
|
310
|
-
source_map_page.source_map(
|
247
|
+
source_map_page.source_map(source_map)
|
311
248
|
site.pages << source_map_page
|
312
|
-
rescue ::SassC::NotRenderedError => e
|
313
|
-
Jekyll.logger.warn "Could not generate source map #{e.message} => #{e.cause}"
|
314
249
|
end
|
315
250
|
|
316
|
-
#
|
317
|
-
def
|
251
|
+
# Returns a source mapping url for given source-map.
|
252
|
+
def source_mapping_url
|
318
253
|
return if associate_page_failed?
|
319
254
|
|
320
|
-
|
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
|
324
|
-
end
|
325
|
-
|
326
|
-
source_map_page.source_map(JSON.generate(map_data))
|
327
|
-
site.pages << source_map_page
|
255
|
+
Addressable::URI.encode(sass_page.basename + ".css.map")
|
328
256
|
end
|
329
257
|
|
330
258
|
def site
|
@@ -335,17 +263,18 @@ module Jekyll
|
|
335
263
|
site.source
|
336
264
|
end
|
337
265
|
|
338
|
-
def
|
339
|
-
|
340
|
-
Pathname.new(site_source).relative_path_from(Pathname.new(Dir.pwd)).to_s
|
266
|
+
def file_url_from_path(path)
|
267
|
+
Addressable::URI.encode("file://#{path.start_with?("/") ? "" : "/"}#{path}")
|
341
268
|
end
|
342
269
|
|
343
|
-
|
344
|
-
|
270
|
+
# Returns the value of the `quiet_deps`-option chosen by the user or 'false' by default.
|
271
|
+
def quiet_deps_option
|
272
|
+
!!jekyll_sass_configuration.fetch("quiet_deps", false)
|
345
273
|
end
|
346
274
|
|
347
|
-
|
348
|
-
|
275
|
+
# Returns the value of the `verbose`-option chosen by the user or 'false' by default.
|
276
|
+
def verbose_option
|
277
|
+
!!jekyll_sass_configuration.fetch("verbose", false)
|
349
278
|
end
|
350
279
|
end
|
351
280
|
end
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-sass-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.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: 2022-
|
11
|
+
date: 2022-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: sass-embedded
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.1
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
19
|
+
version: '1.54'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.0.1
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
26
|
+
version: '1.54'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: bundler
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
104
|
requirements:
|
111
105
|
- - ">="
|
112
106
|
- !ruby/object:Gem::Version
|
113
|
-
version: 2.
|
107
|
+
version: 2.6.0
|
114
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
109
|
requirements:
|
116
110
|
- - ">="
|