sass-embedded 0.13.1 → 0.14.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: 6c8f92f0e6135b60c156ef3e8db7c7db99e5c2bc6eb3d0a8d557000851297c8e
4
- data.tar.gz: 751defdb3ff0b131e31ce532bc879137df34ee59f949497fdad0bad03df4ee95
3
+ metadata.gz: 1c998b528ffddfc218f32dbefa09559dbdf519cf8a430f8dc9a58d4cae8a7b2a
4
+ data.tar.gz: 84bb150040b3e01d68b7673f00ab08041deb98e357cb653a01ca99e40569f553
5
5
  SHA512:
6
- metadata.gz: 85b2081c739e06f454d3d47d15c2c8cf2321b38f9853ef7a18713761029c2adc0bbc40d38d43c9ebc44b4bec13b986ae1915c29e4fab5dd6f62eb68624f37246
7
- data.tar.gz: 2efe026a515f212d6025635b9e12bacc8532102a1441582daee31931a59a9268aedb8430a35aefb1c94e102100c216b0151f10bcc74b501a458c7ff2606855aa
6
+ metadata.gz: cb4dd021d2dfd85b652dcf88c523e106c84a8ebcfa8e158c02f5a8b43aa4fc852b506dd39b33cf83766253be59bb084b7612a49165883eca4062c9c17b5f1a25
7
+ data.tar.gz: d804392b2bc53fccba57c2d68c86f9118ffe80c24c854cea62b462738185634d59af4e41fc8ea86fabe0db120e16133d15bb3f2822ad3064c1c4e7c467796871
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
@@ -162,9 +162,9 @@ 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,
167
+ from_import: canonicalize_request.from_import
168
168
 
169
169
  EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
170
170
  id: canonicalize_request.id,
@@ -178,15 +178,15 @@ module Sass
178
178
  end
179
179
 
180
180
  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
181
+ importer = importer_of_id import_request.importer_id
182
+ importer_result = to_struct importer.load(import_request.url)
183
183
 
184
184
  EmbeddedProtocol::InboundMessage::ImportResponse.new(
185
185
  id: import_request.id,
186
186
  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)
187
+ contents: importer_result.contents,
188
+ syntax: to_proto_syntax(importer_result.syntax),
189
+ source_map_url: importer_result.respond_to?(:source_map_url) ? importer_result.source_map_url : nil
190
190
  )
191
191
  )
192
192
  rescue StandardError => e
@@ -197,9 +197,9 @@ module Sass
197
197
  end
198
198
 
199
199
  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
200
+ importer = importer_of_id file_import_request.importer_id
201
+ file_url = importer.find_file_url file_import_request.url,
202
+ from_import: file_import_request.from_import
203
203
 
204
204
  raise "file_url must be a file: URL, was \"#{file_url}\"" if !file_url.nil? && !file_url.start_with?('file:')
205
205
 
@@ -254,8 +254,8 @@ module Sass
254
254
  end
255
255
 
256
256
  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)
257
+ is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
258
+ is_file_importer = importer.respond_to?(:find_file_url)
259
259
 
260
260
  if is_importer && !is_file_importer
261
261
  EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
@@ -284,7 +284,7 @@ module Sass
284
284
  proto_importers
285
285
  end
286
286
 
287
- def importer_with_id(id)
287
+ def importer_of_id(id)
288
288
  if id == @importers.length
289
289
  @importer
290
290
  else
@@ -292,30 +292,22 @@ module Sass
292
292
  end
293
293
  end
294
294
 
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
295
+ def to_struct(obj)
296
+ return obj unless obj.is_a? Hash
307
297
 
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]
298
+ struct = Object.new
299
+ obj.each do |key, value|
300
+ if value.respond_to? :call
301
+ struct.define_singleton_method key.to_sym do |*args, **kwargs|
302
+ value.call(*args, **kwargs)
303
+ end
304
+ else
305
+ struct.define_singleton_method key.to_sym do
306
+ value
307
+ end
317
308
  end
318
309
  end
310
+ struct
319
311
  end
320
312
  end
321
313
  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
@@ -17,7 +17,7 @@ module Sass
17
17
 
18
18
  def path_to_file_url(path)
19
19
  if File.absolute_path? path
20
- URI_PARSER.escape "#{FILE_SCHEME}#{Platform::OS == 'windows' ? File::SEPARATOR : ''}#{path}"
20
+ URI_PARSER.escape "#{FILE_SCHEME}#{Gem.win_platform? ? File::SEPARATOR : ''}#{path}"
21
21
  else
22
22
  URI_PARSER.escape path
23
23
  end
@@ -25,7 +25,7 @@ module Sass
25
25
 
26
26
  def file_url_to_path(url)
27
27
  if url.start_with? FILE_SCHEME
28
- URI_PARSER.unescape url[(FILE_SCHEME.length + (Platform::OS == 'windows' ? 1 : 0))..]
28
+ URI_PARSER.unescape url[(FILE_SCHEME.length + (Gem.win_platform? ? 1 : 0))..]
29
29
  else
30
30
  URI_PARSER.unescape url
31
31
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sass
4
4
  class Embedded
5
- VERSION = '0.13.1'
5
+ VERSION = '0.14.0'
6
6
  end
7
7
  end
data/lib/sass/embedded.rb CHANGED
@@ -2,13 +2,13 @@
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
7
  require_relative 'embedded/render'
9
8
  require_relative 'embedded/url'
10
9
  require_relative 'embedded/version'
11
10
  require_relative 'embedded/version_context'
11
+ require_relative 'importer_result'
12
12
  require_relative 'logger'
13
13
 
14
14
  module Sass
@@ -123,7 +123,7 @@ module Sass
123
123
  #
124
124
  # @raise [ProtocolError]
125
125
  def info
126
- @info ||= VersionContext.new(@channel).receive_message
126
+ @info ||= "sass-embedded\t#{VersionContext.new(@channel).receive_message.implementation_version}"
127
127
  end
128
128
 
129
129
  def close
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.1
4
+ version: 0.14.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-01 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,7 +175,6 @@ 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
180
  - lib/sass/embedded/url.rb
@@ -192,8 +191,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
192
191
  licenses:
193
192
  - MIT
194
193
  metadata:
195
- documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.13.1
196
- source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.13.1
194
+ documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.14.0
195
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.14.0
197
196
  funding_uri: https://github.com/sponsors/ntkme
198
197
  post_install_message:
199
198
  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