sass-embedded 0.3.0 → 0.6.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.
@@ -3,7 +3,9 @@
3
3
  require_relative 'test_helper'
4
4
 
5
5
  module Sass
6
- class ErrorTest < MiniTest::Test
6
+ class RenderErrorTest < MiniTest::Test
7
+ include TempFileTest
8
+
7
9
  def setup
8
10
  @embedded = Embedded.new
9
11
  end
@@ -12,7 +14,7 @@ module Sass
12
14
  @embedded.close
13
15
  end
14
16
 
15
- def test_first_backtrace_is_sass
17
+ def test_first_backtrace_is_stdin
16
18
  template = <<~SCSS
17
19
  .foo {
18
20
  baz: bang;
@@ -25,5 +27,18 @@ module Sass
25
27
  expected = 'stdin:3:20'
26
28
  assert_equal expected, e.backtrace.first
27
29
  end
30
+
31
+ def test_first_backtrace_is_file
32
+ temp_file('style.scss', <<~SCSS)
33
+ .foo {
34
+ baz: bang;
35
+ padding top: 10px;
36
+ }
37
+ SCSS
38
+
39
+ @embedded.render(file: 'style.scss')
40
+ rescue RenderError => e
41
+ assert e.backtrace.first.end_with? '/style.scss:3:20'
42
+ end
28
43
  end
29
44
  end
@@ -3,8 +3,8 @@
3
3
  require_relative 'test_helper'
4
4
 
5
5
  module Sass
6
- class SassTest < MiniTest::Test
7
- def test_sass_works
6
+ class RenderTest < MiniTest::Test
7
+ def test_sass_render
8
8
  assert_equal '', ::Sass.render(data: '')[:css]
9
9
 
10
10
  css = <<~CSS.chomp
@@ -12,6 +12,7 @@ module Sass
12
12
  font-size: 2rem;
13
13
  }
14
14
  CSS
15
+
15
16
  assert_equal css, ::Sass.render(data: 'h1 { font-size: 2rem; }')[:css]
16
17
  end
17
18
  end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'test_helper'
4
+
5
+ module Sass
6
+ class SourceMapsTest < MiniTest::Test
7
+ include TempFileTest
8
+
9
+ def setup
10
+ @embedded = Embedded.new
11
+ end
12
+
13
+ def teardown
14
+ @embedded.close
15
+ end
16
+
17
+ def test_no_source_map
18
+ scss = <<~SCSS
19
+ $size: 40px;
20
+ h1 {
21
+ font-size: $size;
22
+ }
23
+ SCSS
24
+
25
+ css = <<~CSS.chomp
26
+ h1 {
27
+ font-size: 40px;
28
+ }
29
+ CSS
30
+
31
+ temp_file('style.scss', scss)
32
+
33
+ result = @embedded.render(file: 'style.scss')
34
+ assert_equal css, result[:css]
35
+ assert_nil result[:map]
36
+ end
37
+
38
+ def test_source_map_file_as_string
39
+ scss = <<~SCSS
40
+ $size: 40px;
41
+ h1 {
42
+ font-size: $size;
43
+ }
44
+ SCSS
45
+
46
+ css = <<~CSS.chomp
47
+ h1 {
48
+ font-size: 40px;
49
+ }
50
+ /*# sourceMappingURL=out.map */
51
+ CSS
52
+
53
+ temp_file('style.scss', scss)
54
+
55
+ result = @embedded.render(file: 'style.scss',
56
+ source_map: 'out.map')
57
+ assert_equal css, result[:css]
58
+ JSON.parse(result[:map])
59
+ end
60
+
61
+ def test_source_map_true_without_out_file_has_no_effect
62
+ scss = <<~SCSS
63
+ $size: 40px;
64
+ h1 {
65
+ font-size: $size;
66
+ }
67
+ SCSS
68
+
69
+ css = <<~CSS.chomp
70
+ h1 {
71
+ font-size: 40px;
72
+ }
73
+ CSS
74
+
75
+ temp_file('style.scss', scss)
76
+
77
+ result = @embedded.render(file: 'style.scss',
78
+ source_map: true)
79
+ assert_equal css, result[:css]
80
+ assert_nil result[:map]
81
+ end
82
+
83
+ def test_source_map_true_with_out_file
84
+ scss = <<~SCSS
85
+ $size: 40px;
86
+ h1 {
87
+ font-size: $size;
88
+ }
89
+ SCSS
90
+
91
+ css = <<~CSS.chomp
92
+ h1 {
93
+ font-size: 40px;
94
+ }
95
+ /*# sourceMappingURL=out.css.map */
96
+ CSS
97
+
98
+ temp_file('style.scss', scss)
99
+
100
+ result = @embedded.render(file: 'style.scss',
101
+ source_map: true,
102
+ out_file: 'out.css')
103
+ assert_equal css, result[:css]
104
+ JSON.parse(result[:map])
105
+ end
106
+
107
+ def test_omit_source_map_url
108
+ scss = <<~SCSS
109
+ $size: 40px;
110
+ h1 {
111
+ font-size: $size;
112
+ }
113
+ SCSS
114
+
115
+ css = <<~CSS.chomp
116
+ h1 {
117
+ font-size: 40px;
118
+ }
119
+ CSS
120
+
121
+ temp_file('style.scss', scss)
122
+
123
+ result = @embedded.render(file: 'style.scss',
124
+ source_map: 'out.map',
125
+ omit_source_map_url: true)
126
+ assert_equal css, result[:css]
127
+ JSON.parse(result[:map])
128
+ end
129
+
130
+ def test_source_map_embedded
131
+ scss = <<~SCSS
132
+ $size: 40px;
133
+ h1 {
134
+ font-size: $size;
135
+ }
136
+ SCSS
137
+
138
+ css = <<~CSS.chomp
139
+ h1 {
140
+ font-size: 40px;
141
+ }
142
+ /*# sourceMappingURL=data:application/json;base64,
143
+ CSS
144
+
145
+ temp_file('style.scss', scss)
146
+
147
+ result = @embedded.render(file: 'style.scss',
148
+ source_map: 'out.map',
149
+ source_map_embed: true)
150
+ assert result[:css].start_with? css
151
+ JSON.parse(result[:map])
152
+ end
153
+
154
+ def test_source_map_root
155
+ scss = <<~SCSS
156
+ $size: 40px;
157
+ h1 {
158
+ font-size: $size;
159
+ }
160
+ SCSS
161
+
162
+ css = <<~CSS.chomp
163
+ h1 {
164
+ font-size: 40px;
165
+ }
166
+ /*# sourceMappingURL=out.map */
167
+ CSS
168
+
169
+ temp_file('style.scss', scss)
170
+
171
+ result = @embedded.render(file: 'style.scss',
172
+ source_map: 'out.map',
173
+ source_map_root: 'assets')
174
+ assert_equal css, result[:css]
175
+ assert_equal 'assets', JSON.parse(result[:map])['sourceRoot']
176
+ end
177
+ end
178
+ end
data/test/test_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'fileutils'
4
5
  require 'minitest/autorun'
5
6
  require 'minitest/pride'
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.3.0
4
+ version: 0.6.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-26 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -157,17 +157,26 @@ files:
157
157
  - lib/sass.rb
158
158
  - lib/sass/embedded.rb
159
159
  - lib/sass/error.rb
160
+ - lib/sass/info.rb
161
+ - lib/sass/observer.rb
160
162
  - lib/sass/platform.rb
163
+ - lib/sass/render.rb
164
+ - lib/sass/result.rb
165
+ - lib/sass/struct.rb
161
166
  - lib/sass/transport.rb
162
167
  - lib/sass/util.rb
163
168
  - lib/sass/version.rb
164
169
  - sass-embedded.gemspec
165
- - test/compiler_test.rb
166
- - test/custom_importer_test.rb
167
- - test/error_test.rb
170
+ - test/concurrency_test.rb
168
171
  - test/functions_test.rb
169
- - test/output_style_test.rb
170
- - test/sass_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
171
180
  - test/test_helper.rb
172
181
  homepage: https://github.com/ntkme/embedded-host-ruby
173
182
  licenses:
@@ -181,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
190
  requirements:
182
191
  - - ">="
