sassc-embedded 1.0.0 → 1.0.3

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: ab0678b3173a808bb49c1772c1188fa5401989602679332cda0b016d98252dfe
4
- data.tar.gz: 280d458c11585dcdfe5915ad55a2079b323d6b520dd54c6b4f716fcddcfd8c3c
3
+ metadata.gz: 653470aa52eea5c7abe494d8ac3580ac2b5d7c1029286586751a73faf74aa55c
4
+ data.tar.gz: 99e69744a6cbc30974008b302929cb3eea966645ec9c199667180ce944eb58b3
5
5
  SHA512:
6
- metadata.gz: a636e215cd5db491aedf47b256b6f4111e14933a8ac299b74001a18a90e5d4f8b27f554a5667d419b28b7c5fa4288ef03ec4263dd0388b1aedc8698b357b5c4e
7
- data.tar.gz: da72a50497341ff4a461e9d0f946a885eb516a18961b25a68176b2abf5e82116077bc92d0e57a34b7c6d33f6b0e7304b7d66333d7f21e7ac961b412062e19465
6
+ metadata.gz: 73f16f7eb7fae394d7ff2d7e98ae451e13caa17fc89cb89f55a17e572f869389c5d202ef0c0327610d00aaafcfeb9a8e5e610b0463c71d5ba0bf088a3f4af6c9
7
+ data.tar.gz: '03942b1cc4f56e4b84402143bf85f5d97dae0a7f3b89d43c1b5dc246526856c5a6cc5936609362c5eb8d584a5a2054c34624a37dec7724f9cbec530e931fc1bb'
data/README.md CHANGED
@@ -29,8 +29,13 @@ See [rubydoc.info/gems/sassc](https://rubydoc.info/gems/sassc) for full API docu
29
29
  ## Behavioral Differences from SassC Ruby
30
30
 
31
31
  1. Option `:style => :nested` behaves as `:expanded`.
32
+
32
33
  2. Option `:style => :compact` behaves as `:compressed`.
34
+
33
35
  3. Option `:precision` is ignored.
36
+
34
37
  4. Option `:line_comments` is ignored.
35
- 5. Argument `parent_path` in `Importer#imports` is set to value of option `:filename`.
36
- 6. See [the dart-sass documentation](https://github.com/sass/dart-sass#behavioral-differences-from-ruby-sass) for other differences.
38
+
39
+ 5. In `Importer#imports(path, parent_path)`, argument `path` is set to absolute path, and argument `parent_path` is set to value of option `:filename`.
40
+
41
+ See [the dart-sass documentation](https://github.com/sass/dart-sass#behavioral-differences-from-ruby-sass) for other differences.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SassC
4
4
  module Embedded
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.3'
6
6
  end
7
7
  end
@@ -39,21 +39,24 @@ module SassC
39
39
  @dependencies = result.loaded_urls
40
40
  .filter { |url| url.start_with?('file:') && url != file_url }
41
41
  .map { |url| Util.file_url_to_path(url) }
42
- @source_map = post_process_source_map(result.source_map)
42
+ @source_map = post_process_source_map(result.source_map)
43
43
 
44
44
  return post_process_css(result.css) unless quiet?
45
45
  rescue ::Sass::CompileError => e
46
46
  line = e.span&.start&.line
47
47
  line += 1 unless line.nil?
48
48
  path = Util.file_url_to_path(e.span&.url)
49
- path = relative_path(Dir.pwd, path)
49
+ path = relative_path(Dir.pwd, path) unless path.nil?
50
50
  raise SyntaxError.new(e.message, filename: path, line: line)
51
51
  end
52
52
 
53
53
  private
54
54
 
55
55
  def output_path
56
- @options[:output_path]
56
+ @output_path ||= @options.fetch(
57
+ :output_path,
58
+ ("#{File.basename(filename, File.extname(filename))}.css" if filename)
59
+ )
57
60
  end
58
61
 
59
62
  def file_url
@@ -93,17 +96,19 @@ module SassC
93
96
 
94
97
  data = JSON.parse(source_map)
95
98
 
96
- data['file'] = URI::DEFAULT_PARSER.escape(output_path) if output_path
99
+ source_map_dir = File.dirname(source_map_file || '')
100
+
101
+ data['file'] = Util::URI_PARSER.escape(relative_path(source_map_dir, output_path)) if output_path
97
102
 
98
103
  data['sources'].map! do |source|
99
104
  if source.start_with? 'file:'
100
- relative_path(Dir.pwd, Util.file_url_to_path(source))
105
+ relative_path(source_map_dir, Util.file_url_to_path(source))
101
106
  else
102
107
  source
103
108
  end
104
109
  end
105
110
 
106
- -JSON.generate(data)
111
+ JSON.generate(data)
107
112
  end
108
113
 
109
114
  def post_process_css(css)
@@ -112,15 +117,15 @@ module SassC
112
117
  url = if source_map_embed?
113
118
  "data:application/json;base64,#{Base64.strict_encode64(@source_map)}"
114
119
  else
115
- URI::DEFAULT_PARSER.escape(source_map_file)
120
+ Util::URI_PARSER.escape(relative_path(File.dirname(output_path || ''), source_map_file))
116
121
  end
117
122
  css += "\n/*# sourceMappingURL=#{url} */"
118
123
  end
119
- -css
124
+ css
120
125
  end
121
126
 
122
127
  def relative_path(from, to)
123
- Pathname.new(to).relative_path_from(Pathname.new(from)).to_s
128
+ Pathname.new(File.absolute_path(to)).relative_path_from(Pathname.new(File.absolute_path(from))).to_s
124
129
  end
125
130
  end
126
131
 
@@ -159,7 +164,7 @@ module SassC
159
164
 
160
165
  def arguments_from_native_list(native_argument_list)
161
166
  native_argument_list.map do |embedded_value|
162
- Script::ValueConversion.from_native embedded_value
167
+ Script::ValueConversion.from_native embedded_value, @options
163
168
  end
164
169
  end
165
170
 
@@ -218,7 +223,7 @@ module SassC
218
223
  return canonical_url
219
224
  end
220
225
 
221
- canonical_url = "sass-importer-shim:#{canonical_url}"
226
+ canonical_url = "sassc-embedded:#{canonical_url}"
222
227
 
223
228
  imports = @importer.imports path, @importer.options[:filename]
224
229
  unless imports.is_a? Array
@@ -227,25 +232,25 @@ module SassC
227
232
  imports = [imports]
228
233
  end
229
234
 
235
+ dirname = File.dirname(@importer.options.fetch(:filename, 'stdin'))
230
236
  contents = imports.map do |import|
231
- import_path = File.absolute_path(import.path)
232
- import_url = Util.path_to_file_url(import_path)
237
+ import_url = Util.path_to_file_url(File.absolute_path(import.path, dirname))
233
238
  @importer_results[import_url] = if import.source
234
239
  {
235
240
  contents: import.source,
236
241
  syntax: case import.path
237
- when /\.scss$/i
238
- :scss
239
242
  when /\.sass$/i
240
243
  :indented
241
244
  when /\.css$/i
242
245
  :css
243
246
  else
244
- raise ArgumentError
247
+ :scss
245
248
  end,
246
249
  source_map_url: if import.source_map_path
247
250
  Util.path_to_file_url(
248
- File.absolute_path(import.source_map_path, path)
251
+ File.absolute_path(
252
+ import.source_map_path, dirname
253
+ )
249
254
  )
250
255
  end
251
256
  }
@@ -271,6 +276,61 @@ module SassC
271
276
 
272
277
  module Script
273
278
  module ValueConversion
279
+ def self.from_native(value, options)
280
+ case value
281
+ when ::Sass::Value::Null::NULL
282
+ nil
283
+ when ::Sass::Value::Boolean
284
+ ::SassC::Script::Value::Bool.new(value.to_bool)
285
+ when ::Sass::Value::Color
286
+ if value.instance_eval { defined? @hue }
287
+ ::SassC::Script::Value::Color.new(
288
+ hue: value.hue,
289
+ saturation: value.saturation,
290
+ lightness: value.lightness,
291
+ alpha: value.alpha
292
+ )
293
+ else
294
+ ::SassC::Script::Value::Color.new(
295
+ red: value.red,
296
+ green: value.green,
297
+ blue: value.blue,
298
+ alpha: value.alpha
299
+ )
300
+ end
301
+ when ::Sass::Value::List
302
+ ::SassC::Script::Value::List.new(
303
+ value.to_a.map { |element| from_native(element, options) },
304
+ separator: case value.separator
305
+ when ','
306
+ :comma
307
+ when ' '
308
+ :space
309
+ else
310
+ raise UnsupportedValue, "Sass list separator #{value.separator} unsupported"
311
+ end,
312
+ bracketed: value.bracketed?
313
+ )
314
+ when ::Sass::Value::Map
315
+ ::SassC::Script::Value::Map.new(
316
+ value.contents.to_a.to_h { |k, v| [from_native(k, options), from_native(v, options)] }
317
+ )
318
+ when ::Sass::Value::Number
319
+ ::SassC::Script::Value::Number.new(
320
+ value.value,
321
+ value.numerator_units,
322
+ value.denominator_units
323
+ )
324
+ when ::Sass::Value::String
325
+ ::SassC::Script::Value::String.new(
326
+ value.text,
327
+ value.quoted? ? :string : :identifier
328
+ )
329
+ else
330
+ raise UnsupportedValue, "Sass argument of type #{value.class.name.split('::').last} unsupported"
331
+ end
332
+ end
333
+
274
334
  def self.to_native(value)
275
335
  case value
276
336
  when nil
@@ -293,7 +353,7 @@ module SassC
293
353
  alpha: value.alpha
294
354
  )
295
355
  else
296
- raise ArgumentError
356
+ raise UnsupportedValue, "Sass color mode #{value.instance_eval { @mode }} unsupported"
297
357
  end
298
358
  when ::SassC::Script::Value::List
299
359
  ::Sass::Value::List.new(
@@ -304,7 +364,7 @@ module SassC
304
364
  when :space
305
365
  ' '
306
366
  else
307
- raise ArgumentError
367
+ raise UnsupportedValue, "Sass list separator #{value.separator} unsupported"
308
368
  end,
309
369
  bracketed: value.bracketed
310
370
  )
@@ -325,62 +385,7 @@ module SassC
325
385
  quoted: value.type != :identifier
326
386
  )
327
387
  else
328
- raise ArgumentError
329
- end
330
- end
331
-
332
- def self.from_native(value)
333
- case value
334
- when ::Sass::Value::Null::NULL
335
- nil
336
- when ::Sass::Value::Boolean
337
- ::SassC::Script::Value::Bool.new(value.to_bool)
338
- when ::Sass::Value::Color
339
- if value.instance_eval { defined? @hue }
340
- ::SassC::Script::Value::Color.new(
341
- hue: value.hue,
342
- saturation: value.saturation,
343
- lightness: value.lightness,
344
- alpha: value.alpha
345
- )
346
- else
347
- ::SassC::Script::Value::Color.new(
348
- red: value.red,
349
- green: value.green,
350
- blue: value.blue,
351
- alpha: value.alpha
352
- )
353
- end
354
- when ::Sass::Value::List
355
- ::SassC::Script::Value::List.new(
356
- value.to_a.map { |element| from_native(element) },
357
- separator: case value.separator
358
- when ','
359
- :comma
360
- when ' '
361
- :space
362
- else
363
- raise ArgumentError
364
- end,
365
- bracketed: value.bracketed?
366
- )
367
- when ::Sass::Value::Map
368
- ::SassC::Script::Value::Map.new(
369
- value.contents.to_a.to_h { |k, v| [from_native(k), from_native(v)] }
370
- )
371
- when ::Sass::Value::Number
372
- ::SassC::Script::Value::Number.new(
373
- value.value,
374
- value.numerator_units,
375
- value.denominator_units
376
- )
377
- when ::Sass::Value::String
378
- ::SassC::Script::Value::String.new(
379
- value.text,
380
- value.quoted? ? :string : :identifier
381
- )
382
- else
383
- raise ArgumentError
388
+ raise UnsupportedValue, "Sass return type #{value.class.name.split('::').last} unsupported"
384
389
  end
385
390
  end
386
391
  end
@@ -389,10 +394,12 @@ module SassC
389
394
  module Util
390
395
  module_function
391
396
 
397
+ URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
398
+
392
399
  def file_url_to_path(url)
393
400
  return if url.nil?
394
401
 
395
- path = URI::DEFAULT_PARSER.unescape(URI.parse(url).path)
402
+ path = URI_PARSER.unescape(URI.parse(url).path)
396
403
  path = path[1..] if Gem.win_platform? && path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':'
397
404
  path
398
405
  end
@@ -402,7 +409,7 @@ module SassC
402
409
 
403
410
  path = File.absolute_path(path)
404
411
  path = "/#{path}" unless path.start_with? '/'
405
- URI::File.build([nil, URI::DEFAULT_PARSER.escape(path)]).to_s
412
+ URI::File.build([nil, URI_PARSER.escape(path)]).to_s
406
413
  end
407
414
  end
408
415
  end
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.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-21 00:00:00.000000000 Z
11
+ date: 2022-03-22 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.0.0
142
- source_code_uri: https://github.com/ntkme/sassc-embedded-polyfill-ruby/tree/v1.0.0
141
+ documentation_uri: https://rubydoc.info/gems/sassc-embedded/1.0.3
142
+ source_code_uri: https://github.com/ntkme/sassc-embedded-polyfill-ruby/tree/v1.0.3
143
143
  funding_uri: https://github.com/sponsors/ntkme
144
144
  post_install_message:
145
145
  rdoc_options: []