sass-embedded 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/sass_test.rb CHANGED
@@ -5,18 +5,14 @@ require_relative 'test_helper'
5
5
  module Sass
6
6
  class SassTest < MiniTest::Test
7
7
  def test_sass_works
8
- assert_equal '', Sass.render({
9
- data: ''
10
- })[:css]
8
+ assert_equal '', ::Sass.render(data: '')[:css]
11
9
 
12
10
  css = <<~CSS.chomp
13
11
  h1 {
14
12
  font-size: 2rem;
15
13
  }
16
14
  CSS
17
- assert_equal css, Sass.render({
18
- data: 'h1 { font-size: 2rem; }'
19
- })[:css]
15
+ assert_equal css, ::Sass.render(data: 'h1 { font-size: 2rem; }')[:css]
20
16
  end
21
17
  end
22
18
  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.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-24 00:00:00.000000000 Z
11
+ date: 2021-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -108,28 +108,57 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: Use dart-sass with Ruby!
112
140
  email:
113
141
  - i@ntk.me
114
142
  executables: []
115
143
  extensions:
116
- - ext/sass_embedded/extconf.rb
144
+ - ext/extconf.rb
117
145
  extra_rdoc_files: []
118
146
  files:
119
147
  - ".github/workflows/build.yml"
120
148
  - ".gitignore"
149
+ - ".rubocop.yml"
121
150
  - Gemfile
122
151
  - LICENSE
123
152
  - README.md
124
153
  - Rakefile
125
- - ext/sass_embedded/.gitignore
126
- - ext/sass_embedded/Makefile
127
- - ext/sass_embedded/extconf.rb
154
+ - ext/.gitignore
155
+ - ext/Makefile
156
+ - ext/extconf.rb
128
157
  - lib/sass.rb
129
- - lib/sass/embedded/compiler.rb
130
- - lib/sass/embedded/transport.rb
158
+ - lib/sass/embedded.rb
131
159
  - lib/sass/error.rb
132
160
  - lib/sass/platform.rb
161
+ - lib/sass/transport.rb
133
162
  - lib/sass/util.rb
134
163
  - lib/sass/version.rb
135
164
  - sass-embedded.gemspec
@@ -152,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
181
  requirements:
153
182
  - - ">="
154
183
  - !ruby/object:Gem::Version
155
- version: 2.0.0
184
+ version: '2.6'
156
185
  required_rubygems_version: !ruby/object:Gem::Requirement
157
186
  requirements:
158
187
  - - ">="
