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