sass-embedded 0.11.0 → 0.12.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: 8d392419747bbe1cffb4c3843a60a8de343a07fc938c1ad061ce8cde4519fd4a
4
- data.tar.gz: 358c8083d14d6d27d84d6091cad64dd39e35c1076295e030b668386b4856098a
3
+ metadata.gz: c66e86f830cc084c0a5a24104a6b6bc9fc0c57bb8fe4e0e52ee15a5b320ecec6
4
+ data.tar.gz: 1439b6e65bd51f2f589e3dbc62670ea37dc36a365217f69b76e989bf286e62c2
5
5
  SHA512:
6
- metadata.gz: 3a50de89e870d5d4fe054eb0702da7774fba5e445e65fba3efb9364d6ed140bbb07cb1dec2d06bee96d08cf79017c383a921def2487c78468c2a3fe2c3e6a54e
7
- data.tar.gz: e746cc7db807ab73557e03d342d7a5f88d81b7c581a5969d2a63dec1a63699828bc49fcfa1fa4d80ac5edb8452495b15bc8c2e5163127d4985276490c3259e98
6
+ metadata.gz: 7bc51670f5c2cc7cd4edbea3d490d6182ef7d3eb9ebfb800e248dd7a2053828816722f2906c7e41c352821fd79a8ea462e3cf119e2bb6cd3daa05b7e4aa6f0f3
7
+ data.tar.gz: bb7724417e10a1b4642702cf4f5973647698121e3ea358a4bd3b86b4ea47c07527d4af7338040b75033223132a57e9502356781bd3022f0f0c5fc4f9e02fd26e
@@ -50,7 +50,11 @@ module Sass
50
50
 
51
51
  @alert_ascii = alert_ascii
52
52
  @alert_color = alert_color
53
- @logger = logger
53
+
54
+ %i[debug warn].each do |sym|
55
+ instance_variable_set("@#{sym}".to_sym, get_method(logger, sym))
56
+ end
57
+
54
58
  @quiet_deps = quiet_deps
55
59
  @verbose = verbose
56
60
 
@@ -72,9 +76,7 @@ module Sass
72
76
  when EmbeddedProtocol::OutboundMessage::LogEvent
73
77
  return unless message.compilation_id == id
74
78
 
75
- Thread.new do
76
- log message
77
- end
79
+ log message
78
80
  when EmbeddedProtocol::OutboundMessage::CanonicalizeRequest
79
81
  return unless message.compilation_id == id
80
82
 
@@ -111,24 +113,26 @@ module Sass
111
113
  def log(event)
112
114
  case event.type
113
115
  when :DEBUG
114
- if @logger.respond_to? :debug
115
- @logger.debug(event.message, span: Logger::SourceSpan.from_proto(event.span))
116
- else
116
+ if @debug.nil?
117
117
  Kernel.warn(event.formatted)
118
+ else
119
+ @debug.call(event.message, span: Logger::SourceSpan.from_proto(event.span))
118
120
  end
119
121
  when :DEPRECATION_WARNING
120
- if @logger.respond_to? :warn
121
- @logger.warn(event.message, deprecation: true, span: Logger::SourceSpan.from_proto(event.span),
122
- stack: event.stack_trace)
123
- else
122
+ if @warn.nil?
124
123
  Kernel.warn(event.formatted)
124
+ else
125
+ @warn.call(event.message, deprecation: true,
126
+ span: Logger::SourceSpan.from_proto(event.span),
127
+ stack: event.stack_trace)
125
128
  end
126
129
  when :WARNING
127
- if @logger.respond_to? :warn
128
- @logger.warn(event.message, deprecation: false, span: Logger::SourceSpan.from_proto(event.span),
129
- stack: event.stack_trace)
130
- else
130
+ if @warn.nil?
131
131
  Kernel.warn(event.formatted)
132
+ else
133
+ @warn.call(event.message, deprecation: false,
134
+ span: Logger::SourceSpan.from_proto(event.span),
135
+ stack: event.stack_trace)
132
136
  end
133
137
  end
134
138
  end
@@ -155,7 +159,9 @@ module Sass
155
159
  end
156
160
 
157
161
  def canonicalize_response(canonicalize_request)
158
- url = importer_with_id(canonicalize_request.importer_id).canonicalize canonicalize_request.url
162
+ importer = importer_with_id(canonicalize_request.importer_id)
163
+ url = get_method(importer, :canonicalize).call canonicalize_request.url,
164
+ from_import: canonicalize_request.from_import
159
165
 
160
166
  EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
161
167
  id: canonicalize_request.id,
@@ -169,14 +175,15 @@ module Sass
169
175
  end
170
176
 
171
177
  def import_response(import_request)
172
- importer_result = importer_with_id(import_request.importer_id).load import_request.url
178
+ importer = importer_with_id(import_request.importer_id)
179
+ importer_result = get_method(importer, :load).call import_request.url
173
180
 
174
181
  EmbeddedProtocol::InboundMessage::ImportResponse.new(
175
182
  id: import_request.id,
176
183
  success: EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
177
- contents: importer_result.contents,
178
- syntax: to_proto_syntax(importer_result.syntax),
179
- source_map_url: importer_result.source_map_url
184
+ contents: get_attr(importer_result, :contents),
185
+ syntax: to_proto_syntax(get_attr(importer_result, :syntax)),
186
+ source_map_url: get_attr(importer_result, :source_map_url)
180
187
  )
181
188
  )
182
189
  rescue StandardError => e
@@ -188,8 +195,10 @@ module Sass
188
195
 
189
196
  def file_import_response(file_import_request)
190
197
  file_importer = importer_with_id(file_import_request.importer_id)
191
- file_url = file_importer.find_file_url file_import_request.url,
192
- from_import: file_import_request.from_import
198
+ file_url = get_method(file_importer, :find_file_url).call file_import_request.url,
199
+ from_import: file_import_request.from_import
200
+
201
+ raise "file_url must be a file: URL, was \"#{file_url}\"" if !file_url.nil? && !file_url.start_with?('file:')
193
202
 
194
203
  EmbeddedProtocol::InboundMessage::FileImportResponse.new(
195
204
  id: file_import_request.id,
@@ -237,16 +246,19 @@ module Sass
237
246
  when :compressed
238
247
  EmbeddedProtocol::OutputStyle::COMPRESSED
239
248
  else
240
- raise ArgumentError, 'output_style must be one of :expanded, :compressed'
249
+ raise ArgumentError, 'style must be one of :expanded, :compressed'
241
250
  end
242
251
  end
243
252
 
244
253
  def to_proto_importer(importer, id)
245
- if importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
254
+ is_importer = get_method(importer, :canonicalize) && get_method(importer, :load)
255
+ is_file_importer = get_method(importer, :find_file_url)
256
+
257
+ if is_importer && !is_file_importer
246
258
  EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
247
259
  importer_id: id
248
260
  )
249
- elsif importer.respond_to?(:find_file_url)
261
+ elsif is_file_importer && !is_importer
250
262
  EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
251
263
  file_importer_id: id
252
264
  )
@@ -276,6 +288,32 @@ module Sass
276
288
  @importers[id]
277
289
  end
278
290
  end
291
+
292
+ def get_method(obj, sym)
293
+ sym = sym.to_sym
294
+ if obj.respond_to? sym
295
+ obj.method(sym)
296
+ elsif obj.respond_to? :[]
297
+ if obj[sym].respond_to? :call
298
+ obj[sym]
299
+ elsif obj[sym.to_s].respond_to? :call
300
+ obj[sym.to_s]
301
+ end
302
+ end
303
+ end
304
+
305
+ def get_attr(obj, sym)
306
+ sym = sym.to_sym
307
+ if obj.respond_to? sym
308
+ obj.method(sym).call
309
+ elsif obj.respond_to? :[]
310
+ if obj[sym]
311
+ obj[sym]
312
+ elsif obj[sym.to_s]
313
+ obj[sym.to_s]
314
+ end
315
+ end
316
+ end
279
317
  end
