sass-embedded 0.13.2 → 0.15.0

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: 18c9d477f0de8ecd58a168476206d8284b840b10df7c1cea367cd553cce11054
4
- data.tar.gz: 32c45918de0b8fe090c421c0cde9ef50c5499e0272a3e43bbe173485ed10d089
3
+ metadata.gz: 8b1ad905f18295ab48835d21b1e6a9c644a860154b37531eeaae2f50f16f70e9
4
+ data.tar.gz: 229fe63046318d8ce512683d11e3868e8c70d6b28897badeb74be7757ff63e7e
5
5
  SHA512:
6
- metadata.gz: e8f4a1e589659b8e811f757bfee50f821bb5b295c43ccf77c382f6c6e028ff7c160ba310204538c5792cce2512a99a580df51703ddd738399fca61db05bbd672
7
- data.tar.gz: 975a2d4257ec8a72c1bd4056902c748e8eda4b5c0e4d62f13c8cd01e2e76f5f55d93b849bd273621f82ad8732d171da63c79afd0e30340041f12c752cf2f9db3
6
+ metadata.gz: 20bc3d260f0ac7bd9473351b7f59a08ccd1de7720afc56c027c83025924b7c986335994a4b257344e8c8435c11b5248de2d1dd512cf5e499d85eeddd1166f260
7
+ data.tar.gz: 5cd706afea71314dc85b47d58f3d4cb9f7ecc82a0a1ed72fc8afc5f772bd98022a8026b62eb490b7c2d9c74c1045d7edb945736078e5195f8c93f858d3f6cc7f
data/ext/sass/extconf.rb CHANGED
@@ -7,10 +7,61 @@ require 'mkmf'
7
7
  require 'open-uri'
8
8
  require_relative '../../lib/sass/embedded/compiler/path'
9
9
  require_relative '../../lib/sass/embedded/compiler/requirements'
10
- require_relative '../../lib/sass/embedded/platform'
11
10
 
12
11
  module Sass
13
12
  class Embedded
13
+ module Platform
14
+ OS = case RbConfig::CONFIG['host_os'].downcase
15
+ when /linux/
16
+ 'linux'
17
+ when /darwin/
18
+ 'darwin'
19
+ when /freebsd/
20
+ 'freebsd'
21
+ when /netbsd/
22
+ 'netbsd'
23
+ when /openbsd/
24
+ 'openbsd'
25
+ when /dragonfly/
26
+ 'dragonflybsd'
27
+ when /sunos|solaris/
28
+ 'solaris'
29
+ when *Gem::WIN_PATTERNS
30
+ 'windows'
31
+ else
32
+ RbConfig::CONFIG['host_os'].downcase
33
+ end
34
+
35
+ OSVERSION = RbConfig::CONFIG['host_os'].gsub(/[^\d]/, '').to_i
36
+
37
+ CPU = RbConfig::CONFIG['host_cpu']
38
+
39
+ ARCH = case CPU.downcase
40
+ when /amd64|x86_64|x64/
41
+ 'x86_64'
42
+ when /i\d86|x86|i86pc/
43
+ 'i386'
44
+ when /ppc64|powerpc64/
45
+ 'powerpc64'
46
+ when /ppc|powerpc/
47
+ 'powerpc'
48
+ when /sparcv9|sparc64/
49
+ 'sparcv9'
50
+ when /arm64|aarch64/ # MacOS calls it "arm64", other operating systems "aarch64"
51
+ 'aarch64'
52
+ when /^arm/
53
+ if OS == 'darwin' # Ruby before 3.0 reports "arm" instead of "arm64" as host_cpu on darwin
54
+ 'aarch64'
55
+ else
56
+ 'arm'
57
+ end
58
+ else
59
+ RbConfig::CONFIG['host_cpu']
60
+ end
61
+ end
62
+
63
+ private_constant :Platform
64
+
14
65
  # The dependency downloader. This downloads all the dependencies during gem
15
66
  # installation. The companion Makefile then unpacks all downloaded
16
67
  # dependencies. By default it downloads the release of each dependency
