sass-embedded 0.7.3 → 0.7.8

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: 65d80ba547e32d13dc4a4b9f0760e8203df64c5481dea662564e1872bff6bec9
4
- data.tar.gz: 363baff44d6a57b5ad5cd6e8963c915b582a147b2c360182e8218ce4ae7a7338
3
+ metadata.gz: 182ccd964e82f33282215272b2fe64abb8caa446988d81564c85e237236e3db4
4
+ data.tar.gz: 72ff376803cd9da9de460e6418c8c9025c8c8614d4ce331cf837ed0ac554e713
5
5
  SHA512:
6
- metadata.gz: 12f310e82141b47c7fe61b06a03df7abd00ec06cb9b268aa6c29bd28a523d7182014caaabdd314bebcaeeddad7c62517cb0fda180a81a4ca276862207f8f796b
7
- data.tar.gz: 5d4a397ec28e27cedc67c3467a2ffa91b9d8fe0e3ae02b0939fb29fa05a61a0156a7a5a3a6c6eceb6a8049b23867136a94b3962e360db29dd8d3427032f2a52e
6
+ metadata.gz: 358fb5171fcfd2af9e687e4a8a1662644504b71892f2b052d7340eaf44c32940958aa0bdf20b387ed5cd33b33fa4091751cceb96e08d9d899000100ca9554a4d
7
+ data.tar.gz: c94db17eae89bcc55d3ea762bb5e138e701f1b1d209f6033e0f33639a4ee6324865230734a026a96f2a5fa5287e8710e89badbb3965a0bfe7d790eb7d1e8e380
data/lib/sass/embedded.rb CHANGED
@@ -23,7 +23,7 @@ module Sass
23
23
  #
24
24
  # @raise [ProtocolError]
25
25
  def info
26
- @info ||= Version.new(@transport, next_id).message
26
+ @info ||= VersionContext.new(@transport, next_id).receive_message
27
27
  end
28
28
 
29
29
  # The {Embedded#render} method.
@@ -55,16 +55,16 @@ module Sass
55
55
  indent_width = parse_indent_width(indent_width)
56
56
  linefeed = parse_linefeed(linefeed)
57
57
 
58
- message = Render.new(@transport, next_id,
59
- data: data,
60
- file: file,
61
- indented_syntax: indented_syntax,
62
- include_paths: include_paths,
63
- output_style: output_style,
64
- source_map: source_map,
65
- out_file: out_file,
66
- functions: functions,
67
- importer: importer).message
58
+ message = RenderContext.new(@transport, next_id,
59
+ data: data,
60
+ file: file,
61
+ indented_syntax: indented_syntax,
62
+ include_paths: include_paths,
63
+ output_style: output_style,
64
+ source_map: source_map,
65
+ out_file: out_file,
66
+ functions: functions,
67
+ importer: importer).receive_message
68
68
 
69
69
  if message.failure
