sass-embedded 0.7.28 → 0.9.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.
data/lib/sass/struct.rb DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- # The {Struct} module.
5
- module Struct
6
- def [](key)
7
- instance_variable_get("@#{key}".to_sym)
8
- end
9
-
10
- def to_h
11
- instance_variables.map do |variable|
12
- [variable[1..].to_sym, instance_variable_get(variable)]
13
- end.to_h
14
- end
15
-
16
- def to_s
17
- to_h.to_s
18
- end
19
- end
20
- end
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
- require 'observer'
5
- require_relative '../../ext/sass/embedded_sass_pb'
6
-
7
- module Sass
8
- # The {::Observable} {Transport} for low level communication with
9
- # `dart-sass-embedded` using protocol buffers via stdio. Received messages
10
- # can be observed by an {Observer}.
11
- class Transport
12
- include Observable
13
-
14
- DART_SASS_EMBEDDED = File.absolute_path(
15
- "../../ext/sass/sass_embedded/dart-sass-embedded#{Platform::OS == 'windows' ? '.bat' : ''}", __dir__
16
- )
17
-
18
- PROTOCOL_ERROR_ID = 4_294_967_295
19
-
20
- ONEOF_MESSAGE = EmbeddedProtocol::InboundMessage
21
- .descriptor
22
- .lookup_oneof('message')
23
- .collect do |field_descriptor|
24
- [field_descriptor.subtype, field_descriptor.name]
25
- end.to_h
26
-
27
- private_constant :ONEOF_MESSAGE
28
-
29
- def initialize
30
- @observerable_mutex = Mutex.new
31
- @stdin_mutex = Mutex.new
32
- @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(DART_SASS_EMBEDDED)
33
-
34
- [@stdin, @stdout].each(&:binmode)
35
-
36
- poll do
37
- warn(@stderr.readline, uplevel: 1)
38
- end
39
- poll do
40
- receive_proto read
41
- end
42
- end
43
-
44
- def add_observer(*args)
45
- @observerable_mutex.synchronize do
46
- super(*args)
47
- end
48
- end
49
-
50
- def send_message(message)
51
- write EmbeddedProtocol::InboundMessage.new(
52
- ONEOF_MESSAGE[message.class.descriptor] => message
53
- ).to_proto
54
- end
55
-
56
- def close
57
- delete_observers
58
- @stdin.close unless @stdin.closed?
59
- @stdout.close unless @stdout.closed?
60
- @stderr.close unless @stderr.closed?
61
- nil
62
- end
63
-
64
- def closed?
65
- @stdin.closed?
66
- end
67
-
68
- private
69
-
70
- def poll
71
- Thread.new do
72
- loop do
73
- yield
74
- rescue StandardError => e
75
- notify_observers(e, nil)
76
- close
77
- break
78
- end
79
- end
80
- end
81
-
82
- def notify_observers(*args)
83
- @observerable_mutex.synchronize do
84
- changed
85
- super(*args)
86
- end
87
- end
88
-
89
- def receive_proto(proto)
90
- payload = EmbeddedProtocol::OutboundMessage.decode(proto)
91
- message = payload[payload.message.to_s]
92
- case message
93
- when EmbeddedProtocol::ProtocolError
94
- raise ProtocolError, message.message
95
- else
96
- notify_observers(nil, message)
97
- end
98
- end
99
-
100
- def read
101
- length = read_varint(@stdout)
102
- @stdout.read(length)
103
- end
104
-
105
- def write(payload)
106
- @stdin_mutex.synchronize do
107
- write_varint(@stdin, payload.length)
108
- @stdin.write payload
109
- end
110
- end
111
-
112
- def read_varint(readable)
113
- value = bits = 0
114
- loop do
115
- byte = readable.readbyte
116
- value |= (byte & 0x7f) << bits
117
- bits += 7
118
- break if byte < 0x80
119
- end
120
- value
121
- end
122
-
123
- def write_varint(writeable, value)
124
- bytes = []
125
- until value < 0x80
126
- bytes << (0x80 | (value & 0x7f))
127
- value >>= 7
128
- end
129
- bytes << value
130
- writeable.write bytes.pack('C*')
131
- end
132
- end
133
- end
data/lib/sass/util.rb DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pathname'
4
- require 'uri'
5
-
6
- module Sass
7
- # The {Util} module.
8
- module Util
9
- module_function
10
-
11
- URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
12
-
13
- private_constant :URI_PARSER
14
-
15
- def file_uri_from_path(path)
16
- "file://#{Platform::OS == 'windows' ? File::SEPARATOR : ''}#{URI_PARSER.escape(path)}"
17
- end
18
-
19
- def path_from_file_uri(file_uri)
20
- URI_PARSER.unescape(file_uri[(Platform::OS == 'windows' ? 8 : 7)..])
21
- end
22
-
23
- def relative_path(from, to)
24
- Pathname.new(File.absolute_path(to)).relative_path_from(Pathname.new(File.absolute_path(from))).to_s
25
- end
26
-
27
- def now
28
- (Time.now.to_f * 1000).to_i
29
- end
30
- end
31
- end