sass-embedded 0.16.1 → 0.16.2
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 +4 -4
- data/lib/sass/embedded/compile_context/function_registry.rb +6 -4
- data/lib/sass/embedded/compile_context/importer_registry.rb +3 -1
- data/lib/sass/embedded/compile_context/logger_registry.rb +45 -0
- data/lib/sass/embedded/compile_context/value_protofier.rb +237 -0
- data/lib/sass/embedded/compile_context.rb +25 -77
- data/lib/sass/embedded/compiler.rb +3 -24
- data/lib/sass/embedded/protofier.rb +55 -293
- data/lib/sass/embedded/structifier.rb +30 -0
- data/lib/sass/embedded/varint.rb +33 -0
- data/lib/sass/embedded/version.rb +1 -1
- data/lib/sass.rb +4 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc4a584b02baef5fc270ec2ce84d7843c01f3656e64aa0c30e303a1d4c123313
|
4
|
+
data.tar.gz: d2230700daf1964f727ca1e5d5c695244cdb1d304700ad15997526ccb62ad31c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fc031920618a3bc5b40a5c146b7ef8fc56b9d048b5c481b214425f3e17b72d05651ef1645b29ac08a15c5504d0c48b4f6605e6e5c13224560a9b26d212b13e9
|
7
|
+
data.tar.gz: e2a1e112ab8241f2a5393d01b237d1a9d41dcca7f386fdaa42a287c5a9cd82d4a6ec909775598a4235a373573ff76381df302f07f16861399ecad35734ea9913
|
@@ -8,6 +8,8 @@ module Sass
|
|
8
8
|
attr_reader :global_functions
|
9
9
|
|
10
10
|
def initialize(functions)
|
11
|
+
functions = functions.transform_keys(&:to_s)
|
12
|
+
|
11
13
|
@global_functions = functions.keys
|
12
14
|
@functions_by_name = functions.transform_keys do |signature|
|
13
15
|
signature = signature.chomp
|
@@ -37,10 +39,10 @@ module Sass
|
|
37
39
|
|
38
40
|
def function_call(function_call_request)
|
39
41
|
arguments = function_call_request.arguments.map do |argument|
|
40
|
-
|
42
|
+
value_protofier.from_proto(argument)
|
41
43
|
end
|
42
44
|
|
43
|
-
success =
|
45
|
+
success = value_protofier.to_proto(get(function_call_request).call(arguments))
|
44
46
|
accessed_argument_lists = arguments
|
45
47
|
.filter do |argument|
|
46
48
|
argument.is_a?(Sass::Value::ArgumentList) && argument.instance_eval do
|
@@ -72,8 +74,8 @@ module Sass
|
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
75
|
-
def
|
76
|
-
@
|
77
|
+
def value_protofier
|
78
|
+
@value_protofier ||= ValueProtofier.new(self)
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -20,6 +20,8 @@ module Sass
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def register(importer)
|
23
|
+
importer = Structifier.to_struct(importer)
|
24
|
+
|
23
25
|
is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
|
24
26
|
is_file_importer = importer.respond_to?(:find_file_url)
|
25
27
|
|
@@ -56,7 +58,7 @@ module Sass
|
|
56
58
|
|
57
59
|
def import(import_request)
|
58
60
|
importer = @importers_by_id[import_request.importer_id]
|
59
|
-
importer_result =
|
61
|
+
importer_result = Structifier.to_struct importer.load(import_request.url)
|
60
62
|
|
61
63
|
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
62
64
|
id: import_request.id,
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
class CompileContext
|
6
|
+
# The {LoggerRegistry} for {CompileContext}.
|
7
|
+
class LoggerRegistry
|
8
|
+
attr_reader :logger
|
9
|
+
|
10
|
+
def initialize(logger)
|
11
|
+
@logger = Structifier.to_struct(logger)
|
12
|
+
end
|
13
|
+
|
14
|
+
def log(event)
|
15
|
+
case event.type
|
16
|
+
when :DEBUG
|
17
|
+
if logger.respond_to? :debug
|
18
|
+
logger.debug(event.message, span: Protofier.from_proto_source_span(event.span))
|
19
|
+
else
|
20
|
+
warn(event.formatted)
|
21
|
+
end
|
22
|
+
when :DEPRECATION_WARNING
|
23
|
+
if logger.respond_to? :warn
|
24
|
+
logger.warn(event.message, deprecation: true,
|
25
|
+
span: Protofier.from_proto_source_span(event.span),
|
26
|
+
stack: event.stack_trace)
|
27
|
+
else
|
28
|
+
warn(event.formatted)
|
29
|
+
end
|
30
|
+
when :WARNING
|
31
|
+
if logger.respond_to? :warn
|
32
|
+
logger.warn(event.message, deprecation: false,
|
33
|
+
span: Protofier.from_proto_source_span(event.span),
|
34
|
+
stack: event.stack_trace)
|
35
|
+
else
|
36
|
+
warn(event.formatted)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private_constant :LoggerRegistry
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
class CompileContext
|
6
|
+
# The {ValueProtofier} between Pure Ruby types and Protobuf Ruby types.
|
7
|
+
class ValueProtofier
|
8
|
+
def initialize(function_registry)
|
9
|
+
@function_registry = function_registry
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_proto(obj)
|
13
|
+
case obj
|
14
|
+
when Sass::Value::String
|
15
|
+
Sass::EmbeddedProtocol::Value.new(
|
16
|
+
string: Sass::EmbeddedProtocol::Value::String.new(
|
17
|
+
text: obj.text,
|
18
|
+
quoted: obj.quoted?
|
19
|
+
)
|
20
|
+
)
|
21
|
+
when Sass::Value::Number
|
22
|
+
Sass::EmbeddedProtocol::Value.new(
|
23
|
+
number: Sass::EmbeddedProtocol::Value::Number.new(
|
24
|
+
value: obj.value.to_f,
|
25
|
+
numerators: obj.numerator_units,
|
26
|
+
denominators: obj.denominator_units
|
27
|
+
)
|
28
|
+
)
|
29
|
+
when Sass::Value::Color
|
30
|
+
if obj.instance_eval { @hue.nil? }
|
31
|
+
Sass::EmbeddedProtocol::Value.new(
|
32
|
+
rgb_color: Sass::EmbeddedProtocol::Value::RgbColor.new(
|
33
|
+
red: obj.red,
|
34
|
+
green: obj.green,
|
35
|
+
blue: obj.blue,
|
36
|
+
alpha: obj.alpha.to_f
|
37
|
+
)
|
38
|
+
)
|
39
|
+
elsif obj.instance_eval { @saturation.nil? }
|
40
|
+
Sass::EmbeddedProtocol::Value.new(
|
41
|
+
hwb_color: Sass::EmbeddedProtocol::Value::HwbColor.new(
|
42
|
+
hue: obj.hue.to_f,
|
43
|
+
whiteness: obj.whiteness.to_f,
|
44
|
+
blackness: obj.blackness.to_f,
|
45
|
+
alpha: obj.alpha.to_f
|
46
|
+
)
|
47
|
+
)
|
48
|
+
else
|
49
|
+
Sass::EmbeddedProtocol::Value.new(
|
50
|
+
hsl_color: Sass::EmbeddedProtocol::Value::HslColor.new(
|
51
|
+
hue: obj.hue.to_f,
|
52
|
+
saturation: obj.saturation.to_f,
|
53
|
+
lightness: obj.lightness.to_f,
|
54
|
+
alpha: obj.alpha.to_f
|
55
|
+
)
|
56
|
+
)
|
57
|
+
end
|
58
|
+
when Sass::Value::ArgumentList
|
59
|
+
Sass::EmbeddedProtocol::Value.new(
|
60
|
+
argument_list: Sass::EmbeddedProtocol::Value::ArgumentList.new(
|
61
|
+
id: obj.instance_eval { @id },
|
62
|
+
contents: obj.contents.map { |element| to_proto(element) },
|
63
|
+
keywords: obj.keywords.transform_values { |value| to_proto(value) },
|
64
|
+
separator: ListSeparator.to_proto(obj.separator)
|
65
|
+
)
|
66
|
+
)
|
67
|
+
when Sass::Value::List
|
68
|
+
Sass::EmbeddedProtocol::Value.new(
|
69
|
+
list: Sass::EmbeddedProtocol::Value::List.new(
|
70
|
+
contents: obj.contents.map { |element| to_proto(element) },
|
71
|
+
separator: ListSeparator.to_proto(obj.separator),
|
72
|
+
has_brackets: obj.bracketed?
|
73
|
+
)
|
74
|
+
)
|
75
|
+
when Sass::Value::Map
|
76
|
+
Sass::EmbeddedProtocol::Value.new(
|
77
|
+
map: Sass::EmbeddedProtocol::Value::Map.new(
|
78
|
+
entries: obj.contents.map do |key, value|
|
79
|
+
Sass::EmbeddedProtocol::Value::Map::Entry.new(
|
80
|
+
key: to_proto(key),
|
81
|
+
value: to_proto(value)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
)
|
85
|
+
)
|
86
|
+
when Sass::Value::Function
|
87
|
+
if obj.id
|
88
|
+
Sass::EmbeddedProtocol::Value.new(
|
89
|
+
compiler_function: Sass::EmbeddedProtocol::Value::CompilerFunction.new(
|
90
|
+
id: obj.id
|
91
|
+
)
|
92
|
+
)
|
93
|
+
else
|
94
|
+
Sass::EmbeddedProtocol::Value.new(
|
95
|
+
host_function: Sass::EmbeddedProtocol::Value::HostFunction.new(
|
96
|
+
id: @function_registry.register(obj.callback),
|
97
|
+
signature: obj.signature
|
98
|
+
)
|
99
|
+
)
|
100
|
+
end
|
101
|
+
when Sass::Value::Boolean
|
102
|
+
Sass::EmbeddedProtocol::Value.new(
|
103
|
+
singleton: obj.value ? :TRUE : :FALSE
|
104
|
+
)
|
105
|
+
when Sass::Value::Null
|
106
|
+
Sass::EmbeddedProtocol::Value.new(
|
107
|
+
singleton: :NULL
|
108
|
+
)
|
109
|
+
else
|
110
|
+
raise Sass::ScriptError, "Unknown Sass::Value #{obj}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def from_proto(proto)
|
115
|
+
obj = proto.method(proto.value).call
|
116
|
+
case proto.value
|
117
|
+
when :string
|
118
|
+
Sass::Value::String.new(
|
119
|
+
obj.text,
|
120
|
+
quoted: obj.quoted
|
121
|
+
)
|
122
|
+
when :number
|
123
|
+
Sass::Value::Number.new(
|
124
|
+
obj.value,
|
125
|
+
obj.numerators,
|
126
|
+
obj.denominators
|
127
|
+
)
|
128
|
+
when :rgb_color
|
129
|
+
Sass::Value::Color.new(
|
130
|
+
red: obj.red,
|
131
|
+
green: obj.green,
|
132
|
+
blue: obj.blue,
|
133
|
+
alpha: obj.alpha
|
134
|
+
)
|
135
|
+
when :hsl_color
|
136
|
+
Sass::Value::Color.new(
|
137
|
+
hue: obj.hue,
|
138
|
+
saturation: obj.saturation,
|
139
|
+
lightness: obj.lightness,
|
140
|
+
alpha: obj.alpha
|
141
|
+
)
|
142
|
+
when :hwb_color
|
143
|
+
Sass::Value::Color.new(
|
144
|
+
hue: obj.hue,
|
145
|
+
whiteness: obj.whiteness,
|
146
|
+
blackness: obj.blackness,
|
147
|
+
alpha: obj.alpha
|
148
|
+
)
|
149
|
+
when :argument_list
|
150
|
+
Sass::Value::ArgumentList.new(
|
151
|
+
obj.contents.map do |element|
|
152
|
+
from_proto(element)
|
153
|
+
end,
|
154
|
+
obj.keywords.entries.to_h do |entry|
|
155
|
+
[entry.first, from_proto(entry.last)]
|
156
|
+
end,
|
157
|
+
ListSeparator.from_proto(obj.separator)
|
158
|
+
).instance_eval do
|
159
|
+
@id = obj.id
|
160
|
+
self
|
161
|
+
end
|
162
|
+
when :list
|
163
|
+
Sass::Value::List.new(
|
164
|
+
obj.contents.map do |element|
|
165
|
+
from_proto(element)
|
166
|
+
end,
|
167
|
+
separator: ListSeparator.from_proto(obj.separator),
|
168
|
+
bracketed: obj.has_brackets
|
169
|
+
)
|
170
|
+
when :map
|
171
|
+
Sass::Value::Map.new(
|
172
|
+
obj.entries.to_h do |entry|
|
173
|
+
[from_proto(entry.key), from_proto(entry.value)]
|
174
|
+
end
|
175
|
+
)
|
176
|
+
when :compiler_function
|
177
|
+
Sass::Value::Function.new(obj.id)
|
178
|
+
when :host_function
|
179
|
+
raise ProtocolError, 'The compiler may not send Value.host_function to host'
|
180
|
+
when :singleton
|
181
|
+
case obj
|
182
|
+
when :TRUE
|
183
|
+
Sass::Value::Boolean::TRUE
|
184
|
+
when :FALSE
|
185
|
+
Sass::Value::Boolean::FALSE
|
186
|
+
when :NULL
|
187
|
+
Sass::Value::Null::NULL
|
188
|
+
else
|
189
|
+
raise Sass::ScriptError, "Unknown Value.singleton #{obj}"
|
190
|
+
end
|
191
|
+
else
|
192
|
+
raise Sass::ScriptError, "Unknown Value.value #{obj}"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# The {ListSeparator} Protofier.
|
197
|
+
module ListSeparator
|
198
|
+
module_function
|
199
|
+
|
200
|
+
def to_proto(separator)
|
201
|
+
case separator
|
202
|
+
when ','
|
203
|
+
:COMMA
|
204
|
+
when ' '
|
205
|
+
:SPACE
|
206
|
+
when '/'
|
207
|
+
:SLASH
|
208
|
+
when nil
|
209
|
+
:UNDECIDED
|
210
|
+
else
|
211
|
+
raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def from_proto(separator)
|
216
|
+
case separator
|
217
|
+
when :COMMA
|
218
|
+
','
|
219
|
+
when :SPACE
|
220
|
+
' '
|
221
|
+
when :SLASH
|
222
|
+
'/'
|
223
|
+
when :UNDECIDED
|
224
|
+
nil
|
225
|
+
else
|
226
|
+
raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
private_constant :ListSeparator
|
232
|
+
end
|
233
|
+
|
234
|
+
private_constant :ValueProtofier
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -27,34 +27,33 @@ module Sass
|
|
27
27
|
logger:,
|
28
28
|
quiet_deps:,
|
29
29
|
verbose:)
|
30
|
-
@
|
31
|
-
@
|
32
|
-
|
33
|
-
@load_paths = load_paths
|
34
|
-
@syntax = syntax
|
35
|
-
@url = url
|
36
|
-
|
37
|
-
@source_map = source_map
|
38
|
-
@source_map_include_sources = source_map_include_sources
|
39
|
-
@style = style
|
40
|
-
|
41
|
-
@function_registery = FunctionRegistry.new(functions.transform_keys(&:to_s))
|
42
|
-
@importer_registery = ImporterRegistry.new(importers.map do |obj|
|
43
|
-
Protofier.to_struct(obj)
|
44
|
-
end, load_paths)
|
45
|
-
@importer = importer.nil? ? nil : @importer_registery.register(Protofier.to_struct(importer))
|
46
|
-
|
47
|
-
@alert_ascii = alert_ascii
|
48
|
-
@alert_color = alert_color
|
49
|
-
|
50
|
-
@logger = Protofier.to_struct(logger)
|
51
|
-
|
52
|
-
@quiet_deps = quiet_deps
|
53
|
-
@verbose = verbose
|
30
|
+
@function_registery = FunctionRegistry.new(functions)
|
31
|
+
@importer_registery = ImporterRegistry.new(importers, load_paths)
|
32
|
+
@logger_registery = LoggerRegistry.new(logger)
|
54
33
|
|
55
34
|
super(channel)
|
56
35
|
|
57
|
-
send_message
|
36
|
+
send_message EmbeddedProtocol::InboundMessage::CompileRequest.new(
|
37
|
+
id: id,
|
38
|
+
string: unless source.nil?
|
39
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
|
40
|
+
source: source,
|
41
|
+
url: url&.to_s,
|
42
|
+
syntax: Protofier.to_proto_syntax(syntax),
|
43
|
+
importer: importer.nil? ? nil : @importer_registery.register(importer)
|
44
|
+
)
|
45
|
+
end,
|
46
|
+
path: path,
|
47
|
+
style: Protofier.to_proto_output_style(style),
|
48
|
+
source_map: source_map,
|
49
|
+
source_map_include_sources: source_map_include_sources,
|
50
|
+
importers: @importer_registery.importers,
|
51
|
+
global_functions: @function_registery.global_functions,
|
52
|
+
alert_ascii: alert_ascii,
|
53
|
+
alert_color: alert_color,
|
54
|
+
quiet_deps: quiet_deps,
|
55
|
+
verbose: verbose
|
56
|
+
)
|
58
57
|
end
|
59
58
|
|
60
59
|
def update(error, message)
|
@@ -70,7 +69,7 @@ module Sass
|
|
70
69
|
when EmbeddedProtocol::OutboundMessage::LogEvent
|
71
70
|
return unless message.compilation_id == id
|
72
71
|
|
73
|
-
log message
|
72
|
+
@logger_registery.log message
|
74
73
|
when EmbeddedProtocol::OutboundMessage::CanonicalizeRequest
|
75
74
|
return unless message.compilation_id == id
|
76
75
|
|
@@ -101,57 +100,6 @@ module Sass
|
|
101
100
|
super(e, nil)
|
102
101
|
end
|
103
102
|
end
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
def log(event)
|
108
|
-
case event.type
|
109
|
-
when :DEBUG
|
110
|
-
if @logger.respond_to? :debug
|
111
|
-
@logger.debug(event.message, span: Protofier.from_proto_source_span(event.span))
|
112
|
-
else
|
113
|
-
Kernel.warn(event.formatted)
|
114
|
-
end
|
115
|
-
when :DEPRECATION_WARNING
|
116
|
-
if @logger.respond_to? :warn
|
117
|
-
@logger.warn(event.message, deprecation: true,
|
118
|
-
span: Protofier.from_proto_source_span(event.span),
|
119
|
-
stack: event.stack_trace)
|
120
|
-
else
|
121
|
-
Kernel.warn(event.formatted)
|
122
|
-
end
|
123
|
-
when :WARNING
|
124
|
-
if @logger.respond_to? :warn
|
125
|
-
@logger.warn(event.message, deprecation: false,
|
126
|
-
span: Protofier.from_proto_source_span(event.span),
|
127
|
-
stack: event.stack_trace)
|
128
|
-
else
|
129
|
-
Kernel.warn(event.formatted)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def compile_request
|
135
|
-
EmbeddedProtocol::InboundMessage::CompileRequest.new(
|
136
|
-
id: id,
|
137
|
-
string: unless @source.nil?
|
138
|
-
EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
|
139
|
-
source: @source,
|
140
|
-
url: @url&.to_s,
|
141
|
-
syntax: Protofier.to_proto_syntax(@syntax),
|
142
|
-
importer: @importer
|
143
|
-
)
|
144
|
-
end,
|
145
|
-
path: @path,
|
146
|
-
style: Protofier.to_proto_output_style(@style),
|
147
|
-
source_map: @source_map,
|
148
|
-
source_map_include_sources: @source_map_include_sources,
|
149
|
-
importers: @importer_registery.importers,
|
150
|
-
global_functions: @function_registery.global_functions,
|
151
|
-
alert_ascii: @alert_ascii,
|
152
|
-
alert_color: @alert_color
|
153
|
-
)
|
154
|
-
end
|
155
103
|
end
|
156
104
|
|
157
105
|
private_constant :CompileContext
|
@@ -106,37 +106,16 @@ module Sass
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def read
|
109
|
-
length =
|
109
|
+
length = Varint.read(@stdout)
|
110
110
|
@stdout.read(length)
|
111
111
|
end
|
112
112
|
|
113
113
|
def write(payload)
|
114
114
|
@stdin_mutex.synchronize do
|
115
|
-
|
116
|
-
@stdin.write
|
115
|
+
Varint.write(@stdin, payload.length)
|
116
|
+
@stdin.write(payload)
|
117
117
|
end
|
118
118
|
end
|
119
|
-
|
120
|
-
def read_varint(readable)
|
121
|
-
value = bits = 0
|
122
|
-
loop do
|
123
|
-
byte = readable.readbyte
|
124
|
-
value |= (byte & 0x7f) << bits
|
125
|
-
bits += 7
|
126
|
-
break if byte < 0x80
|
127
|
-
end
|
128
|
-
value
|
129
|
-
end
|
130
|
-
|
131
|
-
def write_varint(writeable, value)
|
132
|
-
bytes = []
|
133
|
-
until value < 0x80
|
134
|
-
bytes << (0x80 | (value & 0x7f))
|
135
|
-
value >>= 7
|
136
|
-
end
|
137
|
-
bytes << value
|
138
|
-
writeable.write bytes.pack('C*')
|
139
|
-
end
|
140
119
|
end
|
141
120
|
|
142
121
|
private_constant :Compiler
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Sass
|
4
4
|
class Embedded
|
5
5
|
# The {Protofier} between Pure Ruby types and Protobuf Ruby types.
|
6
|
-
|
6
|
+
module Protofier
|
7
7
|
ONEOF_MESSAGE = EmbeddedProtocol::InboundMessage
|
8
8
|
.descriptor
|
9
9
|
.lookup_oneof('message')
|
@@ -13,313 +13,75 @@ module Sass
|
|
13
13
|
|
14
14
|
private_constant :ONEOF_MESSAGE
|
15
15
|
|
16
|
-
|
17
|
-
@function_registry = function_registry
|
18
|
-
end
|
16
|
+
module_function
|
19
17
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
)
|
28
|
-
)
|
29
|
-
when Sass::Value::Number
|
30
|
-
Sass::EmbeddedProtocol::Value.new(
|
31
|
-
number: Sass::EmbeddedProtocol::Value::Number.new(
|
32
|
-
value: obj.value.to_f,
|
33
|
-
numerators: obj.numerator_units,
|
34
|
-
denominators: obj.denominator_units
|
35
|
-
)
|
36
|
-
)
|
37
|
-
when Sass::Value::Color
|
38
|
-
if obj.instance_eval { @hue.nil? }
|
39
|
-
Sass::EmbeddedProtocol::Value.new(
|
40
|
-
rgb_color: Sass::EmbeddedProtocol::Value::RgbColor.new(
|
41
|
-
red: obj.red,
|
42
|
-
green: obj.green,
|
43
|
-
blue: obj.blue,
|
44
|
-
alpha: obj.alpha.to_f
|
45
|
-
)
|
46
|
-
)
|
47
|
-
elsif obj.instance_eval { @saturation.nil? }
|
48
|
-
Sass::EmbeddedProtocol::Value.new(
|
49
|
-
hwb_color: Sass::EmbeddedProtocol::Value::HwbColor.new(
|
50
|
-
hue: obj.hue.to_f,
|
51
|
-
whiteness: obj.whiteness.to_f,
|
52
|
-
blackness: obj.blackness.to_f,
|
53
|
-
alpha: obj.alpha.to_f
|
54
|
-
)
|
55
|
-
)
|
56
|
-
else
|
57
|
-
Sass::EmbeddedProtocol::Value.new(
|
58
|
-
hsl_color: Sass::EmbeddedProtocol::Value::HslColor.new(
|
59
|
-
hue: obj.hue.to_f,
|
60
|
-
saturation: obj.saturation.to_f,
|
61
|
-
lightness: obj.lightness.to_f,
|
62
|
-
alpha: obj.alpha.to_f
|
63
|
-
)
|
64
|
-
)
|
65
|
-
end
|
66
|
-
when Sass::Value::ArgumentList
|
67
|
-
Sass::EmbeddedProtocol::Value.new(
|
68
|
-
argument_list: Sass::EmbeddedProtocol::Value::ArgumentList.new(
|
69
|
-
id: obj.instance_eval { @id },
|
70
|
-
contents: obj.contents.map { |element| to_proto_value(element) },
|
71
|
-
keywords: obj.keywords.transform_values { |value| to_proto_value(value) },
|
72
|
-
separator: to_proto_separator(obj.separator)
|
73
|
-
)
|
74
|
-
)
|
75
|
-
when Sass::Value::List
|
76
|
-
Sass::EmbeddedProtocol::Value.new(
|
77
|
-
list: Sass::EmbeddedProtocol::Value::List.new(
|
78
|
-
contents: obj.contents.map { |element| to_proto_value(element) },
|
79
|
-
separator: to_proto_separator(obj.separator),
|
80
|
-
has_brackets: obj.bracketed?
|
81
|
-
)
|
82
|
-
)
|
83
|
-
when Sass::Value::Map
|
84
|
-
Sass::EmbeddedProtocol::Value.new(
|
85
|
-
map: Sass::EmbeddedProtocol::Value::Map.new(
|
86
|
-
entries: obj.contents.map do |key, value|
|
87
|
-
Sass::EmbeddedProtocol::Value::Map::Entry.new(
|
88
|
-
key: to_proto_value(key),
|
89
|
-
value: to_proto_value(value)
|
90
|
-
)
|
91
|
-
end
|
92
|
-
)
|
93
|
-
)
|
94
|
-
when Sass::Value::Function
|
95
|
-
if obj.id
|
96
|
-
Sass::EmbeddedProtocol::Value.new(
|
97
|
-
compiler_function: Sass::EmbeddedProtocol::Value::CompilerFunction.new(
|
98
|
-
id: obj.id
|
99
|
-
)
|
100
|
-
)
|
101
|
-
else
|
102
|
-
Sass::EmbeddedProtocol::Value.new(
|
103
|
-
host_function: Sass::EmbeddedProtocol::Value::HostFunction.new(
|
104
|
-
id: @function_registry.register(obj.callback),
|
105
|
-
signature: obj.signature
|
106
|
-
)
|
107
|
-
)
|
108
|
-
end
|
109
|
-
when Sass::Value::Boolean
|
110
|
-
Sass::EmbeddedProtocol::Value.new(
|
111
|
-
singleton: obj.value ? :TRUE : :FALSE
|
18
|
+
def from_proto_compile_response(compile_response)
|
19
|
+
if compile_response.result == :failure
|
20
|
+
raise CompileError.new(
|
21
|
+
compile_response.failure.formatted || compile_response.failure.message,
|
22
|
+
compile_response.failure.message,
|
23
|
+
compile_response.failure.stack_trace,
|
24
|
+
from_proto_source_span(compile_response.failure.span)
|
112
25
|
)
|
113
|
-
when Sass::Value::Null
|
114
|
-
Sass::EmbeddedProtocol::Value.new(
|
115
|
-
singleton: :NULL
|
116
|
-
)
|
117
|
-
else
|
118
|
-
raise Sass::ScriptError, "Unknown Sass::Value #{obj}"
|
119
26
|
end
|
120
|
-
end
|
121
27
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
value.text,
|
128
|
-
quoted: value.quoted
|
129
|
-
)
|
130
|
-
when :number
|
131
|
-
Sass::Value::Number.new(
|
132
|
-
value.value,
|
133
|
-
value.numerators,
|
134
|
-
value.denominators
|
135
|
-
)
|
136
|
-
when :rgb_color
|
137
|
-
Sass::Value::Color.new(
|
138
|
-
red: value.red,
|
139
|
-
green: value.green,
|
140
|
-
blue: value.blue,
|
141
|
-
alpha: value.alpha
|
142
|
-
)
|
143
|
-
when :hsl_color
|
144
|
-
Sass::Value::Color.new(
|
145
|
-
hue: value.hue,
|
146
|
-
saturation: value.saturation,
|
147
|
-
lightness: value.lightness,
|
148
|
-
alpha: value.alpha
|
149
|
-
)
|
150
|
-
when :hwb_color
|
151
|
-
Sass::Value::Color.new(
|
152
|
-
hue: value.hue,
|
153
|
-
whiteness: value.whiteness,
|
154
|
-
blackness: value.blackness,
|
155
|
-
alpha: value.alpha
|
156
|
-
)
|
157
|
-
when :argument_list
|
158
|
-
Sass::Value::ArgumentList.new(
|
159
|
-
value.contents.map do |i|
|
160
|
-
from_proto_value(i)
|
161
|
-
end,
|
162
|
-
value.keywords.entries.to_h do |entry|
|
163
|
-
[entry.first, from_proto_value(entry.last)]
|
164
|
-
end,
|
165
|
-
from_proto_separator(value.separator)
|
166
|
-
).instance_eval do
|
167
|
-
@id = value.id
|
168
|
-
self
|
169
|
-
end
|
170
|
-
when :list
|
171
|
-
Sass::Value::List.new(
|
172
|
-
value.contents.map do |element|
|
173
|
-
from_proto_value(element)
|
174
|
-
end,
|
175
|
-
separator: from_proto_separator(value.separator),
|
176
|
-
bracketed: value.has_brackets
|
177
|
-
)
|
178
|
-
when :map
|
179
|
-
Sass::Value::Map.new(
|
180
|
-
value.entries.to_h do |entry|
|
181
|
-
[from_proto_value(entry.key), from_proto_value(entry.value)]
|
182
|
-
end
|
183
|
-
)
|
184
|
-
when :compiler_function
|
185
|
-
Sass::Value::Function.new(value.id)
|
186
|
-
when :host_function
|
187
|
-
raise ProtocolError, 'The compiler may not send Value.host_function to host'
|
188
|
-
when :singleton
|
189
|
-
case value
|
190
|
-
when :TRUE
|
191
|
-
Sass::Value::Boolean::TRUE
|
192
|
-
when :FALSE
|
193
|
-
Sass::Value::Boolean::FALSE
|
194
|
-
when :NULL
|
195
|
-
Sass::Value::Null::NULL
|
196
|
-
else
|
197
|
-
raise Sass::ScriptError "Unknown Value.singleton #{value}"
|
198
|
-
end
|
199
|
-
else
|
200
|
-
raise Sass::ScriptError, "Unknown Value.value #{value}"
|
201
|
-
end
|
28
|
+
CompileResult.new(
|
29
|
+
compile_response.success.css,
|
30
|
+
compile_response.success.source_map,
|
31
|
+
compile_response.success.loaded_urls
|
32
|
+
)
|
202
33
|
end
|
203
34
|
|
204
|
-
|
35
|
+
def from_proto_source_span(source_span)
|
36
|
+
return nil if source_span.nil?
|
205
37
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
:SPACE
|
212
|
-
when '/'
|
213
|
-
:SLASH
|
214
|
-
when nil
|
215
|
-
:UNDECIDED
|
216
|
-
else
|
217
|
-
raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
|
218
|
-
end
|
38
|
+
Logger::SourceSpan.new(from_proto_source_location(source_span.start),
|
39
|
+
from_proto_source_location(source_span.end),
|
40
|
+
source_span.text,
|
41
|
+
source_span.url,
|
42
|
+
source_span.context)
|
219
43
|
end
|
220
44
|
|
221
|
-
def
|
222
|
-
|
223
|
-
when :COMMA
|
224
|
-
','
|
225
|
-
when :SPACE
|
226
|
-
' '
|
227
|
-
when :SLASH
|
228
|
-
'/'
|
229
|
-
when :UNDECIDED
|
230
|
-
nil
|
231
|
-
else
|
232
|
-
raise Sass::ScriptError, "Unknown ListSeparator #{separator}"
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
class << self
|
237
|
-
def from_proto_compile_response(compile_response)
|
238
|
-
if compile_response.result == :failure
|
239
|
-
raise CompileError.new(
|
240
|
-
compile_response.failure.formatted || compile_response.failure.message,
|
241
|
-
compile_response.failure.message,
|
242
|
-
compile_response.failure.stack_trace,
|
243
|
-
from_proto_source_span(compile_response.failure.span)
|
244
|
-
)
|
245
|
-
end
|
246
|
-
|
247
|
-
CompileResult.new(
|
248
|
-
compile_response.success.css,
|
249
|
-
compile_response.success.source_map,
|
250
|
-
compile_response.success.loaded_urls
|
251
|
-
)
|
252
|
-
end
|
253
|
-
|
254
|
-
def from_proto_source_span(source_span)
|
255
|
-
return nil if source_span.nil?
|
256
|
-
|
257
|
-
Logger::SourceSpan.new(from_proto_source_location(source_span.start),
|
258
|
-
from_proto_source_location(source_span.end),
|
259
|
-
source_span.text,
|
260
|
-
source_span.url,
|
261
|
-
source_span.context)
|
262
|
-
end
|
263
|
-
|
264
|
-
def from_proto_source_location(source_location)
|
265
|
-
return nil if source_location.nil?
|
266
|
-
|
267
|
-
Logger::SourceLocation.new(source_location.offset,
|
268
|
-
source_location.line,
|
269
|
-
source_location.column)
|
270
|
-
end
|
45
|
+
def from_proto_source_location(source_location)
|
46
|
+
return nil if source_location.nil?
|
271
47
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
48
|
+
Logger::SourceLocation.new(source_location.offset,
|
49
|
+
source_location.line,
|
50
|
+
source_location.column)
|
51
|
+
end
|
276
52
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
53
|
+
def from_proto_message(proto)
|
54
|
+
message = EmbeddedProtocol::OutboundMessage.decode(proto)
|
55
|
+
message.method(message.message).call
|
56
|
+
end
|
282
57
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
EmbeddedProtocol::Syntax::INDENTED
|
289
|
-
when :css
|
290
|
-
EmbeddedProtocol::Syntax::CSS
|
291
|
-
else
|
292
|
-
raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
|
293
|
-
end
|
294
|
-
end
|
58
|
+
def to_proto_message(message)
|
59
|
+
EmbeddedProtocol::InboundMessage.new(
|
60
|
+
ONEOF_MESSAGE[message.class.descriptor] => message
|
61
|
+
).to_proto
|
62
|
+
end
|
295
63
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
64
|
+
def to_proto_syntax(syntax)
|
65
|
+
case syntax&.to_sym
|
66
|
+
when :scss
|
67
|
+
EmbeddedProtocol::Syntax::SCSS
|
68
|
+
when :indented
|
69
|
+
EmbeddedProtocol::Syntax::INDENTED
|
70
|
+
when :css
|
71
|
+
EmbeddedProtocol::Syntax::CSS
|
72
|
+
else
|
73
|
+
raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
|
305
74
|
end
|
75
|
+
end
|
306
76
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
end
|
316
|
-
else
|
317
|
-
struct.define_singleton_method key.to_sym do
|
318
|
-
value
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
struct
|
77
|
+
def to_proto_output_style(style)
|
78
|
+
case style&.to_sym
|
79
|
+
when :expanded
|
80
|
+
EmbeddedProtocol::OutputStyle::EXPANDED
|
81
|
+
when :compressed
|
82
|
+
EmbeddedProtocol::OutputStyle::COMPRESSED
|
83
|
+
else
|
84
|
+
raise ArgumentError, 'style must be one of :expanded, :compressed'
|
323
85
|
end
|
324
86
|
end
|
325
87
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
# The {Structifier} that convert {::Hash} to {Struct}-like object.
|
6
|
+
module Structifier
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def to_struct(obj)
|
10
|
+
return obj unless obj.is_a? Hash
|
11
|
+
|
12
|
+
struct = Object.new
|
13
|
+
obj.each do |key, value|
|
14
|
+
if value.respond_to? :call
|
15
|
+
struct.define_singleton_method key.to_sym do |*args, **kwargs|
|
16
|
+
value.call(*args, **kwargs)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
struct.define_singleton_method key.to_sym do
|
20
|
+
value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
struct
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private_constant :Structifier
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
# Read and write {Varint} from {::IO}.
|
6
|
+
module Varint
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def read(readable)
|
10
|
+
value = bits = 0
|
11
|
+
loop do
|
12
|
+
byte = readable.readbyte
|
13
|
+
value |= (byte & 0x7f) << bits
|
14
|
+
bits += 7
|
15
|
+
break if byte < 0x80
|
16
|
+
end
|
17
|
+
value
|
18
|
+
end
|
19
|
+
|
20
|
+
def write(writeable, value)
|
21
|
+
bytes = []
|
22
|
+
until value < 0x80
|
23
|
+
bytes << (0x80 | (value & 0x7f))
|
24
|
+
value >>= 7
|
25
|
+
end
|
26
|
+
bytes << value
|
27
|
+
writeable.write bytes.pack('C*')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private_constant :Varint
|
32
|
+
end
|
33
|
+
end
|
data/lib/sass.rb
CHANGED
@@ -8,12 +8,16 @@ require_relative 'sass/embedded/observer'
|
|
8
8
|
require_relative 'sass/embedded/compile_context'
|
9
9
|
require_relative 'sass/embedded/compile_context/function_registry'
|
10
10
|
require_relative 'sass/embedded/compile_context/importer_registry'
|
11
|
+
require_relative 'sass/embedded/compile_context/logger_registry'
|
12
|
+
require_relative 'sass/embedded/compile_context/value_protofier'
|
11
13
|
require_relative 'sass/embedded/compiler'
|
12
14
|
require_relative 'sass/embedded/compiler/path'
|
13
15
|
require_relative 'sass/embedded_protocol'
|
14
16
|
require_relative 'sass/embedded/legacy'
|
15
17
|
require_relative 'sass/embedded/protocol_error'
|
16
18
|
require_relative 'sass/embedded/protofier'
|
19
|
+
require_relative 'sass/embedded/structifier'
|
20
|
+
require_relative 'sass/embedded/varint'
|
17
21
|
require_relative 'sass/embedded/version'
|
18
22
|
require_relative 'sass/embedded/version_context'
|
19
23
|
require_relative 'sass/logger'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sass-embedded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- なつき
|
@@ -131,6 +131,8 @@ files:
|
|
131
131
|
- lib/sass/embedded/compile_context.rb
|
132
132
|
- lib/sass/embedded/compile_context/function_registry.rb
|
133
133
|
- lib/sass/embedded/compile_context/importer_registry.rb
|
134
|
+
- lib/sass/embedded/compile_context/logger_registry.rb
|
135
|
+
- lib/sass/embedded/compile_context/value_protofier.rb
|
134
136
|
- lib/sass/embedded/compiler.rb
|
135
137
|
- lib/sass/embedded/compiler/path.rb
|
136
138
|
- lib/sass/embedded/compiler/requirements.rb
|
@@ -138,6 +140,8 @@ files:
|
|
138
140
|
- lib/sass/embedded/observer.rb
|
139
141
|
- lib/sass/embedded/protocol_error.rb
|
140
142
|
- lib/sass/embedded/protofier.rb
|
143
|
+
- lib/sass/embedded/structifier.rb
|
144
|
+
- lib/sass/embedded/varint.rb
|
141
145
|
- lib/sass/embedded/version.rb
|
142
146
|
- lib/sass/embedded/version_context.rb
|
143
147
|
- lib/sass/embedded_protocol.rb
|
@@ -161,8 +165,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
|
|
161
165
|
licenses:
|
162
166
|
- MIT
|
163
167
|
metadata:
|
164
|
-
documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.16.
|
165
|
-
source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.16.
|
168
|
+
documentation_uri: https://www.rubydoc.info/gems/sass-embedded/0.16.2
|
169
|
+
source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.16.2
|
166
170
|
funding_uri: https://github.com/sponsors/ntkme
|
167
171
|
post_install_message:
|
168
172
|
rdoc_options: []
|