70
70
  raise RenderError.new(
@@ -75,7 +75,7 @@ module Sass
75
75
  elsif message.failure.span.url == ''
76
76
  'stdin'
77
77
  else
78
- Util.path(message.failure.span.url)
78
+ Util.path_from_file_uri(message.failure.span.url)
79
79
  end,
80
80
  message.failure.span ? message.failure.span.start.line + 1 : nil,
81
81
  message.failure.span ? message.failure.span.start.column + 1 : nil,
@@ -138,7 +138,7 @@ module Sass
138
138
  source_map_dir = File.dirname(source_map_path)
139
139
 
140
140
  if out_file
141
- map_data['file'] = Util.relative(source_map_dir, out_file)
141
+ map_data['file'] = Util.relative_path(source_map_dir, out_file)
142
142
  elsif file
143
143
  ext = File.extname(file)
144
144
  map_data['file'] = "#{file[0..(ext.empty? ? -1 : -ext.length - 1)]}.css"
@@ -149,10 +149,10 @@ module Sass
149
149
  map_data['sourcesContent'] = [] if source_map_contents
150
150
 
151
151
  map_data['sources'].map! do |source|
152
- if source.start_with? Util::FILE_PROTOCOL
153
- path = Util.path(source)
152
+ if source.start_with? 'file://'
153
+ path = Util.path_from_file_uri(source)
154
154
  map_data['sourcesContent'].push(File.read(path)) if source_map_contents
155
- Util.relative(source_map_dir, path)
155
+ Util.relative_path(source_map_dir, path)
156
156
  else
157
157
  map_data['sourcesContent'].push(nil) if source_map_contents
158
158
  source
@@ -184,7 +184,7 @@ module Sass
184
184
  url = if source_map_embed
185
185
  "data:application/json;base64,#{Base64.strict_encode64(map)}"
186
186
  elsif out_file
187
- Util.relative(File.dirname(out_file), source_map)
187
+ Util.relative_path(File.dirname(out_file), source_map)
188
188
  else
189
189
  source_map
190
190
  end
data/lib/sass/info.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Sass
4
4
  # The {Observer} for {Embedded#info}.
5
- class Version
5
+ class VersionContext
6
6
  include Observer
7
7
 
8
8
  def initialize(transport, id)
@@ -17,8 +17,6 @@ module Sass
17
17
  raise error unless error.nil?
18
18
 
19
19
  case message
20
- when EmbeddedProtocol::ProtocolError
21
- raise ProtocolError, message.message
22
20
  when EmbeddedProtocol::OutboundMessage::VersionResponse
23
21
  return unless message.id == @id
24
22
 
data/lib/sass/observer.rb CHANGED
@@ -12,7 +12,7 @@ module Sass
12
12
  @transport.add_observer self
13
13
  end
14
14
 
15
- def message
15
+ def receive_message
16
16
  @mutex.synchronize do
17
17
  @condition_variable.wait(@mutex) if @error.nil? && @message.nil?
18
18
  end
data/lib/sass/render.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Sass
4
4
  # The {Observer} for {Embedded#render}.
5
- class Render
5
+ class RenderContext
6
6
  include Observer
7
7
 
8
8
  def initialize(transport, id,
@@ -41,8 +41,6 @@ module Sass
41
41
  raise error unless error.nil?
42
42
 
43
43
  case message
44
- when EmbeddedProtocol::ProtocolError
45
- raise ProtocolError, message.message
46
44
  when EmbeddedProtocol::OutboundMessage::CompileResponse
47
45
  return unless message.id == @id
48
46
 
@@ -97,7 +95,7 @@ module Sass
97
95
  end
98
96
 
99
97
  def canonicalize_response(canonicalize_request)
100
- url = Util.file_uri(File.absolute_path(canonicalize_request.url, (@file.nil? ? 'stdin' : @file)))
98
+ url = Util.file_uri_from_path(File.absolute_path(canonicalize_request.url, (@file.nil? ? 'stdin' : @file)))
101
99
 
102
100
  begin
103
101
  result = @importer[canonicalize_request.importer_id].call canonicalize_request.url, @file
@@ -123,7 +121,7 @@ module Sass
123
121
  url: url
124
122
  )
125
123
  elsif result&.key? :file
126
- canonicalized_url = Util.file_uri(result[:file])
124
+ canonicalized_url = Util.file_uri_from_path(result[:file])
127
125
 
128
126
  # TODO: FileImportRequest is not supported yet.
129
127
  # Workaround by reading contents and return it when server asks
@@ -185,7 +183,7 @@ module Sass
185
183
  def url
186
184
  return if @file.nil?
187
185
 
188
- Util.file_uri @file
186
+ Util.file_uri_from_path @file
189
187
  end
190
188
 
191
189
  def string
@@ -24,12 +24,18 @@ module Sass
24
24
  [field_descriptor.subtype, field_descriptor.name]
25
25
  end.to_h
26
26
 
27
+ private_constant :ONEOF_MESSAGE
28
+
27
29
  def initialize
28
30
  @observerable_mutex = Mutex.new
29
31
  @stdin_mutex = Mutex.new
30
32
  @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(DART_SASS_EMBEDDED)
31
- pipe @stderr, $stderr
32
- read @stdout
33
+ poll do
34
+ warn(@stderr.readline, uplevel: 1)
35
+ end
36
+ poll do
37
+ receive_proto read
38
+ end
33
39
  end
34
40
 
35
41
  def add_observer(*args)
@@ -58,44 +64,41 @@ module Sass
58
64
 
59
65
  private
60
66
 
61
- def receive_message(error, message)
62
- @observerable_mutex.synchronize do
63
- changed
64
- notify_observers error, message
65
- end
66
- end
67
-
68
- def pipe(readable, writeable)
67
+ def poll
69
68
  Thread.new do
70
69
  loop do
71
- writeable.write readable.readline
72
- rescue Interrupt
73
- break
74
- rescue IOError => e
75
- receive_message(e, nil)
70
+ yield
71
+ rescue StandardError => e
72
+ notify_observers(e, nil)
76
73
  close
77
74
  break
78
75
  end
79
76
  end
80
77
  end
81
78
 
82
- def read(readable)
83
- Thread.new do
84
- loop do
85
- length = read_varint(readable)
86
- payload = readable.read(length)
87
- message = EmbeddedProtocol::OutboundMessage.decode payload
88
- receive_message(nil, message[message.message.to_s])
89
- rescue Interrupt
90
- break
91
- rescue IOError => e
92
- receive_message(e, nil)
93
- close
94
- break
95
- end
79
+ def notify_observers(*args)
80
+ @observerable_mutex.synchronize do
81
+ changed
82
+ super(*args)
96
83
  end
97
84
  end
98
85
 
86
+ def receive_proto(proto)
87
+ payload = EmbeddedProtocol::OutboundMessage.decode(proto)
88
+ message = payload[payload.message.to_s]
89
+ case message
90
+ when EmbeddedProtocol::ProtocolError
91
+ raise ProtocolError, message.message
92
+ else
93
+ notify_observers(nil, message)
94
+ end
95
+ end
96
+
97
+ def read
98
+ length = read_varint(@stdout)
99
+ @stdout.read(length)
100
+ end
101
+
99
102
  def write(payload)
100
103
  @stdin_mutex.synchronize do
101
104
  write_varint(@stdin, payload.length)
data/lib/sass/util.rb CHANGED
@@ -1,39 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
+ require 'uri'
4
5
 
5
6
  module Sass
6
7
  # The {Util} module.
7
8
  module Util
8
9
  module_function
9
10
 
10
- FILE_PROTOCOL = 'file://'
11
+ URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
11
12
 
12
- def file_uri(path)
13
+ private_constant :URI_PARSER
14
+
15
+ def file_uri_from_path(path)
13
16
  absolute_path = File.absolute_path(path)
14
17
 
15
- unless absolute_path.start_with? File::SEPARATOR
16
- components = absolute_path.split File::SEPARATOR
17
- components[0] = components[0][0].downcase
18
- absolute_path = components.join File::SEPARATOR
19
- end
18
+ absolute_path = File::SEPARATOR + absolute_path unless absolute_path.start_with? File::SEPARATOR
20
19
 
21
- "#{FILE_PROTOCOL}#{absolute_path}"
20
+ URI_PARSER.escape("file://#{absolute_path}")
22
21
  end
23
22
 
24
- def path(file_uri)
25
- absolute_path = file_uri[FILE_PROTOCOL.length..]
26
-
27
- unless absolute_path.start_with? File::SEPARATOR
28
- components = absolute_path.split File::SEPARATOR
29
- components[0] = "#{components[0].upcase}:"
30
- absolute_path = components.join File::SEPARATOR
31
- end
32
-
33
- absolute_path
23
+ def path_from_file_uri(file_uri)
24
+ URI_PARSER.unescape(file_uri)[7..]
34
25
  end
35
26
 
36
- def relative(from, to)
27
+ def relative_path(from, to)
37
28
  Pathname.new(File.absolute_path(to)).relative_path_from(Pathname.new(File.absolute_path(from))).to_s
38
29
  end
39
30
 
data/lib/sass/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sass
4
- VERSION = '0.7.3'
4
+ VERSION = '0.7.8'
5
5
  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.7.3
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-30 00:00:00.000000000 Z
11
+ date: 2021-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -165,7 +165,7 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
165
165
  licenses:
166
166
  - MIT
167
167
  metadata:
168
- source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.7.3
168
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.7.8
169
169
  post_install_message:
170
170
  rdoc_options: []
171
171
  require_paths: