sass-embedded 0.6.7 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b1b7d4e1bdfae2dbb2f99b43c42c0e06673a5f4f8c92b213efdfa4535a56b5b
4
- data.tar.gz: 23fe4aeaeab07ddf717e7f2fad75d3fc9d9c82db4f4606763e52df8450113f59
3
+ metadata.gz: 8a920bc1fd2f9767c87dcc604c8ad44266b285310a7b0e9e46cf65c7a610ba4d
4
+ data.tar.gz: 8041922c104b94fb0bc4634735444315692a0d9a37a50db3cf213a9914455bb0
5
5
  SHA512:
6
- metadata.gz: 13f8c565606af71bad343b5863ca3c792897d9a7bfea0071f17c510d99b6f0bf4d995441433572ba6aab2ca7489b9202c70fee3db4fc1c63fd15a5d4a5e8f593
7
- data.tar.gz: a9bcd6caf920377fd86aa94f1ef536582f41483e0b0fca252718995af25037162eb2e77ee61cf6fc8d761195c10da48ebbf6dcb48de0c723cf0d01d46de0c1c6
6
+ metadata.gz: 180d0212926afd166fafc991cf30e8af33adc843171ec69d53a4b42ad7d587857e77a224cf8c25f343af7bacd6b76eeb5f2b93fd7c9886d2fd83105de3d891cc
7
+ data.tar.gz: 3d91c28089e6157b815a63cdc5b93d8adc2bb81f56828d6e3554c633ed31d845c070361797f32b45ae3bfbc39e034866a2c8e17f80a2222b5c827f9a2669a985
data/README.md CHANGED
@@ -22,7 +22,7 @@ Sass.render(file: "style.scss")
22
22
 
23
23
  ## Options
24
24
 
25
- `Sass.render()` support the following options:
25
+ `Sass.render(**kwargs)` supports the following options:
26
26
 