183
192
  - !ruby/object:Gem::Version
184
- version: '2.6'
193
+ version: 2.6.0
185
194
  required_rubygems_version: !ruby/object:Gem::Requirement
186
195
  requirements:
187
196
  - - ">="
@@ -193,10 +202,14 @@ signing_key:
193
202
  specification_version: 4
194
203
  summary: Use dart-sass with Ruby!
195
204
  test_files:
196
- - test/compiler_test.rb
197
- - test/custom_importer_test.rb
198
- - test/error_test.rb
205
+ - test/concurrency_test.rb
199
206
  - test/functions_test.rb
200
- - test/output_style_test.rb
201
- - test/sass_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
202
215
  - test/test_helper.rb
@@ -1,262 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- module Sass
6
- class EmbeddedTest < MiniTest::Test
7
- include TempFileTest
8
-
9
- def setup
10
- @embedded = Embedded.new
11
- end
12
-
13
- def teardown
14
- @embedded.close
15
- end
16
-
17
- def render(data)
18
- @embedded.render(data: data)[:css]
19
- end
20
-
21
- def test_line_comments
22
- skip 'not supported'
23
-
24
- template = <<~SCSS
25
- .foo {
26
- baz: bang; }
27
- SCSS
28
- expected_output = <<~CSS
29
- /* line 1, stdin */
30
- .foo {
31
- baz: bang;
32
- }
33
- CSS
34
- output = @embedded.render(data: template,
35
- source_comments: true)
36
- assert_equal expected_output, output[:css]
37
- end
38
-
39
- def test_one_line_comments
40
- assert_equal <<~CSS.chomp, render(<<~SCSS)
41
- .foo {
42
- baz: bang;
43
- }
44
- CSS
45
- .foo {// bar: baz;}
46
- baz: bang; //}
47
- }
48
- SCSS
49
- assert_equal <<~CSS.chomp, render(<<~SCSS)
50
- .foo bar[val="//"] {
51
- baz: bang;
52
- }
53
- CSS
54
- .foo bar[val="//"] {
55
- baz: bang; //}
56
- }
57
- SCSS
58
- end
59
-
60
- def test_variables
61
- assert_equal <<~CSS.chomp, render(<<~SCSS)
62
- blat {
63
- a: foo;
64
- }
65
- CSS
66
- $var: foo;
67
- #{' '}
68
- blat {a: $var}
69
- SCSS
70
-
71
- assert_equal <<~CSS.chomp, render(<<~SCSS)
72
- foo {
73
- a: 2;
74
- b: 6;
75
- }
76
- CSS
77
- foo {
78
- $var: 2;
79
- $another-var: 4;
80
- a: $var;
81
- b: $var + $another-var;}
82
- SCSS
83
- end
84
-
85
- def test_precision
86
- skip 'not supported'
87
-
88
- template = <<~SCSS
89
- $var: 1;
90
- .foo {
91
- baz: $var / 3; }
92
- SCSS
93
- expected_output = <<~CSS.chomp
94
- .foo {
95
- baz: 0.33333333;
96
- }
97
- CSS
98
- output = @embedded.render(data: template,
99
- precision: 8)
100
- assert_equal expected_output, output
101
- end
102
-
103
- def test_precision_not_specified
104
- template = <<~SCSS
105
- $var: 1;
106
- .foo {
107
- baz: $var / 3; }
108
- SCSS
109
- expected_output = <<~CSS.chomp
110
- .foo {
111
- baz: 0.3333333333;
112
- }
113
- CSS
114
- output = render(template)
115
- assert_equal expected_output, output
116
- end
117
-
118
- def test_source_map
119
- temp_dir('admin')
120
-
121
- temp_file('admin/text-color.scss', <<~SCSS)
122
- p {
123
- color: red;
124
- }
125
- SCSS
126
- temp_file('style.scss', <<~SCSS)
127
- @use 'admin/text-color';
128
- #{' '}
129
- p {
130
- padding: 20px;
131
- }
132
- SCSS
133
- output = @embedded.render(data: File.read('style.scss'),
134
- source_map: 'style.scss.map')
135
-
136
- assert output[:map].start_with? '{"version":3,'
137
- end
138
-
139
- def test_no_source_map
140
- output = @embedded.render(data: '$size: 30px;')
141
- assert_equal '', output[:map]
142
- end
143
-
144
- def test_include_paths
145
- temp_dir('included_1')
146
- temp_dir('included_2')
147
-
148
- temp_file('included_1/import_parent.scss', '$s: 30px;')
149
- temp_file('included_2/import.scss', "@use 'import_parent' as *; $size: $s;")
150
- temp_file('styles.scss', "@use 'import.scss' as *; .hi { width: $size; }")
151
-
152
- assert_equal ".hi {\n width: 30px;\n}", @embedded.render(data: File.read('styles.scss'),
153
- include_paths: %w[
154
- included_1 included_2
155
- ])[:css]
156
- end
157
-
158
- def test_global_include_paths
159
- temp_dir('included_1')
160
- temp_dir('included_2')
161
-
162
- temp_file('included_1/import_parent.scss', '$s: 30px;')
163
- temp_file('included_2/import.scss', "@use 'import_parent' as *; $size: $s;")
164
- temp_file('styles.scss', "@use 'import.scss' as *; .hi { width: $size; }")
165
-
166
- ::Sass.include_paths << 'included_1'
167
- ::Sass.include_paths << 'included_2'
168
-
169
- assert_equal ".hi {\n width: 30px;\n}", render(File.read('styles.scss'))
170
- end
171
-
172
- def test_env_include_paths
173
- expected_include_paths = %w[included_3 included_4]
174
-
175
- ::Sass.instance_eval { @include_paths = nil }
176
-
177
- ENV['SASS_PATH'] = expected_include_paths.join(File::PATH_SEPARATOR)
178
-
179
- assert_equal expected_include_paths, ::Sass.include_paths
180
-
181
- ::Sass.include_paths.clear
182
- end
183
-
184
- def test_include_paths_not_configured
185
- temp_dir('included_5')
186
- temp_dir('included_6')
187
- temp_file('included_5/import_parent.scss', '$s: 30px;')
188
- temp_file('included_6/import.scss', "@use 'import_parent' as *; $size: $s;")
189
- temp_file('styles.scss', "@use 'import.scss' as *; .hi { width: $size; }")
190
-
191
- assert_raises(RenderError) do
192
- render(File.read('styles.scss'))
193
- end
194
- end
195
-
196
- def test_sass_variation
197
- sass = <<~SASS
198
- $size: 30px
199
- .foo
200
- width: $size
201
- SASS
202
-
203
- css = <<~CSS.chomp
204
- .foo {
205
- width: 30px;
206
- }
207
- CSS
208
-
209
- assert_equal css, @embedded.render(data: sass, indented_syntax: true)[:css]
210
- assert_raises(RenderError) do
211
- @embedded.render(data: sass, indented_syntax: false)
212
- end
213
- end
214
-
215
- def test_inline_source_maps
216
- skip 'not supported'
217
-
218
- template = <<~SCSS
219
- .foo {
220
- baz: bang; }
221
- SCSS
222
-
223
- output = @embedded.render(data: template,
224
- source_map: '.',
225
- source_map_embed: true,
226
- source_map_contents: true)[:css]
227
-
228
- assert_match(/sourceMappingURL/, output)
229
- assert_match(/.foo/, output)
230
- end
231
-
232
- def test_empty_template
233
- output = render('')
234
- assert_equal '', output
235
- end
236
-
237
- def test_import_plain_css
238
- temp_file('test.css', '.something{color: red}')
239
- expected_output = <<~CSS.chomp
240
- .something {
241
- color: red;
242
- }
243
- CSS
244
-
245
- output = render("@use 'test';")
246
- assert_equal expected_output, output
247
- end
248
-
249
- def test_concurrency
250
- 10.times do
251
- threads = []
252
- 10.times do |i|
253
- threads << Thread.new(i) do |id|
254
- output = @embedded.render(data: "div { width: #{id} }")[:css]
255
- assert_match(/#{id}/, output)
256
- end
257
- end
258
- threads.each(&:join)
259
- end
260
- end
261
- end
262
- end