@@ -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,124 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'mkmf'
5
- require 'json'
6
- require 'open-uri'
7
- require_relative '../../lib/sass/platform'
8
-
9
- def api(url)
10
- headers = {}
11
- headers['Authorization'] = "token #{ENV['GITHUB_TOKEN']}" if ENV['GITHUB_TOKEN']
12
- URI.parse(url).open(headers) do |file|
13
- JSON.parse file.read
14
- end
15
- end
16
-
17
- def download(url)
18
- URI.parse(url).open do |source|
19
- File.open(File.absolute_path(File.basename(url), __dir__), 'wb') do |destination|
20
- destination.write source.read
21
- end
22
- end
23
- rescue StandardError
24
- raise "Failed to download: #{url}"
25
- end
26
-
27
- def download_sass_embedded
28
- repo = 'sass/dart-sass-embedded'
29
-
30
- release = api("https://api.github.com/repos/#{repo}/releases")[0]['tag_name']
31
-
32
- os = case Sass::Platform::OS
33
- when 'darwin'
34
- 'macos'
35
- when 'linux'
36
- 'linux'
37
- when 'windows'
38
- 'windows'
39
- else
40
- raise "Unsupported OS: #{Sass::Platform::OS}"
41
- end
42
-
43
- arch = case Sass::Platform::ARCH
44
- when 'x86_64'
45
- 'x64'
46
- when 'i386'
47
- 'ia32'
48
- else
49
- raise "Unsupported Arch: #{Sass::Platform::ARCH}"
50
- end
51
-
52
- ext = case os
53
- when 'windows'
54
- 'zip'
55
- else
56
- 'tar.gz'
57
- end
58
-
59
- url = "https://github.com/#{repo}/releases/download/#{release}/sass_embedded-#{release}-#{os}-#{arch}.#{ext}"
60
- download url
61
- end
62
-
63
- def download_protoc
64
- repo = 'protocolbuffers/protobuf'
65
-
66
- tag = URI.parse("https://github.com/#{repo}/releases/latest").open do |file|
67
- File.basename file.base_uri.to_s
68
- end
69
-
70
- release = tag[1..-1]
71
-
72
- os = case Sass::Platform::OS
73
- when 'darwin'
74
- 'osx'
75
- when 'linux'
76
- 'linux'
77
- when 'windows'
78
- 'win'
79
- else
80
- raise "Unsupported OS: #{Sass::Platform::OS}"
81
- end
82
-
83
- arch = case Sass::Platform::ARCH
84
- when 'aarch64'
85
- 'aarch_64'
86
- when 'sparcv9'
87
- 's390'
88
- when 'i386'
89
- 'x86_32'
90
- when 'x86_64'
91
- 'x86_64'
92
- when 'powerpc64'
93
- 'ppcle_64'
94
- else
95
- raise "Unsupported Arch: #{Sass::Platform::ARCH}"
96
- end
97
-
98
- os_arch = case os
99
- when 'win'
100
- os + arch.split('_').last
101
- else
102
- "#{os}-#{arch}"
103
- end
104
-
105
- ext = 'zip'
106
-
107
- url = "https://github.com/#{repo}/releases/download/#{tag}/protoc-#{release}-#{os_arch}.#{ext}"
108
- download url
109
- end
110
-
111
- def download_embedded_sass_proto
112
- url = 'https://raw.githubusercontent.com/sass/embedded-protocol/HEAD/embedded_sass.proto'
113
- download url
114
- end
115
-
116
- system('make', '-C', __dir__, 'distclean')
117
- download_sass_embedded
118
- download_protoc
119
- download_embedded_sass_proto
120
- system('make', '-C', __dir__, 'install')
121
-
122
- File.open(File.absolute_path("sass_embedded.#{RbConfig::CONFIG['DLEXT']}", __dir__), 'w') {}
123
-
124
- $makefile_created = true
@@ -1,238 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- module Embedded
5
- class Compiler
6
- def initialize
7
- @transport = Transport.new
8
- @id_semaphore = Mutex.new
9
- @id = 0
10
- end
11
-
12
- def render(options)
13
- start = Sass::Util.now
14
-
15
- raise Sass::NotRenderedError, 'Either :data or :file must be set.' if options[:file].nil? && options[:data].nil?
16
-
17
- string = if options[:data]
18
- Sass::EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
19
- source: options[:data],
20
- url: options[:file] ? Sass::Util.file_uri(options[:file]) : 'stdin',
21
- syntax: options[:indented_syntax] == true ? Sass::EmbeddedProtocol::Syntax::INDENTED : Sass::EmbeddedProtocol::Syntax::SCSS
22
- )
23
- end
24
-
25
- path = options[:data] ? nil : options[:file]
26
-
27
- style = case options[:output_style]&.to_sym
28
- when :expanded, nil
29
- Sass::EmbeddedProtocol::OutputStyle::EXPANDED
30
- when :compressed
31
- Sass::EmbeddedProtocol::OutputStyle::COMPRESSED
32
- when :nested, :compact
33
- raise Sass::UnsupportedValue, "#{options[:output_style]} is not a supported :output_style"
34
- else
35
- raise Sass::InvalidStyleError, "#{options[:output_style]} is not a valid :output_style"
36
- end
37
-
38
- source_map = options[:source_map].is_a?(String) || (options[:source_map] == true && !options[:out_file].nil?)
39
-
40
- # 1. Loading a file relative to the file in which the @use or @import appeared.
41
- # 2. Each custom importer.
42
- # 3. Loading a file relative to the current working directory.
43
- # 4. Each load path in includePaths
44
- # 5. Each load path specified in the SASS_PATH environment variable, which should be semicolon-separated on Windows and colon-separated elsewhere.
45
- importers = (if options[:importer]
46
- [
47
- Sass::EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(importer_id: 0)
48
- ]
49
- else
50
- []
51
- end).concat(
52
- (options[:include_paths] || []).concat(Sass.include_paths)
53
- .map do |include_path|
54
- Sass::EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
55
- path: File.absolute_path(include_path)
56
- )
57
- end
58
- )
59
-
60
- signatures = []
61
- functions = {}
62
- options[:functions]&.each do |signature, function|
63
- signatures.push signature
64
- functions[signature.to_s.split('(')[0].chomp] = function
65
- end
66
-
67
- compilation_id = next_id
68
-
69
- compile_request = Sass::EmbeddedProtocol::InboundMessage::CompileRequest.new(
70
- id: compilation_id,
71
- string: string,
72
- path: path,
73
- style: style,
74
- source_map: source_map,
75
- importers: importers,
76
- global_functions: options[:functions] ? signatures : [],
77
- alert_color: true,
78
- alert_ascii: true
79
- )
80
-
81
- response = @transport.send compile_request, compilation_id
82
-
83
- file = options[:file] || 'stdin'
84
- canonicalizations = {}
85
- imports = {}
86
-
87
- loop do
88
- case response
89
- when Sass::EmbeddedProtocol::OutboundMessage::CompileResponse
90
- break
91
- when Sass::EmbeddedProtocol::OutboundMessage::CanonicalizeRequest
92
- url = Sass::Util.file_uri(File.absolute_path(response.url, File.dirname(file)))
93
-
94
- if canonicalizations.key? url
95
- canonicalizations[url].id = response.id
96
- else
97
- resolved = nil
98
- options[:importer].each do |importer|
99
- begin
100
- resolved = importer.call response.url, file
101
- rescue StandardError => e
102
- resolved = e
103
- end
104
- break if resolved
105
- end
106
- if resolved.nil?
107
- canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
108
- id: response.id,
109
- url: url
110
- )
111
- elsif resolved.is_a? StandardError
112
- canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
113
- id: response.id,
114
- error: resolved.message
115
- )
116
- elsif resolved.key? :contents
117
- canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
118
- id: response.id,
119
- url: url
120
- )
121
- imports[url] = Sass::EmbeddedProtocol::InboundMessage::ImportResponse.new(
122
- id: response.id,
123
- success: Sass::EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
124
- contents: resolved[:contents],
125
- syntax: Sass::EmbeddedProtocol::Syntax::SCSS,
126
- source_map_url: nil
127
- )
128
- )
129
- elsif resolved.key? :file
130
- canonicalized_url = Sass::Util.file_uri(resolved[:file])
131
- canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
132
- id: response.id,
133
- url: canonicalized_url
134
- )
135
- imports[canonicalized_url] = Sass::EmbeddedProtocol::InboundMessage::ImportResponse.new(
136
- id: response.id,
137
- success: Sass::EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
138
- contents: File.read(resolved[:file]),
139
- syntax: Sass::EmbeddedProtocol::Syntax::SCSS,
140
- source_map_url: nil
141
- )
142
- )
143
- else
144
- canonicalizations[url] = Sass::EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
145
- id: response.id,
146
- error: "Unexpected value returned from importer: #{resolved}"
147
- )
148
- end
149
- end
150
-
151
- response = @transport.send canonicalizations[url], compilation_id
152
- when Sass::EmbeddedProtocol::OutboundMessage::ImportRequest
153
- url = response.url
154
-
155
- if imports.key? url
156
- imports[url].id = response.id
157
- else
158
- imports[url] = Sass::EmbeddedProtocol::InboundMessage::ImportResponse.new(
159
- id: response.id,
160
- error: "Failed to import: #{url}"
161
- )
162
- end
163
-
164
- response = @transport.send imports[url], compilation_id
165
- when Sass::EmbeddedProtocol::OutboundMessage::FunctionCallRequest
166
- begin
167
- message = Sass::EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
168
- id: response.id,
169
- success: functions[response.name].call(*response.arguments)
170
- )
171
- rescue StandardError => e
172
- message = Sass::EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
173
- id: response.id,
174
- error: e.message
175
- )
176
- end
177
-
178
- response = @transport.send message, compilation_id
179
- when Sass::EmbeddedProtocol::ProtocolError
180
- raise Sass::ProtocolError, response.message
181
- else
182
- raise Sass::ProtocolError, "Unexpected packet received: #{response}"
183
- end
184
- end
185
-
186
- if response.failure
187
- raise Sass::CompilationError.new(
188
- response.failure.message,
189
- response.failure.formatted,
190
- response.failure.span ? response.failure.span.url : nil,
191
- response.failure.span ? response.failure.span.start.line + 1 : nil,
192
- response.failure.span ? response.failure.span.start.column + 1 : nil,
193
- 1
194
- )
195
- end
196
-
197
- finish = Sass::Util.now
198
-
199
- {
200
- css: response.success.css,
201
- map: response.success.source_map,
202
- stats: {
203
- entry: options[:file] || 'data',
204
- start: start,
205
- end: finish,
206
- duration: finish - start
207
- }
208
- }
209
- end
210
-
211
- def close
212
- @transport.close
213
- end
214
-
215
- private
216
-
217
- def info
218
- version_response = @transport.send Sass::EmbeddedProtocol::InboundMessage::VersionRequest.new(
219
- id: next_id
220
- )
221
- {
222
- compiler_version: version_response.compiler_version,
223
- protocol_version: version_response.protocol_version,
224
- implementation_name: version_response.implementation_name,
225
- implementation_version: version_response.implementation_version
226
- }
227
- end
228
-
229
- def next_id
230
- @id_semaphore.synchronize do
231
- @id += 1
232
- @id = 0 if @id == Transport::PROTOCOL_ERROR_ID
233
- @id
234
- end
235
- end
236
- end
237
- end
238
- end