sassc-embedded 1.5.3 → 1.5.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b84338d9d4ffba85e3b720f4a2683710800e9f44b15d03f0763de93882963a7a
4
- data.tar.gz: 8e0945ad581b851d3dae2415f9f7f9c3699c270b6e617444025a58612940ae08
3
+ metadata.gz: 464d4f9326ea315b791701d5ff9ca9a06201b9bbdccc920aba591ea5764f9cba
4
+ data.tar.gz: c149398af2d50cad3659f680d1f10a053e7290457340e02758fa4235a2f7ba34
5
5
  SHA512:
6
- metadata.gz: 1c0f74d8531765a1d0e615227b5135fe80a1c44632241dd6eed7ca004ad2ffb64b92c1617ca298c9d31883fbb78dabc5144601399efb0ece8b1ee9862d2017c7
7
- data.tar.gz: e51bb48f861c668d5f31a1b9bc101c2d112baf4145d80a483f38c8a779114ba2f9454b6a278e706fc2726c555058eed7a5dca338ee4dc4e3c4552846c80e2db1
6
+ metadata.gz: 7b9e55b5db011df6ee7befabb77a6e74934ed7addf4bedcc8ebcf831ca38a7cdeff2b2d2f34ce7326f83cd97f52d8f19f79f1229882f8a436dd533243ad207db
7
+ data.tar.gz: 506cf7f45c08fc2e7f82e1d6675fb2d9cf9b36a66d098ae5fc43e6ea0c997b2fe4f442caa4cbdb1b442132768c32c35e83e2457da40ff2a8baff29cb9e05a60c
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SassC
4
4
  module Embedded
5
- VERSION = '1.5.3'
5
+ VERSION = '1.5.6'
6
6
  end
7
7
  end
@@ -36,7 +36,7 @@ module SassC
36
36
  )
37
37
 
38
38
  @dependencies = result.loaded_urls
39
- .filter { |url| url.start_with?('file:') && url != file_url }
39
+ .filter { |url| url.start_with?(Protocol::FILE) && url != file_url }
40
40
  .map { |url| URL.file_url_to_path(url) }
41
41
  @source_map = post_process_source_map(result.source_map)
42
42
 
@@ -45,10 +45,10 @@ module SassC
45
45
  line = e.span&.start&.line
46
46
  line += 1 unless line.nil?
47
47
  url = e.span&.url
48
- path = if url&.start_with?('file:')
48
+ path = if url&.start_with?(Protocol::FILE)
49
49
  URL.parse(url).route_from(URL.path_to_file_url("#{File.absolute_path('')}/"))
50
50
  end
51
- raise SyntaxError.new(e.message, filename: path, line: line)
51
+ raise SyntaxError.new(e.full_message, filename: path, line: line)
52
52
  end
53
53
 
54
54
  private
@@ -109,7 +109,7 @@ module SassC
109
109
  data = JSON.parse(source_map)
110
110
  data['file'] = URL.parse(output_url).route_from(url).to_s if output_url
111
111
  data['sources'].map! do |source|
112
- if source.start_with?('file:')
112
+ if source.start_with?(Protocol::FILE)
113
113
  URL.parse(source).route_from(url).to_s
114
114
  else
115
115
  source
@@ -283,26 +283,20 @@ module SassC
283
283
  private_constant :FileImporter
284
284
 
285
285
  class Importer
286
- module Protocol
287
- FILE = 'file:'
288
- IMPORT = 'sassc-embedded-import:'
289
- LOAD = 'sassc-embedded-load:'
290
- LOADED = 'sassc-embedded-loaded:'
291
- end
292
-
293
- private_constant :Protocol
294
-
295
286
  def initialize(importer)
296
287
  @importer = importer
288
+
289
+ @canonical_urls = {}
290
+ @id = 0
297
291
  @importer_results = {}
298
292
  @parent_urls = [URL.path_to_file_url(File.absolute_path(@importer.options[:filename] || 'stdin'))]
299
293
  end
300
294
 
301
295
  def canonicalize(url, from_import:)
302
- return url if url.start_with?(Protocol::IMPORT, Protocol::LOADED)
296
+ return url if url.start_with?(Protocol::LOADED)
303
297
 
304
- if url.start_with?(Protocol::LOAD)
305
- url = url.delete_prefix(Protocol::LOAD)
298
+ if url.start_with?(Protocol::IMPORT)
299
+ url = @canonical_urls.delete(url.delete_prefix(Protocol::IMPORT))
306
300
  return url if @importer_results.key?(url)
307
301
 
308
302
  path = URL.parse(url).route_from(@parent_urls.last).to_s
@@ -324,8 +318,9 @@ module SassC
324
318
  import.path = File.absolute_path(import.path, File.dirname(parent_path))
325
319
  end
326
320
 
327
- import_url = URL.path_to_file_url(File.absolute_path(path, File.dirname(parent_path)))
328
- canonical_url = "#{Protocol::IMPORT}#{import_url}"
321
+ id = next_id
322
+ canonical_url = "#{Protocol::IMPORT}#{id}"
323
+ @canonical_urls[id] = canonical_url
329
324
  @importer_results[canonical_url] = imports_to_native(imports)
330
325
  canonical_url
331
326
  end
@@ -369,36 +364,51 @@ module SassC
369
364
  end
370
365
 
371
366
  def syntax(path)
372
- File.extname(path) == '.sass' ? :indented : :scss
367
+ case File.extname(path)
368
+ when '.sass'
369
+ :indented
370
+ when '.css'
371
+ :css
372
+ else
373
+ :scss
374
+ end
373
375
  end
374
376
 
375
377
  def imports_to_native(imports)
376
378
  {
377
379
  contents: imports.flat_map do |import|
378
- file_url = URL.path_to_file_url(import.path)
380
+ id = next_id
381
+ canonical_url = URL.path_to_file_url(import.path)
382
+ @canonical_urls[id] = canonical_url
379
383
  if import.source
380
- @importer_results[file_url] = if import.source.is_a?(Hash)
381
- {
382
- contents: import.source[:contents],
383
- syntax: import.source[:syntax],
384
- source_map_url: file_url
385
- }
386
- else
387
- {
388
- contents: import.source,
389
- syntax: syntax(import.path),
390
- source_map_url: file_url
391
- }
392
- end
384
+ @importer_results[canonical_url] = if import.source.is_a?(Hash)
385
+ {
386
+ contents: import.source[:contents],
387
+ syntax: import.source[:syntax],
388
+ source_map_url: canonical_url
389
+ }
390
+ else
391
+ {
392
+ contents: import.source,
393
+ syntax: syntax(import.path),
394
+ source_map_url: canonical_url
395
+ }
396
+ end
393
397
  end
394
398
  [
395
- "@import #{"#{Protocol::LOAD}#{file_url}".inspect};",
396
- "@import #{"#{Protocol::LOADED}#{file_url}".inspect};"
399
+ "@import \"#{Protocol::IMPORT}#{id}\";",
400
+ "@import \"#{Protocol::LOADED}#{id}\";"
397
401
  ]
398
402
  end.join("\n"),
399
403
  syntax: :scss
400
404
  }
401
405
  end
406
+
407
+ def next_id
408
+ id = @id
409
+ @id = id.next
410
+ id.to_s
411
+ end
402
412
  end
403
413
 
404
414
  private_constant :Importer
@@ -530,6 +540,14 @@ module SassC
530
540
  end
531
541
  end
532
542
 
543
+ module Protocol
544
+ FILE = 'file:'
545
+ IMPORT = 'sassc-embedded-import:'
546
+ LOADED = 'sassc-embedded-loaded:'
547
+ end
548
+
549
+ private_constant :Protocol
550
+
533
551
  module URL
534
552
  PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
535
553
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassc-embedded
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sassc
@@ -138,8 +138,8 @@ homepage: https://github.com/ntkme/sassc-embedded-polyfill-ruby
138
138
  licenses:
139
139
  - MIT
140
140
  metadata:
141
- documentation_uri: https://rubydoc.info/gems/sassc-embedded/1.5.3
142
- source_code_uri: https://github.com/ntkme/sassc-embedded-polyfill-ruby/tree/v1.5.3
141
+ documentation_uri: https://rubydoc.info/gems/sassc-embedded/1.5.6
142
+ source_code_uri: https://github.com/ntkme/sassc-embedded-polyfill-ruby/tree/v1.5.6
143
143
  funding_uri: https://github.com/sponsors/ntkme
144
144
  post_install_message:
145
145
  rdoc_options: []