jekyll-sass-converter 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c051522099eb9c977d893591246ad37863d0ff38feec276b8992c9f16cfa6b3b
4
- data.tar.gz: 388b71b1d56dcde5f45b9860b28ba932291951cf2385e42560032b3c4e144c5f
3
+ metadata.gz: 8210a4fb569272e154c0f114f04ec1a3d71ae306c9c4f2afc1fa19d96437f0c7
4
+ data.tar.gz: 02be36d0eef40d451be28efb65396093de0e1cee3b44843bb41cc19fb0e5a02b
5
5
  SHA512:
6
- metadata.gz: 0b2c4cd74ba4ee2612c92394011d98f6db389078d3668ccebe3cf96ef855c5a1a72c9dbe47057f3cc586b1dac2937379ee02356e289fdbf96869ad860e2ad1c3
7
- data.tar.gz: 275e76080d121f8693b42d1ca46088a0328013b111c8eddc4a998baafd04990ed9ff6cad5ac7246198c79bf63aad7e3ff556a2bbe9d6ffd0a0582dc259daec68
6
+ metadata.gz: 8e5420795ee103377c6562ec3e9435991af4a85981f96605f6e2c99e8ec203182ed9b21ea0a5ceabc4a7e5335fc4558fd53920f1958efafac22c0d3da4783c64
7
+ data.tar.gz: 2da5d0b5f96885c5e3357d1790679c62d129bb2cfa261578ead2e9dc5be562a7baf488118b441effd3c6619adebe7a10698c756d4a7e2eac92c2560d63fd2518
@@ -18,6 +18,8 @@ module Jekyll
18
18
  # This hook is triggered just before the method {#convert(content)} is executed, it
19
19
  # associates the Scss (and Sass) converters with their respective sass_page objects.
20
20
  Jekyll::Hooks.register :pages, :pre_render do |page|
21
+ next unless page.is_a?(Jekyll::Page)
22
+
21
23
  page.converters.each do |converter|
22
24
  converter.associate_page(page) if converter.is_a?(Jekyll::Converters::Scss)
23
25
  end
@@ -26,11 +28,14 @@ module Jekyll
26
28
  # This hook is triggered just after the method {#convert(content)} has been executed, it
27
29
  # dissociates the Scss (and Sass) converters with their respective sass_page objects.
28
30
  Jekyll::Hooks.register :pages, :post_render do |page|
31
+ next unless page.is_a?(Jekyll::Page)
32
+
29
33
  page.converters.each do |converter|
30
34
  converter.dissociate_page(page) if converter.is_a?(Jekyll::Converters::Scss)
31
35
  end
32
36
  end
33
37
 
38
+ ALLOWED_IMPLEMENTATIONS = %w(sassc sass-embedded).freeze
34
39
  ALLOWED_STYLES = %w(nested expanded compact compressed).freeze
35
40
 
36
41
  # Associate this Converter with the "page" object that manages input and output files for
@@ -87,16 +92,11 @@ module Jekyll
87
92
  end
88
93
 
89
94
  def sass_build_configuration_options(overrides)
90
- if safe?
91
- overrides
92
- else
93
- Jekyll::Utils.symbolize_hash_keys(
94
- Jekyll::Utils.deep_merge_hashes(
95
- jekyll_sass_configuration,
96
- overrides
97
- )
98
- )
99
- end
95
+ return overrides if safe?
96
+
97
+ Jekyll::Utils.symbolize_hash_keys(
98
+ Jekyll::Utils.deep_merge_hashes(jekyll_sass_configuration, overrides)
99
+ )
100
100
  end
101
101
 
102
102
  def syntax
@@ -109,9 +109,17 @@ module Jekyll
109
109
  jekyll_sass_configuration["sass_dir"]
110
110
  end
111
111
 
112
+ def sass_implementation
113
+ implementation = jekyll_sass_configuration["implementation"]
114
+ ALLOWED_IMPLEMENTATIONS.include?(implementation) ? implementation : "sassc"
115
+ end
116
+
112
117
  def sass_style
113
- style = jekyll_sass_configuration.fetch("style", :compact)
114
- ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : :compact
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
115
123
  end
116
124
 
117
125
  def user_sass_load_paths
@@ -119,33 +127,30 @@ module Jekyll
119
127
  end
120
128
 
121
129
  def sass_dir_relative_to_site_source
122
- Jekyll.sanitized_path(site_source, sass_dir)
130
+ @sass_dir_relative_to_site_source ||= begin
131
+ Jekyll.sanitized_path(site_source, sass_dir).sub(site.source + "/", "")
132
+ end
123
133
  end
124
134
 