@@ -34,7 +34,7 @@ module Sass
34
34
  @path = path
35
35
  @source = source
36
36
 
37
- @importer = importer
37
+ @importer = to_struct(importer)
38
38
  @load_paths = load_paths
39
39
  @syntax = syntax
40
40
  @url = url
@@ -48,14 +48,14 @@ module Sass
48
48
  @functions = functions.transform_keys do |key|
49
49
  key.to_s.split('(')[0].chomp
50
50
  end
51
- @importers = importers
51
+ @importers = importers.map do |obj|
52
+ to_struct(obj)
53
+ end
52
54
 
53
55
  @alert_ascii = alert_ascii
54
56
  @alert_color = alert_color
55
57
 
56
- %i[debug warn].each do |sym|
57
- instance_variable_set("@#{sym}".to_sym, get_method(logger, sym))
58
- end
58
+ @logger = to_struct(logger)
59
59
 
60
60
  @quiet_deps = quiet_deps
61
61
  @verbose = verbose
@@ -115,26 +115,26 @@ module Sass
115
115
  def log(event)
116
116
  case event.type
117
117
  when :DEBUG
118
- if @debug.nil?
119
- Kernel.warn(event.formatted)
118
+ if @logger.respond_to? :debug
119
+ @logger.debug(event.message, span: Logger::SourceSpan.from_proto(event.span))
120
120
  else
121
- @debug.call(event.message, span: Logger::SourceSpan.from_proto(event.span))
121
+ Kernel.warn(event.formatted)
122
122
  end
123
123
  when :DEPRECATION_WARNING
124
- if @warn.nil?
125
- Kernel.warn(event.formatted)
124
+ if @logger.respond_to? :warn
125
+ @logger.warn(event.message, deprecation: true,
126
+ span: Logger::SourceSpan.from_proto(event.span),
127
+ stack: event.stack_trace)
126
128
  else
127
- @warn.call(event.message, deprecation: true,
128
- span: Logger::SourceSpan.from_proto(event.span),
129
- stack: event.stack_trace)
129
+ Kernel.warn(event.formatted)
130
130
  end
131
131
  when :WARNING
132
- if @warn.nil?
133
- Kernel.warn(event.formatted)
132
+ if @logger.respond_to? :warn
133
+ @logger.warn(event.message, deprecation: false,
134
+ span: Logger::SourceSpan.from_proto(event.span),
135
+ stack: event.stack_trace)
134
136
  else
135
- @warn.call(event.message, deprecation: false,
136
- span: Logger::SourceSpan.from_proto(event.span),
137
- stack: event.stack_trace)
137
+ Kernel.warn(event.formatted)
138
138
  end
139
139
  end
140
140
  end
@@ -145,7 +145,7 @@ module Sass
145
145
  string: unless @source.nil?
146
146
  EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
147
147
  source: @source,
148
- url: @url,
148
+ url: @url&.to_s,
149
149
  syntax: to_proto_syntax(@syntax),
150
150
  importer: @importer.nil? ? nil : to_proto_importer(@importer, @importers.length)
151
151
  )
@@ -162,9 +162,8 @@ module Sass
162
162
  end
163
163
 
164
164
  def canonicalize_response(canonicalize_request)
165
- importer = importer_with_id(canonicalize_request.importer_id)
166
- url = get_method(importer, :canonicalize).call canonicalize_request.url,
167
- from_import: canonicalize_request.from_import
165
+ importer = importer_of_id canonicalize_request.importer_id
166
+ url = importer.canonicalize(canonicalize_request.url, from_import: canonicalize_request.from_import)&.to_s
168
167
 
169
168
  EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
170
169
  id: canonicalize_request.id,
@@ -178,15 +177,15 @@ module Sass
178
177
  end
179
178
 
180
179
  def import_response(import_request)
181
- importer = importer_with_id(import_request.importer_id)
182
- importer_result = get_method(importer, :load).call import_request.url
180
+ importer = importer_of_id import_request.importer_id
181
+ importer_result = to_struct importer.load(import_request.url)
183
182
 