280
318
  end
281
319
  end
@@ -317,7 +317,7 @@ module Sass
317
317
  @importer_results = {}
318
318
  end
319
319
 
320
- def canonicalize(url)
320
+ def canonicalize(url, **_kwargs)
321
321
  path = Url.file_url_to_path(url)
322
322
  canonical_url = Url.path_to_file_url(File.absolute_path(path, (@file.nil? ? 'stdin' : @file)))
323
323
 
@@ -6,24 +6,26 @@ module Sass
6
6
  class Embedded
7
7
  # The {Url} module.
8
8
  module Url
9
- # The {::URI::Parser} that is in consistent with Dart Uri.
9
+ # The {::URI::Parser} that is in consistent with RFC 2396 (URI Generic Syntax) and dart:core library.
10
10
  URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
11
11
 
12
- private_constant :URI_PARSER
12
+ FILE_SCHEME = 'file://'
13
+
14
+ private_constant :URI_PARSER, :FILE_SCHEME
13
15
 
14
16
  module_function
15
17
 
16
18
  def path_to_file_url(path)
17
19
  if File.absolute_path? path
18
- "file://#{Platform::OS == 'windows' ? File::SEPARATOR : ''}#{URI_PARSER.escape(path)}"
20
+ URI_PARSER.escape "#{FILE_SCHEME}#{Platform::OS == 'windows' ? File::SEPARATOR : ''}#{path}"
19
21
  else
20
- URI_PARSER.escape(path)
22
+ URI_PARSER.escape path
21
23
  end
22
24
  end
23
25
 
24
26
  def file_url_to_path(url)
25
- if url.start_with? 'file://'
26
- URI_PARSER.unescape url[(Platform::OS == 'windows' ? 8 : 7)..]
27
+ if url.start_with? FILE_SCHEME
28
+ URI_PARSER.unescape url[(FILE_SCHEME.length + (Platform::OS == 'windows' ? 1 : 0))..]
27
29
  else
28
30
  URI_PARSER.unescape url
29
31
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sass
4
4
  class Embedded
5
- VERSION = '0.11.0'
5
+ VERSION = '0.12.0'
6
6
  end
7
7
  end
data/lib/sass/logger.rb CHANGED
@@ -3,18 +3,22 @@
3
3
  module Sass
4
4
  # The {Logger} module.
5
5
  module Logger
6
- # The instance of a slient {Logger}.
7
- def self.slient
8
- @slient ||= Slient.new
6
+ module_function
7
+
8
+ # The instance of a silent {Logger}.
9
+ def silent
10
+ Silent
9
11
  end
10
12
 
11
- # The slient {Logger}.
12
- class Slient
13
+ # The silent {Logger}.
14
+ module Silent
15
+ module_function
16
+
13
17
  def warn(message, deprecation: false, span: nil, stack: nil); end
14
18
 
15
19
  def debug(message, span: nil); end
16
20
  end
17
21
 
18
- private_constant :Slient
22
+ private_constant :Silent
19
23
  end
20
24
  end
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.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-18 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -66,20 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 13.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.10.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 1.24.0
89
+ version: 1.25.0
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 1.24.0
96
+ version: 1.25.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-minitest
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: 0.6.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.8.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.8.0
125
153
  description: A Ruby library that will communicate with Embedded Dart Sass using the
126
154
  Embedded Sass protocol.
127
155
  email:
@@ -164,8 +192,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
164
192
  licenses:
165
193
  - MIT
166
194
  metadata:
167
- documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.11.0
168
- source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.11.0
195
+ documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.12.0
196
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.12.0
169
197
  funding_uri: https://github.com/sponsors/ntkme
170
198
  post_install_message:
171
199
  rdoc_options: []