sass-embedded 0.1.2 → 0.2.4
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 +7 -3
- data/ext/{sass_embedded/.gitignore → .gitignore} +0 -0
- data/ext/Makefile +51 -0
- data/ext/extconf.rb +159 -0
- data/lib/sass.rb +17 -12
- 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 +19 -20
- data/test/compiler_test.rb +165 -167
- 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 +24 -8
- data/ext/sass_embedded/Makefile +0 -35
- data/ext/sass_embedded/extconf.rb +0 -131
- 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.4
|
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,12 +94,26 @@ 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
|
100
114
|
executables: []
|
101
115
|
extensions:
|
102
|
-
- ext/
|
116
|
+
- ext/extconf.rb
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
105
119
|
- ".github/workflows/build.yml"
|
@@ -108,14 +122,14 @@ files:
|
|
108
122
|
- LICENSE
|
109
123
|
- README.md
|
110
124
|
- Rakefile
|
111
|
-
- ext
|
112
|
-
- ext/
|
113
|
-
- ext/
|
125
|
+
- ext/.gitignore
|
126
|
+
- ext/Makefile
|
127
|
+
- ext/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
|
data/ext/sass_embedded/Makefile
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
.PHONY: install
|
2
|
-
install:
|
3
|
-
ifeq ($(OS),Windows_NT)
|
4
|
-
powershell -command "Get-Item sass_embedded-*.zip | Expand-Archive -DestinationPath (Get-Location) -Force"
|
5
|
-
powershell -command "Get-Item protoc-*.zip | Expand-Archive -DestinationPath protoc -Force"
|
6
|
-
./protoc/bin/protoc --ruby_out=. embedded_sass.proto
|
7
|
-
else
|
8
|
-
tar -vxzf sass_embedded-*.tar.gz
|
9
|
-
unzip -od protoc protoc-*.zip
|
10
|
-
./protoc/bin/protoc --ruby_out=. embedded_sass.proto
|
11
|
-
endif
|
12
|
-
|
13
|
-
.PHONY: clean
|
14
|
-
clean:
|
15
|
-
ifeq ($(OS),Windows_NT)
|
16
|
-
powershell -command "Remove-Item sass_embedded -Recurse -Force -ErrorAction Ignore"
|
17
|
-
powershell -command "Remove-Item protoc -Recurse -Force -ErrorAction Ignore"
|
18
|
-
powershell -command "Remove-Item embedded_sass_pb.rb -Recurse -Force -ErrorAction Ignore"
|
19
|
-
else
|
20
|
-
rm -rf sass_embedded
|
21
|
-
rm -rf protoc
|
22
|
-
rm -rf embedded_sass_pb.rb
|
23
|
-
endif
|
24
|
-
|
25
|
-
.PHONY: distclean
|
26
|
-
distclean: clean
|
27
|
-
ifeq ($(OS),Windows_NT)
|
28
|
-
powershell -command "Remove-Item sass_embedded-*.zip -Force -ErrorAction Ignore"
|
29
|
-
powershell -command "Remove-Item protoc-*.zip -Force -ErrorAction Ignore"
|
30
|
-
powershell -command "Remove-Item embedded_sass.proto -Force -ErrorAction Ignore"
|
31
|
-
else
|
32
|
-
rm -rf sass_embedded-*.tar.gz
|
33
|
-
rm -rf protoc-*.zip
|
34
|
-
rm -rf embedded_sass.proto
|
35
|
-
endif
|
@@ -1,131 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "mkmf"
|
4
|
-
require "json"
|
5
|
-
require "open-uri"
|
6
|
-
require_relative "../../lib/sass/platform"
|
7
|
-
|
8
|
-
def api url
|
9
|
-
headers = {}
|
10
|
-
headers["Authorization"] = "token #{ENV["GITHUB_TOKEN"]}" if ENV["GITHUB_TOKEN"]
|
11
|
-
URI.open(url, headers) do |file|
|
12
|
-
JSON.parse file.read
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def download url
|
17
|
-
URI.open(url) do |source|
|
18
|
-
File.open(File.absolute_path(File.basename(url), __dir__), "wb") do |destination|
|
19
|
-
destination.write source.read
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def download_sass_embedded
|
25
|
-
repo = "sass/dart-sass-embedded"
|
26
|
-
|
27
|
-
release = api("https://api.github.com/repos/#{repo}/releases")[0]['tag_name']
|
28
|
-
|
29
|
-
os = case Sass::Platform::OS
|
30
|
-
when "darwin"
|
31
|
-
"macos"
|
32
|
-
when "linux"
|
33
|
-
"linux"
|
34
|
-
when "windows"
|
35
|
-
"windows"
|
36
|
-
else
|
37
|
-
raise "Unsupported OS: #{Sass::Platform::OS}"
|
38
|
-
end
|
39
|
-
|
40
|
-
arch = case Sass::Platform::ARCH
|
41
|
-
when "x86_64"
|
42
|
-
"x64"
|
43
|
-
when "i386"
|
44
|
-
"ia32"
|
45
|
-
else
|
46
|
-
raise "Unsupported Arch: #{Sass::Platform::ARCH}"
|
47
|
-
end
|
48
|
-
|
49
|
-
ext = case os
|
50
|
-
when "windows"
|
51
|
-
"zip"
|
52
|
-
else
|
53
|
-
"tar.gz"
|
54
|
-
end
|
55
|
-
|
56
|
-
url = "https://github.com/#{repo}/releases/download/#{release}/sass_embedded-#{release}-#{os}-#{arch}.#{ext}"
|
57
|
-
|
58
|
-
begin
|
59
|
-
download url
|
60
|
-
rescue
|
61
|
-
raise "Failed to download: #{url}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def download_protoc
|
66
|
-
repo = "protocolbuffers/protobuf"
|
67
|
-
|
68
|
-
tag = URI.open("https://github.com/#{repo}/releases/latest") { |file|
|
69
|
-
File.basename file.base_uri.to_s
|
70
|
-
}
|
71
|
-
|
72
|
-
release = tag[1..-1]
|
73
|
-
|
74
|
-
os = case Sass::Platform::OS
|
75
|
-
when "darwin"
|
76
|
-
"osx"
|
77
|
-
when "linux"
|
78
|
-
"linux"
|
79
|
-
when "windows"
|
80
|
-
"win"
|
81
|
-
else
|
82
|
-
raise "Unsupported OS: #{Sass::Platform::OS}"
|
83
|
-
end
|
84
|
-
|
85
|
-
arch = case Sass::Platform::ARCH
|
86
|
-
when "aarch64"
|
87
|
-
"aarch_64"
|
88
|
-
when "sparcv9"
|
89
|
-
"s390"
|
90
|
-
when "i386"
|
91
|
-
"x86_32"
|
92
|
-
when "x86_64"
|
93
|
-
"x86_64"
|
94
|
-
when "powerpc64"
|
95
|
-
"ppcle_64"
|
96
|
-
else
|
97
|
-
raise "Unsupported Arch: #{Sass::Platform::ARCH}"
|
98
|
-
end
|
99
|
-
|
100
|
-
os_arch = case os
|
101
|
-
when "win"
|
102
|
-
os + arch.split('_').last
|
103
|
-
else
|
104
|
-
os + '-' + arch
|
105
|
-
end
|
106
|
-
|
107
|
-
ext = "zip"
|
108
|
-
|
109
|
-
url = "https://github.com/#{repo}/releases/download/#{tag}/protoc-#{release}-#{os_arch}.#{ext}"
|
110
|
-
|
111
|
-
begin
|
112
|
-
download url
|
113
|
-
rescue
|
114
|
-
raise "Failed to download: #{url}"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def download_embedded_sass_proto
|
119
|
-
url = "https://raw.githubusercontent.com/sass/embedded-protocol/HEAD/embedded_sass.proto"
|
120
|
-
download url
|
121
|
-
end
|
122
|
-
|
123
|
-
system("make", "-C", __dir__, "distclean")
|
124
|
-
download_sass_embedded
|
125
|
-
download_protoc
|
126
|
-
download_embedded_sass_proto
|
127
|
-
system("make", "-C", __dir__, "install")
|
128
|
-
|
129
|
-
File.open(File.absolute_path("sass_embedded.#{RbConfig::CONFIG['DLEXT']}", __dir__), "w") {}
|
130
|
-
|
131
|
-
$makefile_created = true
|
@@ -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
|
-
(options[:include_paths] || []).concat(Sass.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
|