sass-embedded 0.1.1 → 0.2.3
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/.github/workflows/build.yml +1 -4
- data/Gemfile +2 -0
- data/README.md +2 -0
- data/Rakefile +6 -2
- data/ext/sass_embedded/Makefile +13 -20
- data/ext/sass_embedded/extconf.rb +112 -114
- data/lib/sass.rb +23 -18
- data/lib/sass/embedded.rb +237 -0
- data/lib/sass/error.rb +5 -2
- data/lib/sass/platform.rb +17 -20
- data/lib/sass/transport.rb +139 -0
- data/lib/sass/util.rb +4 -4
- data/lib/sass/version.rb +1 -2
- data/sass-embedded.gemspec +18 -19
- data/test/compiler_test.rb +169 -171
- data/test/custom_importer_test.rb +100 -98
- data/test/error_test.rb +14 -16
- data/test/functions_test.rb +197 -181
- data/test/output_style_test.rb +52 -52
- data/test/sass_test.rb +22 -0
- data/test/test_helper.rb +5 -5
- metadata +20 -4
- data/lib/sass/embedded/compiler.rb +0 -250
- data/lib/sass/embedded/transport.rb +0 -147
data/test/output_style_test.rb
CHANGED
@@ -1,92 +1,92 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative 'test_helper'
|
4
4
|
|
5
5
|
module Sass
|
6
6
|
class OutputStyleTest < MiniTest::Test
|
7
|
-
|
8
7
|
def setup
|
9
|
-
@
|
8
|
+
@embedded = Embedded.new
|
10
9
|
end
|
11
10
|
|
12
11
|
def teardown
|
12
|
+
@embedded.close
|
13
13
|
end
|
14
14
|
|
15
15
|
def input_scss
|
16
|
-
|
17
|
-
$color: #fff;
|
18
|
-
|
19
|
-
#main {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
.huge {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
CSS
|
16
|
+
<<~CSS
|
17
|
+
$color: #fff;
|
18
|
+
|
19
|
+
#main {
|
20
|
+
color: $color;
|
21
|
+
background-color: #000;
|
22
|
+
p {
|
23
|
+
width: 10em;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
.huge {
|
28
|
+
font-size: 10em;
|
29
|
+
font-weight: bold;
|
30
|
+
text-decoration: underline;
|
31
|
+
}
|
32
|
+
CSS
|
33
33
|
end
|
34
34
|
|
35
35
|
def expected_expanded_output
|
36
|
-
|
37
|
-
#main {
|
38
|
-
|
39
|
-
|
40
|
-
}
|
41
|
-
#main p {
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
.huge {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
CSS
|
36
|
+
<<~CSS.chomp
|
37
|
+
#main {
|
38
|
+
color: #fff;
|
39
|
+
background-color: #000;
|
40
|
+
}
|
41
|
+
#main p {
|
42
|
+
width: 10em;
|
43
|
+
}
|
44
|
+
|
45
|
+
.huge {
|
46
|
+
font-size: 10em;
|
47
|
+
font-weight: bold;
|
48
|
+
text-decoration: underline;
|
49
|
+
}
|
50
|
+
CSS
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_expanded_output_is_default
|
54
|
-
output = @
|
54
|
+
output = @embedded.render({ data: input_scss })[:css]
|
55
55
|
assert_equal expected_expanded_output, output
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_output_style_accepts_strings
|
59
|
-
output = @
|
59
|
+
output = @embedded.render({ data: input_scss, output_style: :expanded })[:css]
|
60
60
|
assert_equal expected_expanded_output, output
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_invalid_output_style
|
64
|
-
assert_raises(InvalidStyleError)
|
65
|
-
@
|
66
|
-
|
64
|
+
assert_raises(InvalidStyleError) do
|
65
|
+
@embedded.render({ data: input_scss, output_style: :totally_wrong })[:css]
|
66
|
+
end
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_unsupported_output_style
|
70
|
-
assert_raises(UnsupportedValue)
|
71
|
-
@
|
72
|
-
|
70
|
+
assert_raises(UnsupportedValue) do
|
71
|
+
@embedded.render({ data: input_scss, output_style: :nested })[:css]
|
72
|
+
end
|
73
73
|
|
74
|
-
assert_raises(UnsupportedValue)
|
75
|
-
@
|
76
|
-
|
74
|
+
assert_raises(UnsupportedValue) do
|
75
|
+
@embedded.render({ data: input_scss, output_style: :compact })[:css]
|
76
|
+
end
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_compressed_output
|
80
|
-
output = @
|
81
|
-
assert_equal
|
82
|
-
#main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
80
|
+
output = @embedded.render({ data: input_scss, output_style: :compressed })[:css]
|
81
|
+
assert_equal <<~CSS.chomp, output
|
82
|
+
#main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
83
83
|
CSS
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_string_output_style_names
|
87
|
-
output = @
|
88
|
-
assert_equal
|
89
|
-
#main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
87
|
+
output = @embedded.render({ data: input_scss, output_style: 'compressed' })[:css]
|
88
|
+
assert_equal <<~CSS.chomp, output
|
89
|
+
#main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
90
90
|
CSS
|
91
91
|
end
|
92
92
|
end
|
data/test/sass_test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'test_helper'
|
4
|
+
|
5
|
+
module Sass
|
6
|
+
class SassTest < MiniTest::Test
|
7
|
+
def test_sass_works
|
8
|
+
assert_equal '', Sass.render({
|
9
|
+
data: ''
|
10
|
+
})[:css]
|
11
|
+
|
12
|
+
css = <<~CSS.chomp
|
13
|
+
h1 {
|
14
|
+
font-size: 2rem;
|
15
|
+
}
|
16
|
+
CSS
|
17
|
+
assert_equal css, Sass.render({
|
18
|
+
data: 'h1 { font-size: 2rem; }'
|
19
|
+
})[:css]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/pride'
|
6
|
+
require 'minitest/around/unit'
|
7
7
|
|
8
|
-
require_relative
|
8
|
+
require_relative '../lib/sass'
|
9
9
|
|
10
10
|
module TempFileTest
|
11
11
|
def around
|
@@ -18,7 +18,7 @@ module TempFileTest
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def temp_file(filename, contents)
|
21
|
-
File.open(filename,
|
21
|
+
File.open(filename, 'w') do |file|
|
22
22
|
file.write(contents)
|
23
23
|
end
|
24
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.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- なつき
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Use dart-sass with Ruby!
|
98
112
|
email:
|
99
113
|
- i@ntk.me
|
@@ -112,10 +126,10 @@ files:
|
|
112
126
|
- ext/sass_embedded/Makefile
|
113
127
|
- ext/sass_embedded/extconf.rb
|
114
128
|
- lib/sass.rb
|
115
|
-
- lib/sass/embedded
|
116
|
-
- lib/sass/embedded/transport.rb
|
129
|
+
- lib/sass/embedded.rb
|
117
130
|
- lib/sass/error.rb
|
118
131
|
- lib/sass/platform.rb
|
132
|
+
- lib/sass/transport.rb
|
119
133
|
- lib/sass/util.rb
|
120
134
|
- lib/sass/version.rb
|
121
135
|
- sass-embedded.gemspec
|
@@ -124,6 +138,7 @@ files:
|
|
124
138
|
- test/error_test.rb
|
125
139
|
- test/functions_test.rb
|
126
140
|
- test/output_style_test.rb
|
141
|
+
- test/sass_test.rb
|
127
142
|
- test/test_helper.rb
|
128
143
|
homepage: https://github.com/ntkme/embedded-host-ruby
|
129
144
|
licenses:
|
@@ -154,4 +169,5 @@ test_files:
|
|
154
169
|
- test/error_test.rb
|
155
170
|
- test/functions_test.rb
|
156
171
|
- test/output_style_test.rb
|
172
|
+
- test/sass_test.rb
|
157
173
|
- test/test_helper.rb
|
@@ -1,250 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Sass
|
4
|
-
module Embedded
|
5
|
-
class Compiler
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
if defined? @@pwd
|
9
|
-
if @@pwd == Dir.pwd
|
10
|
-
return
|
11
|
-
else
|
12
|
-
@@transport.close
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
@@transport = Transport.new
|
17
|
-
@@pwd = Dir.pwd
|
18
|
-
|
19
|
-
@@id_semaphore = Mutex.new
|
20
|
-
@@id = 0
|
21
|
-
end
|
22
|
-
|
23
|
-
def render options
|
24
|
-
start = Sass::Util.now
|
25
|
-
|
26
|
-
if options[:file].nil? && options[:data].nil?
|
27
|
-
raise Sass::NotRenderedError.new 'Either :data or :file must be set.'
|
28
|
-
end
|
29
|
-
|
30
|
-
if options[:file].nil? && Dir.pwd != @@pwd
|
31
|
-
raise Sass::NotRenderedError.new 'Working directory changed after launching `dart-sass-embedded`.'
|
32
|
-
end
|
33
|
-
|
34
|
-
string = options[:data] ? Sass::EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
|
35
|
-
:source => options[:data],
|
36
|
-
:url => options[:file] ? Sass::Util.file_uri(options[:file]) : 'stdin',
|
37
|
-
:syntax => options[:indented_syntax] == true ? Sass::EmbeddedProtocol::Syntax::INDENTED : Sass::EmbeddedProtocol::Syntax::SCSS
|
38
|
-
) : nil
|
39
|
-
|
40
|
-
path = options[:data] ? nil : options[:file]
|
41
|
-
|
42
|
-
style = case options[:output_style]&.to_sym
|
43
|
-
when :expanded, nil
|
44
|
-
Sass::EmbeddedProtocol::OutputStyle::EXPANDED
|
45
|
-
when :compressed
|
46
|
-
Sass::EmbeddedProtocol::OutputStyle::COMPRESSED
|
47
|
-
when :nested, :compact
|
48
|
-
raise Sass::UnsupportedValue.new "#{options[:output_style]} is not a supported :output_style"
|
49
|
-
else
|
50
|
-
raise Sass::InvalidStyleError.new "#{options[:output_style]} is not a valid :output_style"
|
51
|
-
end
|
52
|
-
|
53
|
-
source_map = options[:source_map].is_a? String || (options[:source_map] == true && !!options[:out_file])
|
54
|
-
|
55
|
-
# 1. Loading a file relative to the file in which the @use or @import appeared.
|
56
|
-
# 2. Each custom importer.
|
57
|
-
# 3. Loading a file relative to the current working directory.
|
58
|
-
# 4. Each load path in includePaths
|
59
|
-
# 5. Each load path specified in the SASS_PATH environment variable, which should be semicolon-separated on Windows and colon-separated elsewhere.
|
60
|
-
importers = (options[:importer] ? [
|
61
|
-
Sass::EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new( :importer_id => 0 )
|
62
|
-
] : []).concat(
|
63
|
-
Sass.include_paths.concat(options[:include_paths] || [])
|
64
|
-
.map { |path| Sass::EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
65
|
-
:path => File.absolute_path(path)
|
66
|
-
)}
|
67
|
-
)
|
68
|
-
|
69
|
-
signatures = []
|
70
|
-
functions = {}
|
71
|
-
options[:functions]&.each { |signature, function|
|
72
|
-
signatures.push signature
|
73
|
-
functions[signature.to_s.split('(')[0].chomp] = function
|
74
|
-
}
|
75
|
-
|
76
|
-
compilation_id = next_id
|
77
|
-
|
78
|
-
compile_request = Sass::EmbeddedProtocol::InboundMessage::CompileRequest.new(
|
79
|
-
:id => compilation_id,
|
80
|
-
:string => string,
|
81
|
-
:path => path,
|
82
|
-
:style => style,
|
83
|
-
:source_map => source_map,
|
84
|
-
:importers => importers,
|
85
|
-
:global_functions => options[:functions] ? signatures : [],
|
86
|
-
:alert_color => true,
|
87
|
-
:alert_ascii => true
|
88
|
-
)
|
89
|
-
|
90
|
-
response = @@transport.send compile_request, compilation_id
|
91
|
-
|
92
|
-
file = options[:file] || 'stdin'
|
93
|
-
canonicalizations = {}
|
94
|
-
imports = {}
|
95
|
-
|
96
|
-
loop do
|
97
|
-
case response
|
98
|
-
when Sass::EmbeddedProtocol::OutboundMessage::CompileResponse
|
99
|
-
break
|
100
|
-
when Sass::EmbeddedProtocol::OutboundMessage::CanonicalizeRequest
|
101
|
-
url = Sass::Util.file_uri(File.absolute_path(response.url, File.dirname(file)))
|
102
|
-
|
103
|
-
if canonicalizations.has_key? url
|
104
|
-
canonicalizations[url].id = response.id
|
105
|
-
else
|
106
|
-
resolved = nil
|
107
|
-
options[:importer].each { |importer|
|
108
|
-
begin
|
109
|
-
resolved = importer.call response.url, file
|
110
|
-
rescue Exception => error
|
111
|
-
resolved = error
|
112
|
-
end
|
113
|
-
break if resolved
|
114
|
-
}
|
115
|
-
if resolved.nil?
|
116
|
-
canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
117
|
-
:id => response.id,
|
118
|
-
:url => url
|
119
|
-
)
|
120
|
-
elsif resolved.is_a? Exception
|
121
|
-
canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
122
|
-
:id => response.id,
|
123
|
-
:error => resolved.message
|
124
|
-
)
|
125
|
-
elsif resolved.has_key? :contents
|
126
|
-
canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
127
|
-
:id => response.id,
|
128
|
-
:url => url
|
129
|
-
)
|
130
|
-
imports[url] = Sass::EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
131
|
-
:id => response.id,
|
132
|
-
:success => Sass::EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
|
133
|
-
:contents => resolved[:contents],
|
134
|
-
:syntax => Sass::EmbeddedProtocol::Syntax::SCSS,
|
135
|
-
:source_map_url => nil
|
136
|
-
)
|
137
|
-
)
|
138
|
-
elsif resolved.has_key? :file
|
139
|
-
canonicalized_url = Sass::Util.file_uri(resolved[:file])
|
140
|
-
canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
141
|
-
:id => response.id,
|
142
|
-
:url => canonicalized_url
|
143
|
-
)
|
144
|
-
imports[canonicalized_url] = Sass::EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
145
|
-
:id => response.id,
|
146
|
-
:success => Sass::EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
|
147
|
-
:contents => File.read(resolved[:file]),
|
148
|
-
:syntax => Sass::EmbeddedProtocol::Syntax::SCSS,
|
149
|
-
:source_map_url => nil
|
150
|
-
)
|
151
|
-
)
|
152
|
-
else
|
153
|
-
canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
154
|
-
:id => response.id,
|
155
|
-
:error => "Unexpected value returned from importer: #{resolved}"
|
156
|
-
)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
response = @@transport.send canonicalizations[url], compilation_id
|
161
|
-
when Sass::EmbeddedProtocol::OutboundMessage::ImportRequest
|
162
|
-
url = response.url
|
163
|
-
|
164
|
-
if imports.has_key? url
|
165
|
-
imports[url].id = response.id
|
166
|
-
else
|
167
|
-
imports[url] = Sass::EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
168
|
-
:id => response.id,
|
169
|
-
:error => "Failed to import: #{url}"
|
170
|
-
)
|
171
|
-
end
|
172
|
-
|
173
|
-
response = @@transport.send imports[url], compilation_id
|
174
|
-
when Sass::EmbeddedProtocol::OutboundMessage::FunctionCallRequest
|
175
|
-
begin
|
176
|
-
message = Sass::EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
177
|
-
:id => response.id,
|
178
|
-
:success => functions[response.name].call(*response.arguments)
|
179
|
-
)
|
180
|
-
rescue Exception => error
|
181
|
-
message = Sass::EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
182
|
-
:id => response.id,
|
183
|
-
:error => error.message
|
184
|
-
)
|
185
|
-
end
|
186
|
-
|
187
|
-
response = @@transport.send message, compilation_id
|
188
|
-
when Sass::EmbeddedProtocol::ProtocolError
|
189
|
-
raise Sass::ProtocolError.new response.message
|
190
|
-
else
|
191
|
-
raise Sass::ProtocolError.new "Unexpected packet received: #{response}"
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
if response.failure
|
196
|
-
raise Sass::CompilationError.new(
|
197
|
-
response.failure.message,
|
198
|
-
response.failure.formatted,
|
199
|
-
response.failure.span ? response.failure.span.url : nil,
|
200
|
-
response.failure.span ? response.failure.span.start.line + 1 : nil,
|
201
|
-
response.failure.span ? response.failure.span.start.column + 1 : nil,
|
202
|
-
1
|
203
|
-
)
|
204
|
-
end
|
205
|
-
|
206
|
-
finish = Sass::Util.now
|
207
|
-
|
208
|
-
return {
|
209
|
-
css: response.success.css,
|
210
|
-
map: response.success.source_map,
|
211
|
-
stats: {
|
212
|
-
entry: options[:file] || 'data',
|
213
|
-
start: start,
|
214
|
-
end: finish,
|
215
|
-
duration: finish - start
|
216
|
-
}
|
217
|
-
}
|
218
|
-
end
|
219
|
-
|
220
|
-
private
|
221
|
-
|
222
|
-
def info
|
223
|
-
version_response = @@transport.send Sass::EmbeddedProtocol::InboundMessage::VersionRequest.new(
|
224
|
-
:id => next_id
|
225
|
-
)
|
226
|
-
return {
|
227
|
-
compiler_version: version_response.compiler_version,
|
228
|
-
protocol_version: version_response.protocol_version,
|
229
|
-
implementation_name: version_response.implementation_name,
|
230
|
-
implementation_version: version_response.implementation_version
|
231
|
-
}
|
232
|
-
end
|
233
|
-
|
234
|
-
def next_id
|
235
|
-
@@id_semaphore.synchronize {
|
236
|
-
@@id += 1
|
237
|
-
if @@id == Transport::PROTOCOL_ERROR_ID
|
238
|
-
@@id = 0
|
239
|
-
end
|
240
|
-
@@id
|
241
|
-
}
|
242
|
-
end
|
243
|
-
|
244
|
-
def restart
|
245
|
-
@@transport.close
|
246
|
-
@@transport = Transport.new
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|