184
183
  EmbeddedProtocol::InboundMessage::ImportResponse.new(
185
184
  id: import_request.id,
186
185
  success: EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
187
- contents: get_attr(importer_result, :contents),
188
- syntax: to_proto_syntax(get_attr(importer_result, :syntax)),
189
- source_map_url: get_attr(importer_result, :source_map_url)
186
+ contents: importer_result.contents,
187
+ syntax: to_proto_syntax(importer_result.syntax),
188
+ source_map_url: importer_result.respond_to?(:source_map_url) ? importer_result.source_map_url&.to_s : nil
190
189
  )
191
190
  )
192
191
  rescue StandardError => e
@@ -197,9 +196,8 @@ module Sass
197
196
  end
198
197
 
199
198
  def file_import_response(file_import_request)
200
- file_importer = importer_with_id(file_import_request.importer_id)
201
- file_url = get_method(file_importer, :find_file_url).call file_import_request.url,
202
- from_import: file_import_request.from_import
199
+ importer = importer_of_id file_import_request.importer_id
200
+ file_url = importer.find_file_url(file_import_request.url, from_import: file_import_request.from_import)&.to_s
203
201
 
204
202
  raise "file_url must be a file: URL, was \"#{file_url}\"" if !file_url.nil? && !file_url.start_with?('file:')
205
203
 
@@ -254,8 +252,8 @@ module Sass
254
252
  end
255
253
 
256
254
  def to_proto_importer(importer, id)
257
- is_importer = get_method(importer, :canonicalize) && get_method(importer, :load)
258
- is_file_importer = get_method(importer, :find_file_url)
255
+ is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
256
+ is_file_importer = importer.respond_to?(:find_file_url)
259
257
 
260
258
  if is_importer && !is_file_importer
261
259
  EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
@@ -284,7 +282,7 @@ module Sass
284
282
  proto_importers
285
283
  end
286
284
 
287
- def importer_with_id(id)
285
+ def importer_of_id(id)
288
286
  if id == @importers.length
289
287
  @importer
290
288
  else
@@ -292,30 +290,22 @@ module Sass
292
290
  end
293
291
  end
294
292
 
295
- def get_method(obj, sym)
296
- sym = sym.to_sym
297
- if obj.respond_to? sym
298
- obj.method(sym)
299
- elsif obj.respond_to? :[]
300
- if obj[sym].respond_to? :call
301
- obj[sym]
302
- elsif obj[sym.to_s].respond_to? :call
303
- obj[sym.to_s]
304
- end
305
- end
306
- end
293
+ def to_struct(obj)
294
+ return obj unless obj.is_a? Hash
307
295
 
308
- def get_attr(obj, sym)
309
- sym = sym.to_sym
310
- if obj.respond_to? sym
311
- obj.method(sym).call
312
- elsif obj.respond_to? :[]
313
- if obj[sym]
314
- obj[sym]
315
- elsif obj[sym.to_s]
316
- obj[sym.to_s]
296
+ struct = Object.new
297
+ obj.each do |key, value|
298
+ if value.respond_to? :call
299
+ struct.define_singleton_method key.to_sym do |*args, **kwargs|
300
+ value.call(*args, **kwargs)
301
+ end
302
+ else
303
+ struct.define_singleton_method key.to_sym do
304
+ value
305
+ end
317
306
  end
318
307
  end
308
+ struct
319
309
  end
320
310
  end
321
311
  end
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../platform'
4
-
5
3
  module Sass
6
4
  class Embedded
7
5
  class Compiler
8
6
  PATH = File.absolute_path(
9
- "../../../../ext/sass/sass_embedded/dart-sass-embedded#{Platform::OS == 'windows' ? '.bat' : ''}", __dir__
7
+ "../../../../ext/sass/sass_embedded/dart-sass-embedded#{Gem.win_platform? ? '.bat' : ''}", __dir__
10
8
  )
11
9
  end
12
10
  end
@@ -3,7 +3,7 @@
3
3
  require 'base64'
4
4
  require 'json'
5
5
  require 'pathname'
6
- require_relative 'url'
6
+ require 'uri'
7
7
 
8
8
  module Sass
9
9
  # The {Embedded} host for using dart-sass-embedded. Each instance creates
@@ -309,11 +309,17 @@ module Sass
309
309
  raise result if result.is_a? StandardError
310
310
 
311
311
  if result&.key? :contents
312
- @importer_results[canonical_url] = ImporterResult.new(result[:contents], :scss)
312
+ @importer_results[canonical_url] = {
313
+ contents: result[:contents],
314
+ syntax: :scss
315
+ }
313
316
  canonical_url
314
317
  elsif result&.key? :file
315
318
  canonical_url = Url.path_to_file_url(File.absolute_path(result[:file]))
316
- @importer_results[canonical_url] = ImporterResult.new(File.read(result[:file]), :scss)
319
+ @importer_results[canonical_url] = {
320
+ contents: File.read(result[:file]),
321
+ syntax: :scss
322
+ }
317
323
  canonical_url
318
324
  end
319
325
  end
@@ -323,6 +329,35 @@ module Sass
323
329
  end
324
330
  end
325
331
 
332
+ # @deprecated
333
+ # The {Url} module.
334
+ module Url
335
+ # The {::URI::Parser} that is in consistent with RFC 2396 (URI Generic Syntax) and dart:core library.
336
+ URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
337
+
338
+ FILE_SCHEME = 'file://'
339
+
340
+ private_constant :URI_PARSER, :FILE_SCHEME
341
+
342
+ module_function
343
+
344
+ def path_to_file_url(path)
345
+ if File.absolute_path? path
346
+ URI_PARSER.escape "#{FILE_SCHEME}#{Gem.win_platform? ? '/' : ''}#{path}"
347
+ else
348
+ URI_PARSER.escape path
349
+ end
350
+ end
351
+
352
+ def file_url_to_path(url)
353
+ if url.start_with? FILE_SCHEME
354
+ URI_PARSER.unescape url[(FILE_SCHEME.length + (Gem.win_platform? ? 1 : 0))..]
355
+ else
356
+ URI_PARSER.unescape url
357
+ end
358
+ end
359
+ end
360
+
326
361
  private_constant :LegacyImporter
327
362
  end
328
363
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sass
4
4
  class Embedded
5
- VERSION = '0.13.2'
5
+ VERSION = '0.15.0'
6
6
  end
7
7
  end
data/lib/sass/embedded.rb CHANGED
@@ -2,11 +2,9 @@
2
2
 
3
3
  require_relative 'compile_error'
4
4
  require_relative 'compile_result'
5
- require_relative 'importer_result'
6
5
  require_relative 'embedded/channel'
7
6
  require_relative 'embedded/compile_context'
8
- require_relative 'embedded/render'
9
- require_relative 'embedded/url'
7
+ require_relative 'embedded/render' # deprecated
10
8
  require_relative 'embedded/version'
11
9
  require_relative 'embedded/version_context'
12
10
  require_relative 'logger'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-embedded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -175,16 +175,11 @@ files:
175
175
  - lib/sass/embedded/compiler/path.rb
176
176
  - lib/sass/embedded/compiler/requirements.rb
177
177
  - lib/sass/embedded/observer.rb
178
- - lib/sass/embedded/platform.rb
179
178
  - lib/sass/embedded/protocol_error.rb
180
179
  - lib/sass/embedded/render.rb
181
- - lib/sass/embedded/url.rb
182
180
  - lib/sass/embedded/version.rb
183
181
  - lib/sass/embedded/version_context.rb
184
182
  - lib/sass/embedded_protocol.rb
185
- - lib/sass/file_importer.rb
186
- - lib/sass/importer.rb
187
- - lib/sass/importer_result.rb
188
183
  - lib/sass/logger.rb
189
184
  - lib/sass/logger/source_location.rb
190
185
  - lib/sass/logger/source_span.rb
@@ -192,8 +187,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
192
187
  licenses:
193
188
  - MIT
194
189
  metadata:
195
- documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.13.2
196
- source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.13.2
190
+ documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.15.0
191
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.15.0
197
192
  funding_uri: https://github.com/sponsors/ntkme
198
193
  post_install_message:
199
194
  rdoc_options: []
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- class Embedded
5
- module Platform
6
- OS = case RbConfig::CONFIG['host_os'].downcase
7
- when /linux/
8
- 'linux'
9
- when /darwin/
10
- 'darwin'
11
- when /freebsd/
12
- 'freebsd'
13
- when /netbsd/
14
- 'netbsd'
15
- when /openbsd/
16
- 'openbsd'
17
- when /dragonfly/
18
- 'dragonflybsd'
19
- when /sunos|solaris/
20
- 'solaris'
21
- when /mingw|mswin/
22
- 'windows'
23
- else
24
- RbConfig::CONFIG['host_os'].downcase
25
- end
26
-
27
- OSVERSION = RbConfig::CONFIG['host_os'].gsub(/[^\d]/, '').to_i
28
-
29
- CPU = RbConfig::CONFIG['host_cpu']
30
-
31
- ARCH = case CPU.downcase
32
- when /amd64|x86_64|x64/
33
- 'x86_64'
34
- when /i\d86|x86|i86pc/
35
- 'i386'
36
- when /ppc64|powerpc64/
37
- 'powerpc64'
38
- when /ppc|powerpc/
39
- 'powerpc'
40
- when /sparcv9|sparc64/
41
- 'sparcv9'
42
- when /arm64|aarch64/ # MacOS calls it "arm64", other operating systems "aarch64"
43
- 'aarch64'
44
- when /^arm/
45
- if OS == 'darwin' # Ruby before 3.0 reports "arm" instead of "arm64" as host_cpu on darwin
46
- 'aarch64'
47
- else
48
- 'arm'
49
- end
50
- else
51
- RbConfig::CONFIG['host_cpu']
52
- end
53
- end
54
- end
55
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
-
5
- module Sass
6
- class Embedded
7
- # The {Url} module.
8
- module Url
9
- # The {::URI::Parser} that is in consistent with RFC 2396 (URI Generic Syntax) and dart:core library.
10
- URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
11
-
12
- FILE_SCHEME = 'file://'
13
-
14
- private_constant :URI_PARSER, :FILE_SCHEME
15
-
16
- module_function
17
-
18
- def path_to_file_url(path)
19
- if File.absolute_path? path
20
- URI_PARSER.escape "#{FILE_SCHEME}#{Platform::OS == 'windows' ? File::SEPARATOR : ''}#{path}"
21
- else
22
- URI_PARSER.escape path
23
- end
24
- end
25
-
26
- def file_url_to_path(url)
27
- if url.start_with? FILE_SCHEME
28
- URI_PARSER.unescape url[(FILE_SCHEME.length + (Platform::OS == 'windows' ? 1 : 0))..]
29
- else
30
- URI_PARSER.unescape url
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- # The {FileImporter} interface.
5
- class FileImporter
6
- def find_file_url(url, from_import:) # rubocop:disable Lint/UnusedMethodArgument
7
- raise NotImplementedError, 'FileImporter#find_file_url must be implemented'
8
- end
9
- end
10
- end
data/lib/sass/importer.rb DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- # The {Importer} interface.
5
- class Importer
6
- def canonicalize(url) # rubocop:disable Lint/UnusedMethodArgument
7
- raise NotImplementedError, 'Importer#canonicalize must be implemented'
8
- end
9
-
10
- def load(canonical_url) # rubocop:disable Lint/UnusedMethodArgument
11
- raise NotImplementedError, 'Importer#load must be implemented'
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- # The {ImporterResult} of {Importer#load}.
5
- class ImporterResult
6
- attr_reader :contents, :syntax, :source_map_url
7
-
8
- def initialize(contents, syntax, source_map_url = nil)
9
- @contents = contents
10
- @syntax = syntax
11
- @source_map_url = source_map_url
12
- end
13
- end
14
- end