27
27
  - [`data`](https://sass-lang.com/documentation/js-api#data)
28
28
  - [`file`](https://sass-lang.com/documentation/js-api#file)
@@ -35,6 +35,7 @@ Sass.render(file: "style.scss")
35
35
  - [`source_map`](https://sass-lang.com/documentation/js-api#sourcemap)
36
36
  - [`out_file`](https://sass-lang.com/documentation/js-api#outfile)
37
37
  - [`omit_source_map_url`](https://sass-lang.com/documentation/js-api#omitsourcemapurl)
38
+ - [`source_map_contents`](https://sass-lang.com/documentation/js-api#sourcemapcontents)
38
39
  - [`source_map_embed`](https://sass-lang.com/documentation/js-api#sourcemapembed)
39
40
  - [`source_map_root`](https://sass-lang.com/documentation/js-api#sourcemaproot)
40
41
  - [`functions`](https://sass-lang.com/documentation/js-api#functions)
data/lib/sass.rb CHANGED
@@ -60,6 +60,7 @@ module Sass
60
60
  end
61
61
  end
62
62
 
63
+ require_relative 'sass/version'
63
64
  require_relative 'sass/platform'
64
65
  require_relative 'sass/util'
65
66
  require_relative 'sass/struct'
@@ -67,6 +68,6 @@ require_relative 'sass/result'
67
68
  require_relative 'sass/error'
68
69
  require_relative 'sass/transport'
69
70
  require_relative 'sass/observer'
70
- require_relative 'sass/version'
71
+ require_relative 'sass/info'
71
72
  require_relative 'sass/render'
72
73
  require_relative 'sass/embedded'
data/lib/sass/embedded.rb CHANGED
@@ -49,8 +49,6 @@ module Sass
49
49
  source_map_root: '',
50
50
  functions: {},
51
51
  importer: [])
52
- raise NotImplementedError, 'source_map_contents is not implemented' unless source_map_contents == false
53
-
54
52
  start = Util.now
55
53
 
56
54
  indent_type = parse_indent_type(indent_type)
@@ -77,7 +75,7 @@ module Sass
77
75
  elsif message.failure.span.url == ''
78
76
  'stdin'
79
77
  else
80
- Util.path(message.failure.span.url)
78
+ Util.path_from_file_uri(message.failure.span.url)
81
79
  end,
82
80
  message.failure.span ? message.failure.span.start.line + 1 : nil,
83
81
  message.failure.span ? message.failure.span.start.column + 1 : nil,
@@ -89,6 +87,7 @@ module Sass
89
87
  file: file,
90
88
  out_file: out_file,
91
89
  source_map: source_map,
90
+ source_map_contents: source_map_contents,
92
91
  source_map_root: source_map_root)
93
92
 
94
93
  css = post_process_css(css: message.success.css,
@@ -103,7 +102,7 @@ module Sass
103
102
 
104
103
  finish = Util.now
105
104
 
106
- stats = RenderResult::Stats.new(file.nil? ? 'data' : file, start, finish, finish - start)
105
+ stats = RenderResultStats.new(file.nil? ? 'data' : file, start, finish, finish - start)
107
106
 
108
107
  RenderResult.new(css, map, stats)
109
108
  end
@@ -122,6 +121,7 @@ module Sass
122
121
  file:,
123
122
  out_file:,
124
123
  source_map:,
124
+ source_map_contents:,
125
125
  source_map_root:)
126
126
  return if map.nil? || map.empty?
127
127
 
@@ -138,7 +138,7 @@ module Sass
138
138
  source_map_dir = File.dirname(source_map_path)
139
139
 
140
140
  if out_file
141
- map_data['file'] = Util.relative(source_map_dir, out_file)
141
+ map_data['file'] = Util.relative_path(source_map_dir, out_file)
142
142
  elsif file
143
143
  ext = File.extname(file)
144
144
  map_data['file'] = "#{file[0..(ext.empty? ? -1 : -ext.length - 1)]}.css"
@@ -146,10 +146,15 @@ module Sass
146
146
  map_data['file'] = 'stdin.css'
147
147
  end
148
148
 
149
+ map_data['sourcesContent'] = [] if source_map_contents
150
+
149
151
  map_data['sources'].map! do |source|
150
- if source.start_with? Util::FILE_PROTOCOL
151
- Util.relative(source_map_dir, Util.path(source))
152
+ if source.start_with? 'file://'
153
+ path = Util.path_from_file_uri(source)
154
+ map_data['sourcesContent'].push(File.read(path)) if source_map_contents
155
+ Util.relative_path(source_map_dir, path)
152
156
  else
157
+ map_data['sourcesContent'].push(nil) if source_map_contents
153
158
  source
154
159
  end
155
160
  end
@@ -179,7 +184,7 @@ module Sass
179
184
  url = if source_map_embed
180
185
  "data:application/json;base64,#{Base64.strict_encode64(map)}"
181
186
  elsif out_file
182
- Util.relative(File.dirname(out_file), source_map)
187
+ Util.relative_path(File.dirname(out_file), source_map)
183
188
  else
184
189
  source_map
185
190
  end
data/lib/sass/render.rb CHANGED
@@ -97,7 +97,7 @@ module Sass
97
97
  end
98
98
 
99
99
  def canonicalize_response(canonicalize_request)
100
- url = Util.file_uri(File.absolute_path(canonicalize_request.url, (@file.nil? ? 'stdin' : @file)))
100
+ url = Util.file_uri_from_path(File.absolute_path(canonicalize_request.url, (@file.nil? ? 'stdin' : @file)))
101
101
 
102
102
  begin
103
103
  result = @importer[canonicalize_request.importer_id].call canonicalize_request.url, @file
@@ -123,7 +123,7 @@ module Sass
123
123
  url: url
124
124
  )
125
125
  elsif result&.key? :file
126
- canonicalized_url = Util.file_uri(result[:file])
126
+ canonicalized_url = Util.file_uri_from_path(result[:file])
127
127
 
128
128
  # TODO: FileImportRequest is not supported yet.
129
129
  # Workaround by reading contents and return it when server asks
@@ -185,7 +185,7 @@ module Sass
185
185
  def url
186
186
  return if @file.nil?
187
187
 
188
- Util.file_uri @file
188
+ Util.file_uri_from_path @file
189
189
  end
190
190
 
191
191
  def string
data/lib/sass/result.rb CHANGED
@@ -12,19 +12,19 @@ module Sass
12
12
  @map = map
13
13
  @stats = stats
14
14
  end
15
+ end
15
16
 
16
- # The {Stats} of {Embedded#render}.
17
- class Stats
18
- include Struct
17
+ # The {RenderResultStats} of {Embedded#render}.
18
+ class RenderResultStats
19
+ include Struct
19
20
 
20
- attr_reader :entry, :start, :end, :duration
21
+ attr_reader :entry, :start, :end, :duration
21
22
 
22
- def initialize(entry, start, finish, duration)
23
- @entry = entry
24
- @start = start
25
- @end = finish
26
- @duration = duration
27
- end
23
+ def initialize(entry, start, finish, duration)
24
+ @entry = entry
25
+ @start = start
26
+ @end = finish
27
+ @duration = duration
28
28
  end
29
29
  end
30
30
  end
@@ -29,7 +29,7 @@ module Sass
29
29
  @stdin_mutex = Mutex.new
30
30
  @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(DART_SASS_EMBEDDED)
31
31
  pipe @stderr, $stderr
32
- receive_message @stdout
32
+ read @stdout
33
33
  end
34
34
 
35
35
  def add_observer(*args)
@@ -58,42 +58,38 @@ module Sass
58
58
 
59
59
  private
60
60
 
61
- def receive_message(readable)
61
+ def receive_message(error, message)
62
+ @observerable_mutex.synchronize do
63
+ changed
64
+ notify_observers error, message
65
+ end
66
+ end
67
+
68
+ def pipe(readable, writeable)
62
69
  Thread.new do
63
70
  loop do
64
- bits = length = 0
65
- loop do
66
- byte = readable.readbyte
67
- length += (byte & 0x7f) << bits
68
- bits += 7
69
- break if byte <= 0x7f
70
- end
71
- payload = readable.read length
72
- message = EmbeddedProtocol::OutboundMessage.decode payload
73
- @observerable_mutex.synchronize do
74
- changed
75
- notify_observers nil, message[message.message.to_s]
76
- end
71
+ writeable.write readable.readline
77
72
  rescue Interrupt
78
73
  break
79
74
  rescue IOError => e
80
- notify_observers e, nil
75
+ receive_message(e, nil)
81
76
  close
82
77
  break
83
78
  end
84
79
  end
85
80
  end
86
81
 
87
- def pipe(readable, writeable)
82
+ def read(readable)
88
83
  Thread.new do
89
84
  loop do
90
- writeable.write readable.readline
85
+ length = read_varint(readable)
86
+ payload = readable.read(length)
87
+ message = EmbeddedProtocol::OutboundMessage.decode payload
88
+ receive_message(nil, message[message.message.to_s])
91
89
  rescue Interrupt
92
90
  break
93
91
  rescue IOError => e
94
- @observerable_mutex.synchronize do
95
- notify_observers e, nil
96
- end
92
+ receive_message(e, nil)
97
93
  close
98
94
  break
99
95
  end
@@ -102,13 +98,27 @@ module Sass
102
98
 
103
99
  def write(payload)
104
100
  @stdin_mutex.synchronize do
105
- length = payload.length
106
- while length.positive?
107
- @stdin.write ((length > 0x7f ? 0x80 : 0) | (length & 0x7f)).chr
108
- length >>= 7
109
- end
101
+ write_varint(@stdin, payload.length)
110
102
  @stdin.write payload
111
103
  end
112
104
  end
105
+
106
+ def read_varint(readable)
107
+ varint = bits = 0
108
+ loop do
109
+ byte = readable.readbyte
110
+ varint += (byte & 0x7f) << bits
111
+ bits += 7
112
+ break if byte <= 0x7f
113
+ end
114
+ varint
115
+ end
116
+
117
+ def write_varint(writeable, varint)
118
+ while varint.positive?
119
+ writeable.write ((varint > 0x7f ? 0x80 : 0) | (varint & 0x7f)).chr
120
+ varint >>= 7
121
+ end
122
+ end
113
123
  end
114
124
  end
data/lib/sass/util.rb CHANGED
@@ -1,39 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
+ require 'uri'
4
5
 
5
6
  module Sass
6
7
  # The {Util} module.
7
8
  module Util
8
9
  module_function
9
10
 
10
- FILE_PROTOCOL = 'file://'
11
+ URI_PARSER = URI::Parser.new({ RESERVED: ';/?:@&=+$,' })
11
12
 
12
- def file_uri(path)
13
+ def file_uri_from_path(path)
13
14
  absolute_path = File.absolute_path(path)
14
15
 
15
- unless absolute_path.start_with? File::SEPARATOR
16
- components = absolute_path.split File::SEPARATOR
17
- components[0] = components[0][0].downcase
18
- absolute_path = components.join File::SEPARATOR
19
- end
16
+ absolute_path = File::SEPARATOR + absolute_path unless absolute_path.start_with? File::SEPARATOR
20
17
 
21
- "#{FILE_PROTOCOL}#{absolute_path}"
18
+ URI_PARSER.escape("file://#{absolute_path}")
22
19
  end
23
20
 
24
- def path(file_uri)
25
- absolute_path = file_uri[FILE_PROTOCOL.length..]
26
-
27
- unless absolute_path.start_with? File::SEPARATOR
28
- components = absolute_path.split File::SEPARATOR
29
- components[0] = "#{components[0].upcase}:"
30
- absolute_path = components.join File::SEPARATOR
31
- end
32
-
33
- absolute_path
21
+ def path_from_file_uri(file_uri)
22
+ URI_PARSER.unescape(file_uri)[7..]
34
23
  end
35
24
 
36
- def relative(from, to)
25
+ def relative_path(from, to)
37
26
  Pathname.new(File.absolute_path(to)).relative_path_from(Pathname.new(File.absolute_path(from))).to_s
38
27
  end
39
28
 
data/lib/sass/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sass
4
- VERSION = '0.6.7'
4
+ VERSION = '0.7.4'
5
5
  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.6.7
4
+ version: 0.7.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-29 00:00:00.000000000 Z
11
+ date: 2021-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -136,7 +136,8 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: Use dart-sass with Ruby!
139
+ description: A Ruby library that will communicate with Embedded Dart Sass using the
140
+ Embedded Sass protocol.
140
141
  email:
141
142
  - i@ntk.me
142
143
  executables: []
@@ -144,14 +145,8 @@ extensions:
144
145
  - ext/extconf.rb
145
146
  extra_rdoc_files: []
146
147
  files:
147
- - ".github/workflows/build.yml"
148
- - ".gitignore"
149
- - ".rubocop.yml"
150
- - Gemfile
151
148
  - LICENSE
152
149
  - README.md
153
- - Rakefile
154
- - ext/.gitignore
155
150
  - ext/Makefile
156
151
  - ext/extconf.rb
157
152
  - lib/sass.rb
@@ -166,22 +161,11 @@ files:
166
161
  - lib/sass/transport.rb
167
162
  - lib/sass/util.rb
168
163
  - lib/sass/version.rb
169
- - sass-embedded.gemspec
170
- - test/concurrency_test.rb
171
- - test/functions_test.rb
172
- - test/importer_test.rb
173
- - test/include_paths_test.rb
174
- - test/indented_syntax_test.rb
175
- - test/input_test.rb
176
- - test/output_test.rb
177
- - test/render_error_test.rb
178
- - test/render_test.rb
179
- - test/source_maps_test.rb
180
- - test/test_helper.rb
181
164
  homepage: https://github.com/ntkme/sass-embedded-host-ruby
182
165
  licenses:
183
166
  - MIT
184
- metadata: {}
167
+ metadata:
168
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v0.7.4
185
169
  post_install_message:
186
170
  rdoc_options: []
187
171
  require_paths:
@@ -201,15 +185,4 @@ rubygems_version: 3.2.15
201
185
  signing_key:
202
186
  specification_version: 4
203
187
  summary: Use dart-sass with Ruby!
204
- test_files:
205
- - test/concurrency_test.rb
206
- - test/functions_test.rb
207
- - test/importer_test.rb
208
- - test/include_paths_test.rb
209
- - test/indented_syntax_test.rb
210
- - test/input_test.rb
211
- - test/output_test.rb
212
- - test/render_error_test.rb
213
- - test/render_test.rb
214
- - test/source_maps_test.rb
215
- - test/test_helper.rb
188
+ test_files: []
@@ -1,44 +0,0 @@
1
- name: build
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
- pull_request:
7
- branches: [ main ]
8
-
9
- jobs:
10
- build:
11
-
12
- runs-on: ${{ matrix.os }}
13
-
14
- strategy:
15
- matrix:
16
- os: [macos-latest, ubuntu-latest, windows-latest]
17
- ruby-version: ['2.6', '2.7', '3.0']
18
-
19
- steps:
20
- - name: Checkout
21
- uses: actions/checkout@v2
22
-
23
- - name: Set up Ruby
24
- uses: ruby/setup-ruby@v1
25
- with:
26
- ruby-version: ${{ matrix.ruby-version }}
27
- bundler-cache: true
28
-
29
- - name: Download dart-sass-embedded
30
- run: bundle exec rake extconf
31
- env:
32
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33
-
34
- - name: Test
35
- run: bundle exec rake
36
-
37
- - name: Install Gem
38
- run: rake install
39
- env:
40
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41
-
42
- - name: Test Gem
43
- run: |-
44
- ruby -r sass -e "puts Sass.render(data: 'h1 { color: black; }')[:css]"