sass-embedded 0.13.3 → 0.16.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 +4 -4
- data/ext/sass/extconf.rb +52 -1
- data/lib/sass/compile_error.rb +1 -10
- data/lib/sass/compile_result.rb +1 -5
- data/lib/sass/embedded/channel.rb +2 -2
- data/lib/sass/embedded/compile_context/function_registry.rb +83 -0
- data/lib/sass/embedded/compile_context/importer_registry.rb +97 -0
- data/lib/sass/embedded/compile_context.rb +31 -194
- data/lib/sass/embedded/compiler/path.rb +1 -3
- data/lib/sass/embedded/compiler/requirements.rb +1 -1
- data/lib/sass/embedded/compiler.rb +7 -19
- data/lib/sass/embedded/{render.rb → legacy.rb} +79 -3
- data/lib/sass/embedded/observer.rb +2 -0
- data/lib/sass/embedded/protofier.rb +329 -0
- data/lib/sass/embedded/version.rb +1 -1
- data/lib/sass/embedded/version_context.rb +2 -3
- data/lib/sass/embedded.rb +39 -54
- data/lib/sass/embedded_protocol.rb +0 -6
- data/lib/sass/logger/source_location.rb +3 -9
- data/lib/sass/logger/source_span.rb +1 -13
- data/lib/sass/logger.rb +3 -3
- data/lib/sass/script_error.rb +5 -0
- data/lib/sass/value/argument_list.rb +24 -0
- data/lib/sass/value/boolean.rb +42 -0
- data/lib/sass/value/color.rb +213 -0
- data/lib/sass/value/function.rb +35 -0
- data/lib/sass/value/fuzzy_math.rb +81 -0
- data/lib/sass/value/list.rb +60 -0
- data/lib/sass/value/map.rb +57 -0
- data/lib/sass/value/null.rb +39 -0
- data/lib/sass/value/number/unit.rb +186 -0
- data/lib/sass/value/number.rb +272 -0
- data/lib/sass/value/string.rb +43 -0
- data/lib/sass/value.rb +92 -0
- data/lib/sass.rb +47 -48
- metadata +26 -57
- data/lib/sass/embedded/platform.rb +0 -55
- data/lib/sass/embedded/url.rb +0 -36
- data/lib/sass/file_importer.rb +0 -10
- data/lib/sass/importer.rb +0 -14
- data/lib/sass/importer_result.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74339d550d532d1edc9ecb2cb8894a514c5519c71af3eb4a6e3066f09c3d02e4
|
4
|
+
data.tar.gz: b93e64c9e33a7a684a4cb4767e2bdd62b2a81f0dd636483d31b174ba16c0a088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0aaddbc0bf954095bfa061e270eaa86e37409935ae180d1c13e97e3034eb89a913cce63f57c3d0dff2076ba17d03bd4516b058b809c702f31fc08fd40d6780c
|
7
|
+
data.tar.gz: 8a2317cbc80f5f6040e8d341e1f0eee67448547d2dd47b32e94caa5d869cfafc0a0b903e52b63a44f3bbec84178e072424a8a938dc0f568c42d3bffb1ee107ad
|
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
|
data/lib/sass/compile_error.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'logger/source_span'
|
4
|
-
|
5
3
|
module Sass
|
6
|
-
#
|
4
|
+
# An exception thrown because a Sass compilation failed.
|
7
5
|
class CompileError < StandardError
|
8
6
|
attr_accessor :sass_message, :sass_stack, :span
|
9
7
|
|
@@ -13,12 +11,5 @@ module Sass
|
|
13
11
|
@sass_stack = sass_stack
|
14
12
|
@span = span
|
15
13
|
end
|
16
|
-
|
17
|
-
def self.from_proto(compile_failure)
|
18
|
-
CompileError.new(compile_failure.formatted,
|
19
|
-
compile_failure.message,
|
20
|
-
compile_failure.stack_trace,
|
21
|
-
Logger::SourceSpan.from_proto(compile_failure.span))
|
22
|
-
end
|
23
14
|
end
|
24
15
|
end
|
data/lib/sass/compile_result.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Sass
|
4
|
-
# The
|
4
|
+
# The result of compiling Sass to CSS. Returned by {Sass.compile} and {Sass.compile_string}.
|
5
5
|
class CompileResult
|
6
6
|
attr_reader :css, :source_map, :loaded_urls
|
7
7
|
|
@@ -10,9 +10,5 @@ module Sass
|
|
10
10
|
@source_map = source_map == '' ? nil : source_map
|
11
11
|
@loaded_urls = loaded_urls
|
12
12
|
end
|
13
|
-
|
14
|
-
def self.from_proto(compile_success)
|
15
|
-
CompileResult.new(compile_success.css, compile_success.source_map, compile_success.loaded_urls)
|
16
|
-
end
|
17
13
|
end
|
18
14
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'compiler'
|
4
|
-
|
5
3
|
module Sass
|
6
4
|
class Embedded
|
7
5
|
# The {Channel} for {Compiler} calls. Each instance creates its own
|
@@ -58,5 +56,7 @@ module Sass
|
|
58
56
|
|
59
57
|
private_constant :Subscription
|
60
58
|
end
|
59
|
+
|
60
|
+
private_constant :Channel
|
61
61
|
end
|
62
62
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
class CompileContext
|
6
|
+
# The {FunctionRegistry} for {CompileContext}.
|
7
|
+
class FunctionRegistry
|
8
|
+
attr_reader :global_functions
|
9
|
+
|
10
|
+
def initialize(functions)
|
11
|
+
@global_functions = functions.keys
|
12
|
+
@functions_by_name = functions.transform_keys do |signature|
|
13
|
+
signature = signature.chomp
|
14
|
+
index = signature.index('(')
|
15
|
+
if index
|
16
|
+
signature.slice(0, index)
|
17
|
+
else
|
18
|
+
signature
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@functions_by_id = {}
|
22
|
+
@ids_by_function = {}
|
23
|
+
@id = 0
|
24
|
+
end
|
25
|
+
|
26
|
+
def register(function)
|
27
|
+
return if @ids_by_function.key?(function)
|
28
|
+
|
29
|
+
id = @id
|
30
|
+
@id = @id.next
|
31
|
+
|
32
|
+
@ids_by_function[function] = id
|
33
|
+
@functions_by_id[id] = function
|
34
|
+
|
35
|
+
id
|
36
|
+
end
|
37
|
+
|
38
|
+
def function_call(function_call_request)
|
39
|
+
arguments = function_call_request.arguments.map do |argument|
|
40
|
+
protofier.from_proto_value(argument)
|
41
|
+
end
|
42
|
+
|
43
|
+
success = protofier.to_proto_value(get(function_call_request).call(arguments))
|
44
|
+
accessed_argument_lists = arguments
|
45
|
+
.filter do |argument|
|
46
|
+
argument.is_a?(Sass::Value::ArgumentList) && argument.instance_eval do
|
47
|
+
@keywords_accessed
|
48
|
+
end
|
49
|
+
end
|
50
|
+
.map { |argument| argument.instance_eval { @id } }
|
51
|
+
|
52
|
+
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
53
|
+
id: function_call_request.id,
|
54
|
+
success: success,
|
55
|
+
accessed_argument_lists: accessed_argument_lists
|
56
|
+
)
|
57
|
+
rescue StandardError => e
|
58
|
+
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
59
|
+
id: function_call_request.id,
|
60
|
+
error: e.message
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def get(function_call_request)
|
67
|
+
case function_call_request.identifier
|
68
|
+
when :name
|
69
|
+
@functions_by_name[function_call_request.name]
|
70
|
+
when :function_id
|
71
|
+
@functions_by_id[function_call_request.function_id]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def protofier
|
76
|
+
@protofier ||= Protofier.new(self)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private_constant :FunctionRegistry
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
class CompileContext
|
6
|
+
# The {ImporterRegistry} for {CompileContext}.
|
7
|
+
class ImporterRegistry
|
8
|
+
attr_reader :importers
|
9
|
+
|
10
|
+
def initialize(importers, load_paths)
|
11
|
+
@id = 0
|
12
|
+
@importers_by_id = {}
|
13
|
+
@importers = importers
|
14
|
+
.map { |importer| register(importer) }
|
15
|
+
.concat(load_paths.map do |load_path|
|
16
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
17
|
+
path: File.absolute_path(load_path)
|
18
|
+
)
|
19
|
+
end)
|
20
|
+
end
|
21
|
+
|
22
|
+
def register(importer)
|
23
|
+
is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
|
24
|
+
is_file_importer = importer.respond_to?(:find_file_url)
|
25
|
+
|
26
|
+
raise ArgumentError, 'importer must be an Importer or a FileImporter' if is_importer == is_file_importer
|
27
|
+
|
28
|
+
proto = if is_importer
|
29
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
30
|
+
importer_id: @id
|
31
|
+
)
|
32
|
+
else
|
33
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
34
|
+
file_importer_id: @id
|
35
|
+
)
|
36
|
+
end
|
37
|
+
@importers_by_id[@id] = importer
|
38
|
+
@id = @id.next
|
39
|
+
proto
|
40
|
+
end
|
41
|
+
|
42
|
+
def canonicalize(canonicalize_request)
|
43
|
+
importer = @importers_by_id[canonicalize_request.importer_id]
|
44
|
+
url = importer.canonicalize(canonicalize_request.url, from_import: canonicalize_request.from_import)&.to_s
|
45
|
+
|
46
|
+
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
47
|
+
id: canonicalize_request.id,
|
48
|
+
url: url
|
49
|
+
)
|
50
|
+
rescue StandardError => e
|
51
|
+
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
52
|
+
id: canonicalize_request.id,
|
53
|
+
error: e.message
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def import(import_request)
|
58
|
+
importer = @importers_by_id[import_request.importer_id]
|
59
|
+
importer_result = Protofier.to_struct importer.load(import_request.url)
|
60
|
+
|
61
|
+
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
62
|
+
id: import_request.id,
|
63
|
+
success: EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
|
64
|
+
contents: importer_result.contents,
|
65
|
+
syntax: Protofier.to_proto_syntax(importer_result.syntax),
|
66
|
+
source_map_url: importer_result.respond_to?(:source_map_url) ? importer_result.source_map_url&.to_s : nil
|
67
|
+
)
|
68
|
+
)
|
69
|
+
rescue StandardError => e
|
70
|
+
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
71
|
+
id: import_request.id,
|
72
|
+
error: e.message
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def file_import(file_import_request)
|
77
|
+
importer = @importers_by_id[file_import_request.importer_id]
|
78
|
+
file_url = importer.find_file_url(file_import_request.url, from_import: file_import_request.from_import)&.to_s
|
79
|
+
|
80
|
+
raise "file_url must be a file: URL, was \"#{file_url}\"" if !file_url.nil? && !file_url.start_with?('file:')
|
81
|
+
|
82
|
+
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
83
|
+
id: file_import_request.id,
|
84
|
+
file_url: file_url
|
85
|
+
)
|
86
|
+
rescue StandardError => e
|
87
|
+
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
88
|
+
id: file_import_request.id,
|
89
|
+
error: e.message
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private_constant :ImporterRegistry
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../embedded_protocol'
|
4
|
-
require_relative '../logger/source_span'
|
5
|
-
require_relative 'observer'
|
6
|
-
|
7
3
|
module Sass
|
8
4
|
class Embedded
|
9
5
|
# The {Observer} for {Embedded#compile}.
|
@@ -34,7 +30,6 @@ module Sass
|
|
34
30
|
@path = path
|
35
31
|
@source = source
|
36
32
|
|
37
|
-
@importer = importer
|
38
33
|
@load_paths = load_paths
|
39
34
|
@syntax = syntax
|
40
35
|
@url = url
|
@@ -43,19 +38,16 @@ module Sass
|
|
43
38
|
@source_map_include_sources = source_map_include_sources
|
44
39
|
@style = style
|
45
40
|
|
46
|
-
@
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@importers = importers
|
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))
|
52
46
|
|
53
47
|
@alert_ascii = alert_ascii
|
54
48
|
@alert_color = alert_color
|
55
49
|
|
56
|
-
|
57
|
-
instance_variable_set("@#{sym}".to_sym, get_method(logger, sym))
|
58
|
-
end
|
50
|
+
@logger = Protofier.to_struct(logger)
|
59
51
|
|
60
52
|
@quiet_deps = quiet_deps
|
61
53
|
@verbose = verbose
|
@@ -83,25 +75,25 @@ module Sass
|
|
83
75
|
return unless message.compilation_id == id
|
84
76
|
|
85
77
|
Thread.new do
|
86
|
-
send_message
|
78
|
+
send_message @importer_registery.canonicalize message
|
87
79
|
end
|
88
80
|
when EmbeddedProtocol::OutboundMessage::ImportRequest
|
89
81
|
return unless message.compilation_id == id
|
90
82
|
|
91
83
|
Thread.new do
|
92
|
-
send_message
|
84
|
+
send_message @importer_registery.import message
|
93
85
|
end
|
94
86
|
when EmbeddedProtocol::OutboundMessage::FileImportRequest
|
95
87
|
return unless message.compilation_id == id
|
96
88
|
|
97
89
|
Thread.new do
|
98
|
-
send_message
|
90
|
+
send_message @importer_registery.file_import message
|
99
91
|
end
|
100
92
|
when EmbeddedProtocol::OutboundMessage::FunctionCallRequest
|
101
93
|
return unless message.compilation_id == id
|
102
94
|
|
103
95
|
Thread.new do
|
104
|
-
send_message
|
96
|
+
send_message @function_registery.function_call message
|
105
97
|
end
|
106
98
|
end
|
107
99
|
rescue StandardError => e
|
@@ -115,26 +107,26 @@ module Sass
|
|
115
107
|
def log(event)
|
116
108
|
case event.type
|
117
109
|
when :DEBUG
|
118
|
-
if @
|
119
|
-
|
110
|
+
if @logger.respond_to? :debug
|
111
|
+
@logger.debug(event.message, span: Protofier.from_proto_source_span(event.span))
|
120
112
|
else
|
121
|
-
|
113
|
+
Kernel.warn(event.formatted)
|
122
114
|
end
|
123
115
|
when :DEPRECATION_WARNING
|
124
|
-
if @
|
125
|
-
|
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)
|
126
120
|
else
|
127
|
-
|
128
|
-
span: Logger::SourceSpan.from_proto(event.span),
|
129
|
-
stack: event.stack_trace)
|
121
|
+
Kernel.warn(event.formatted)
|
130
122
|
end
|
131
123
|
when :WARNING
|
132
|
-
if @
|
133
|
-
|
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)
|
134
128
|
else
|
135
|
-
|
136
|
-
span: Logger::SourceSpan.from_proto(event.span),
|
137
|
-
stack: event.stack_trace)
|
129
|
+
Kernel.warn(event.formatted)
|
138
130
|
end
|
139
131
|
end
|
140
132
|
end
|
@@ -145,178 +137,23 @@ module Sass
|
|
145
137
|
string: unless @source.nil?
|
146
138
|
EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
|
147
139
|
source: @source,
|
148
|
-
url: @url,
|
149
|
-
syntax: to_proto_syntax(@syntax),
|
150
|
-
importer: @importer
|
140
|
+
url: @url&.to_s,
|
141
|
+
syntax: Protofier.to_proto_syntax(@syntax),
|
142
|
+
importer: @importer
|
151
143
|
)
|
152
144
|
end,
|
153
145
|
path: @path,
|
154
|
-
style: to_proto_output_style(@style),
|
146
|
+
style: Protofier.to_proto_output_style(@style),
|
155
147
|
source_map: @source_map,
|
156
148
|
source_map_include_sources: @source_map_include_sources,
|
157
|
-
importers:
|
158
|
-
global_functions: @global_functions,
|
149
|
+
importers: @importer_registery.importers,
|
150
|
+
global_functions: @function_registery.global_functions,
|
159
151
|
alert_ascii: @alert_ascii,
|
160
152
|
alert_color: @alert_color
|
161
153
|
)
|
162
154
|
end
|
163
|
-
|
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
|
168
|
-
|
169
|
-
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
170
|
-
id: canonicalize_request.id,
|
171
|
-
url: url
|
172
|
-
)
|
173
|
-
rescue StandardError => e
|
174
|
-
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
175
|
-
id: canonicalize_request.id,
|
176
|
-
error: e.message
|
177
|
-
)
|
178
|
-
end
|
179
|
-
|
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
|
183
|
-
|
184
|
-
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
185
|
-
id: import_request.id,
|
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)
|
190
|
-
)
|
191
|
-
)
|
192
|
-
rescue StandardError => e
|
193
|
-
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
194
|
-
id: import_request.id,
|
195
|
-
error: e.message
|
196
|
-
)
|
197
|
-
end
|
198
|
-
|
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
|
203
|
-
|
204
|
-
raise "file_url must be a file: URL, was \"#{file_url}\"" if !file_url.nil? && !file_url.start_with?('file:')
|
205
|
-
|
206
|
-
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
207
|
-
id: file_import_request.id,
|
208
|
-
file_url: file_url
|
209
|
-
)
|
210
|
-
rescue StandardError => e
|
211
|
-
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
212
|
-
id: file_import_request.id,
|
213
|
-
error: e.message
|
214
|
-
)
|
215
|
-
end
|
216
|
-
|
217
|
-
def function_call_response(function_call_request)
|
218
|
-
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
219
|
-
id: function_call_request.id,
|
220
|
-
success: @functions[function_call_request.name].call(*function_call_request.arguments),
|
221
|
-
accessed_argument_lists: function_call_request.arguments
|
222
|
-
.filter { |argument| argument.value == :argument_list }
|
223
|
-
.map { |argument| argument.argument_list.id }
|
224
|
-
)
|
225
|
-
rescue StandardError => e
|
226
|
-
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
227
|
-
id: function_call_request.id,
|
228
|
-
error: e.message
|
229
|
-
)
|
230
|
-
end
|
231
|
-
|
232
|
-
def to_proto_syntax(syntax)
|
233
|
-
case syntax&.to_sym
|
234
|
-
when :scss
|
235
|
-
EmbeddedProtocol::Syntax::SCSS
|
236
|
-
when :indented
|
237
|
-
EmbeddedProtocol::Syntax::INDENTED
|
238
|
-
when :css
|
239
|
-
EmbeddedProtocol::Syntax::CSS
|
240
|
-
else
|
241
|
-
raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
def to_proto_output_style(style)
|
246
|
-
case style&.to_sym
|
247
|
-
when :expanded
|
248
|
-
EmbeddedProtocol::OutputStyle::EXPANDED
|
249
|
-
when :compressed
|
250
|
-
EmbeddedProtocol::OutputStyle::COMPRESSED
|
251
|
-
else
|
252
|
-
raise ArgumentError, 'style must be one of :expanded, :compressed'
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
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)
|
259
|
-
|
260
|
-
if is_importer && !is_file_importer
|
261
|
-
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
262
|
-
importer_id: id
|
263
|
-
)
|
264
|
-
elsif is_file_importer && !is_importer
|
265
|
-
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
266
|
-
file_importer_id: id
|
267
|
-
)
|
268
|
-
else
|
269
|
-
raise ArgumentError, 'importer must be an Importer or a FileImporter'
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
def to_proto_importers(importers, load_paths)
|
274
|
-
proto_importers = importers.map.with_index do |importer, id|
|
275
|
-
to_proto_importer(importer, id)
|
276
|
-
end
|
277
|
-
|
278
|
-
load_paths.each do |load_path|
|
279
|
-
proto_importers << EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
280
|
-
path: File.absolute_path(load_path)
|
281
|
-
)
|
282
|
-
end
|
283
|
-
|
284
|
-
proto_importers
|
285
|
-
end
|
286
|
-
|
287
|
-
def importer_with_id(id)
|
288
|
-
if id == @importers.length
|
289
|
-
@importer
|
290
|
-
else
|
291
|
-
@importers[id]
|
292
|
-
end
|
293
|
-
end
|
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.is_a? Hash
|
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
|
307
|
-
|
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.is_a? Hash
|
313
|
-
if obj[sym]
|
314
|
-
obj[sym]
|
315
|
-
elsif obj[sym.to_s]
|
316
|
-
obj[sym.to_s]
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
155
|
end
|
156
|
+
|
157
|
+
private_constant :CompileContext
|
321
158
|
end
|
322
159
|
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#{
|
7
|
+
"../../../../ext/sass/sass_embedded/dart-sass-embedded#{Gem.win_platform? ? '.bat' : ''}", __dir__
|
10
8
|
)
|
11
9
|
end
|
12
10
|
end
|