125
135
  # rubocop:disable Metrics/AbcSize
126
136
  def sass_load_paths
127
137
  paths = user_sass_load_paths + [sass_dir_relative_to_site_source]
128
- paths << site.theme.sass_path if site.theme&.sass_path
129
138
 
130
- if safe?
131
- # Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
132
- paths.map! { |path| Jekyll.sanitized_path(site_source, path) }
133
- end
139
+ # Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
140
+ paths.map! { |path| Jekyll.sanitized_path(site_source, path) } if safe?
134
141
 
135
142
  # Expand file globs (e.g. `node_modules/*/node_modules` )
136
143
  Dir.chdir(site_source) do
137
- paths = paths.flat_map { |path| Dir.glob(path) }.uniq
144
+ paths = paths.flat_map { |path| Dir.glob(path) }
138
145
 
139
146
  paths.map! do |path|
140
- if safe?
141
- # Sanitize again in case globbing was able to do something crazy.
142
- Jekyll.sanitized_path(site_source, path)
143
- else
144
- File.expand_path(path)
145
- 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)
146
149
  end
147
150
  end
148
151
 
152
+ paths.uniq!
153
+ paths << site.theme.sass_path if site.theme&.sass_path
149
154
  paths.select { |path| File.directory?(path) }
150
155
  end
151
156
  # rubocop:enable Metrics/AbcSize
@@ -173,17 +178,50 @@ module Jekyll
173
178
  end
174
179
 
175
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)
176
193
  config = sass_configs
177
194
  engine = SassC::Engine.new(content.dup, config)
178
195
  output = engine.render
179
- generate_source_map(engine) if sourcemap_required?
196
+ sass_generate_source_map(engine) if sourcemap_required?
180
197
  replacement = add_charset? ? '@charset "UTF-8";' : ""
181
198
  output.sub(BYTE_ORDER_MARK, replacement)
182
199
  rescue SassC::SyntaxError => e
183
200
  raise SyntaxError, e.to_s
184
201
  end
185
202
 
186
- private
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
187
225
 
188
226
  # The Page instance for which this object acts as a converter.
189
227
  attr_reader :sass_page
@@ -199,7 +237,14 @@ module Jekyll
199
237
  def filename
200
238
  return "stdin" if associate_page_failed?
201
239
 
202
- 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))
203
248
  end
204
249
 
205
250
  # The value of the `line_comments` option.
@@ -237,7 +282,7 @@ module Jekyll
237
282
  def output_path
238
283
  return "stdin.css" if associate_page_failed?
239
284
 
240
- sass_page.basename + ".css"
285
+ File.join(site_source_relative_from_pwd, sass_page.basename + ".css")
241
286
  end
242
287
 
243
288
  # The name of the generated source map file. This information will be written into the
@@ -247,7 +292,7 @@ module Jekyll
247
292
  def source_map_file
248
293
  return "" if associate_page_failed?
249
294
 
250
- sass_page.basename + ".css.map"
295
+ File.join(site_source_relative_from_pwd, sass_page.basename + ".css.map")
251
296
  end
252
297
 
253
298
  def source_map_page
@@ -259,7 +304,7 @@ module Jekyll
259
304
  # Reads the source-map from the engine and adds it to the source-map-page.
260
305
  #
261
306
  # @param [::SassC::Engine] engine The sass Compiler engine.
262
- def generate_source_map(engine)
307
+ def sass_generate_source_map(engine)
263
308
  return if associate_page_failed?
264
309
 
265
310
  source_map_page.source_map(engine.source_map)
@@ -268,17 +313,40 @@ module Jekyll
268
313
  Jekyll.logger.warn "Could not generate source map #{e.message} => #{e.cause}"
269
314
  end
270
315
 
271
- def site
272
- if associate_page_failed?
273
- Jekyll.sites.last
274
- else
275
- sass_page.site
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
276
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
277
332
  end
278
333
 
279
334
  def site_source
280
335
  site.source
281
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
282
350
  end
283
351
  end
284
352
  end
@@ -29,6 +29,10 @@ module Jekyll
29
29
  true
30
30
  end
31
31
 
32
+ def render_with_liquid?
33
+ false
34
+ end
35
+
32
36
  # @return[String] the object as a debug String.
33
37
  def inspect
34
38
  "#<#{self.class} @name=#{name.inspect}>"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllSassConverter
4
- VERSION = "2.0.0"
4
+ VERSION = "2.2.0"
5
5
  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.0.0
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: 2019-08-14 00:00:00.000000000 Z
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: '0.4'
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: '0.4'
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.4.0
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.0.4
120
+ rubygems_version: 3.1.6
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: A basic Sass converter for Jekyll.