jekyll-sass-converter 2.1.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 +95 -105
- data/lib/jekyll/source_map_page.rb +4 -0
- data/lib/jekyll-sass-converter/version.rb +1 -1
- metadata +11 -17
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,7 +40,7 @@ module Jekyll
|
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
38
|
-
ALLOWED_STYLES = %w(
|
43
|
+
ALLOWED_STYLES = %w(expanded compressed).freeze
|
39
44
|
|
40
45
|
# Associate this Converter with the "page" object that manages input and output files for
|
41
46
|
# this converter.
|
@@ -84,25 +89,12 @@ module Jekyll
|
|
84
89
|
@jekyll_sass_configuration ||= begin
|
85
90
|
options = @config["sass"] || {}
|
86
91
|
unless options["style"].nil?
|
87
|
-
options["style"] = options["style"].to_s.
|
92
|
+
options["style"] = options["style"].to_s.delete_prefix(":").to_sym
|
88
93
|
end
|
89
94
|
options
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
93
|
-
def sass_build_configuration_options(overrides)
|
94
|
-
if safe?
|
95
|
-
overrides
|
96
|
-
else
|
97
|
-
Jekyll::Utils.symbolize_hash_keys(
|
98
|
-
Jekyll::Utils.deep_merge_hashes(
|
99
|
-
jekyll_sass_configuration,
|
100
|
-
overrides
|
101
|
-
)
|
102
|
-
)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
98
|
def syntax
|
107
99
|
:scss
|
108
100
|
end
|
@@ -114,8 +106,8 @@ module Jekyll
|
|
114
106
|
end
|
115
107
|
|
116
108
|
def sass_style
|
117
|
-
style = jekyll_sass_configuration
|
118
|
-
ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : :
|
109
|
+
style = jekyll_sass_configuration["style"]
|
110
|
+
ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : :expanded
|
119
111
|
end
|
120
112
|
|
121
113
|
def user_sass_load_paths
|
@@ -123,31 +115,24 @@ module Jekyll
|
|
123
115
|
end
|
124
116
|
|
125
117
|
def sass_dir_relative_to_site_source
|
126
|
-
@sass_dir_relative_to_site_source ||=
|
118
|
+
@sass_dir_relative_to_site_source ||=
|
127
119
|
Jekyll.sanitized_path(site_source, sass_dir).sub(site.source + "/", "")
|
128
|
-
end
|
129
120
|
end
|
130
121
|
|
131
122
|
# rubocop:disable Metrics/AbcSize
|
132
123
|
def sass_load_paths
|
133
124
|
paths = user_sass_load_paths + [sass_dir_relative_to_site_source]
|
134
125
|
|
135
|
-
|
136
|
-
|
137
|
-
paths.map! { |path| Jekyll.sanitized_path(site_source, path) }
|
138
|
-
end
|
126
|
+
# Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
|
127
|
+
paths.map! { |path| Jekyll.sanitized_path(site_source, path) } if safe?
|
139
128
|
|
140
129
|
# Expand file globs (e.g. `node_modules/*/node_modules` )
|
141
130
|
Dir.chdir(site_source) do
|
142
131
|
paths = paths.flat_map { |path| Dir.glob(path) }
|
143
132
|
|
144
133
|
paths.map! do |path|
|
145
|
-
|
146
|
-
|
147
|
-
Jekyll.sanitized_path(site_source, path)
|
148
|
-
else
|
149
|
-
File.expand_path(path)
|
150
|
-
end
|
134
|
+
# Sanitize again in case globbing was able to do something crazy.
|
135
|
+
safe? ? Jekyll.sanitized_path(site_source, path) : File.expand_path(path)
|
151
136
|
end
|
152
137
|
end
|
153
138
|
|
@@ -157,37 +142,37 @@ module Jekyll
|
|
157
142
|
end
|
158
143
|
# rubocop:enable Metrics/AbcSize
|
159
144
|
|
160
|
-
def allow_caching?
|
161
|
-
!safe?
|
162
|
-
end
|
163
|
-
|
164
|
-
def add_charset?
|
165
|
-
!!jekyll_sass_configuration["add_charset"]
|
166
|
-
end
|
167
|
-
|
168
145
|
def sass_configs
|
169
|
-
|
170
|
-
:
|
171
|
-
:
|
172
|
-
:
|
173
|
-
:
|
174
|
-
:
|
175
|
-
:
|
176
|
-
:
|
177
|
-
:
|
178
|
-
:
|
179
|
-
|
146
|
+
{
|
147
|
+
:load_paths => sass_load_paths,
|
148
|
+
:charset => !associate_page_failed?,
|
149
|
+
:source_map => sourcemap_required?,
|
150
|
+
:source_map_include_sources => true,
|
151
|
+
:style => sass_style,
|
152
|
+
:syntax => syntax,
|
153
|
+
:url => sass_file_url,
|
154
|
+
:quiet_deps => quiet_deps_option,
|
155
|
+
:verbose => verbose_option,
|
156
|
+
}
|
180
157
|
end
|
181
158
|
|
182
159
|
def convert(content)
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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
|
173
|
+
rescue ::Sass::CompileError => e
|
174
|
+
Jekyll.logger.error e.full_message
|
175
|
+
raise SyntaxError, e.message
|
191
176
|
end
|
192
177
|
|
193
178
|
private
|
@@ -199,23 +184,11 @@ module Jekyll
|
|
199
184
|
!sass_page
|
200
185
|
end
|
201
186
|
|
202
|
-
# The
|
203
|
-
|
204
|
-
|
205
|
-
# Returns the name of the input file or "stdin" if #associate_page failed
|
206
|
-
def filename
|
207
|
-
return "stdin" if associate_page_failed?
|
208
|
-
|
209
|
-
sass_page.name
|
210
|
-
end
|
187
|
+
# The URL of the input scss (or sass) file. This information will be used for error reporting.
|
188
|
+
def sass_file_url
|
189
|
+
return if associate_page_failed?
|
211
190
|
|
212
|
-
|
213
|
-
# When set to `true` causes the line number and filename of the source be emitted into the
|
214
|
-
# compiled CSS-file. Useful for debugging when the source-map is not available.
|
215
|
-
#
|
216
|
-
# Returns the value of the `line_comments`-option chosen by the user or 'false' by default.
|
217
|
-
def line_comments_option
|
218
|
-
jekyll_sass_configuration.fetch("line_comments", false)
|
191
|
+
file_url_from_path(Jekyll.sanitized_path(site_source, sass_page.relative_path))
|
219
192
|
end
|
220
193
|
|
221
194
|
# The value of the `sourcemap` option chosen by the user.
|
@@ -237,55 +210,72 @@ module Jekyll
|
|
237
210
|
!(sourcemap_option == :development && Jekyll.env != "development")
|
238
211
|
end
|
239
212
|
|
240
|
-
|
241
|
-
|
242
|
-
#
|
243
|
-
# Returns the name of the css file or "stdin.css" if #associate_page failed
|
244
|
-
def output_path
|
245
|
-
return "stdin.css" if associate_page_failed?
|
213
|
+
def source_map_page
|
214
|
+
return if associate_page_failed?
|
246
215
|
|
247
|
-
|
216
|
+
@source_map_page ||= SourceMapPage.new(sass_page)
|
248
217
|
end
|
249
218
|
|
250
|
-
#
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
256
227
|
|
257
|
-
|
228
|
+
# Converts file urls in source map to relative paths.
|
229
|
+
#
|
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)
|
258
241
|
end
|
259
242
|
|
260
|
-
|
243
|
+
# Adds the source-map to the source-map-page and adds it to `site.pages`.
|
244
|
+
def generate_source_map_page(source_map)
|
261
245
|
return if associate_page_failed?
|
262
246
|
|
263
|
-
|
247
|
+
source_map_page.source_map(source_map)
|
248
|
+
site.pages << source_map_page
|
264
249
|
end
|
265
250
|
|
266
|
-
#
|
267
|
-
|
268
|
-
# @param [::SassC::Engine] engine The sass Compiler engine.
|
269
|
-
def generate_source_map(engine)
|
251
|
+
# Returns a source mapping url for given source-map.
|
252
|
+
def source_mapping_url
|
270
253
|
return if associate_page_failed?
|
271
254
|
|
272
|
-
|
273
|
-
site.pages << source_map_page
|
274
|
-
rescue ::SassC::NotRenderedError => e
|
275
|
-
Jekyll.logger.warn "Could not generate source map #{e.message} => #{e.cause}"
|
255
|
+
Addressable::URI.encode(sass_page.basename + ".css.map")
|
276
256
|
end
|
277
257
|
|
278
258
|
def site
|
279
|
-
|
280
|
-
Jekyll.sites.last
|
281
|
-
else
|
282
|
-
sass_page.site
|
283
|
-
end
|
259
|
+
associate_page_failed? ? Jekyll.sites.last : sass_page.site
|
284
260
|
end
|
285
261
|
|
286
262
|
def site_source
|
287
263
|
site.source
|
288
264
|
end
|
265
|
+
|
266
|
+
def file_url_from_path(path)
|
267
|
+
Addressable::URI.encode("file://#{path.start_with?("/") ? "" : "/"}#{path}")
|
268
|
+
end
|
269
|
+
|
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)
|
273
|
+
end
|
274
|
+
|
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)
|
278
|
+
end
|
289
279
|
end
|
290
280
|
end
|
291
281
|
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:
|
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
|
@@ -78,14 +72,14 @@ dependencies:
|
|
78
72
|
requirements:
|
79
73
|
- - "~>"
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
75
|
+
version: 0.12.0
|
82
76
|
type: :development
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - "~>"
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
82
|
+
version: 0.12.0
|
89
83
|
description:
|
90
84
|
email:
|
91
85
|
- parkrmoore@gmail.com
|
@@ -110,14 +104,14 @@ 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
|
- - ">="
|
117
111
|
- !ruby/object:Gem::Version
|
118
112
|
version: '0'
|
119
113
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
114
|
+
rubygems_version: 3.1.6
|
121
115
|
signing_key:
|
122
116
|
specification_version: 4
|
123
117
|
summary: A basic Sass converter for Jekyll.
|