sassc-embedded 0.1.3 → 1.0.2

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: 0520ad895979ec3c36838b7fdf5bac2430c923f873358606e49eb72f70776109
4
- data.tar.gz: 2b60642cceca432904ad4f1cd0ab43f2501164e54a33e5e964758b80f29a3828
3
+ metadata.gz: 5243561e8643bea221f2541af3faf2e00fb28c4d54842ee582f97f3e9784275d
4
+ data.tar.gz: cfc193f4fbf98a125bd410578d228612ccd2974e76f40668366a389333ae1020
5
5
  SHA512:
6
- metadata.gz: 873f6c9d78221ad59c2e34f46d384496967e83480878a8e2db71de7166f2d6ec46ab960ca64f010ce7002736bfd6cea0b3a4b57f8eb7c7d020b655a77e132ba6
7
- data.tar.gz: 354510f0d6a528603e3ac1aa3f32c3cb97fb166555508577e115375e4b30a34f889220fea4cd4d4eee95bbbc4c88ec62458d877535539836acb83a1bf7faaba2
6
+ metadata.gz: 92f34277c63720d77ebf60655e50472d26a5511dbd4d3f67a2dbf35ec459decd97764f1e6f72efcceca09c1fcb067ca4763690b287326f7f13383d930711ea3d
7
+ data.tar.gz: 2369e12515b4609d0c38ccca4493b94eba2255783046dbaa1611ef21fb97e5ac8f6de5d8aac6ef3fea266642e5e0cf117407881c6e58f7a6328bcfc13d40f7ac
data/README.md CHANGED
@@ -19,7 +19,7 @@ gem install sassc-embedded
19
19
  This polyfill utilizes `sass-embedded` to allow you to compile SCSS or SASS syntax to CSS. To compile, use a `SassC::Engine`, e.g.:
20
20
 
21
21
  ``` ruby
22
- require 'sassc/embedded'
22
+ require 'sassc-embedded'
23
23
 
24
24
  SassC::Engine.new(sass, style: :compressed).render
25
25
  ```
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SassC
4
4
  module Embedded
5
- VERSION = '0.1.3'
5
+ VERSION = '1.0.2'
6
6
  end
7
7
  end
@@ -46,14 +46,17 @@ module SassC
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
@@ -228,20 +233,17 @@ module SassC
228
233
  end
229
234
 
230
235
  contents = imports.map do |import|
231
- import_path = File.absolute_path(import.path)
232
- import_url = Util.path_to_file_url(import_path)
236
+ import_url = Util.path_to_file_url(File.absolute_path(import.path))
233
237
  @importer_results[import_url] = if import.source
234
238
  {
235
239
  contents: import.source,
236
240
  syntax: case import.path
237
- when /\.scss$/i
238
- :scss
239
241
  when /\.sass$/i
240
242
  :indented
241
243
  when /\.css$/i
242
244
  :css
243
245
  else
244
- raise ArgumentError
246
+ :scss
245
247
  end,
246
248
  source_map_url: if import.source_map_path
247
249
  Util.path_to_file_url(
@@ -271,6 +273,61 @@ module SassC
271
273
 
272
274
  module Script
273
275
  module ValueConversion
276
+ def self.from_native(value, options)
277
+ case value
278
+ when ::Sass::Value::Null::NULL
279
+ nil
280
+ when ::Sass::Value::Boolean
281
+ ::SassC::Script::Value::Bool.new(value.to_bool)
282
+ when ::Sass::Value::Color
283
+ if value.instance_eval { defined? @hue }
284
+ ::SassC::Script::Value::Color.new(
285
+ hue: value.hue,
286
+ saturation: value.saturation,
287
+ lightness: value.lightness,
288
+ alpha: value.alpha
289
+ )
290
+ else
291
+ ::SassC::Script::Value::Color.new(
292
+ red: value.red,
293
+ green: value.green,
294
+ blue: value.blue,
295
+ alpha: value.alpha
296
+ )
297
+ end
298
+ when ::Sass::Value::List
299
+ ::SassC::Script::Value::List.new(
300
+ value.to_a.map { |element| from_native(element, options) },
301
+ separator: case value.separator
302
+ when ','
303
+ :comma
304
+ when ' '
305
+ :space
306
+ else
307
+ raise UnsupportedValue, "Sass list separator #{value.separator} unsupported"
308
+ end,
309
+ bracketed: value.bracketed?
310
+ )
311
+ when ::Sass::Value::Map
312
+ ::SassC::Script::Value::Map.new(
313
+ value.contents.to_a.to_h { |k, v| [from_native(k, options), from_native(v, options)] }
314
+ )
315
+ when ::Sass::Value::Number
316
+ ::SassC::Script::Value::Number.new(
317
+ value.value,
318
+ value.numerator_units,
319
+ value.denominator_units
320
+ )
321
+ when ::Sass::Value::String
322
+ ::SassC::Script::Value::String.new(
323
+ value.text,
324
+ value.quoted? ? :string : :identifier
325
+ )
326
+ else
327
+ raise UnsupportedValue, "Sass argument of type #{value.class.name.split('::').last} unsupported"
328
+ end
329
+ end
330
+
274
331
  def self.to_native(value)
275
332
  case value
276
333
  when nil
@@ -293,7 +350,7 @@ module SassC
293
350
  alpha: value.alpha
294
351
  )
295
352
  else
296
- raise ArgumentError
353
+ raise UnsupportedValue, "Sass color mode #{value.instance_eval { @mode }} unsupported"
297
354
  end
298
355
  when ::SassC::Script::Value::List
299
356
  ::Sass::Value::List.new(
@@ -304,7 +361,7 @@ module SassC
304
361
  when :space
305
362
  ' '
306
363
  else
307
- raise ArgumentError
364
+ raise UnsupportedValue, "Sass list separator #{value.separator} unsupported"
308
365
  end,
309
366
  bracketed: value.bracketed
310
367
  )
@@ -325,62 +382,7 @@ module SassC
325
382
  quoted: value.type != :identifier
326
383
  )
327
384
  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
385
+ raise UnsupportedValue, "Sass return type #{value.class.name.split('::').last} unsupported"
384
386
  end
385
387
  end
386
388
  end
@@ -389,10 +391,12 @@ module SassC
389
391
  module Util
390
392
  module_function
391
393
 
394
+ URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
395
+
392
396
  def file_url_to_path(url)
393
397
  return if url.nil?
394
398
 
395
- path = URI::DEFAULT_PARSER.unescape(URI.parse(url).path)
399
+ path = URI_PARSER.unescape(URI.parse(url).path)
396
400
  path = path[1..] if Gem.win_platform? && path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':'
397
401
  path
398
402
  end
@@ -402,7 +406,7 @@ module SassC
402
406
 
403
407
  path = File.absolute_path(path)
404
408
  path = "/#{path}" unless path.start_with? '/'
405
- URI::File.build([nil, URI::DEFAULT_PARSER.escape(path)]).to_s
409
+ URI::File.build([nil, URI_PARSER.escape(path)]).to_s
406
410
  end
407
411
  end
408
412
  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: 0.1.3
4
+ version: 1.0.2
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
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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/0.1.3
142
- source_code_uri: https://github.com/ntkme/sassc-embedded-polyfill-ruby/tree/v0.1.3
141
+ documentation_uri: https://rubydoc.info/gems/sassc-embedded/1.0.2
142
+ source_code_uri: https://github.com/ntkme/sassc-embedded-polyfill-ruby/tree/v1.0.2
143
143
  funding_uri: https://github.com/sponsors/ntkme
144
144
  post_install_message:
145
145
  rdoc_options: []