sass-embedded 0.2.1 → 0.4.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.1
4
+ version: 0.4.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-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -108,23 +108,52 @@ 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
158
  - lib/sass/embedded.rb
130
159
  - lib/sass/error.rb
@@ -133,12 +162,16 @@ files:
133
162
  - lib/sass/util.rb
134
163
  - lib/sass/version.rb
135
164
  - sass-embedded.gemspec
136
- - test/compiler_test.rb
137
- - test/custom_importer_test.rb
138
- - test/error_test.rb
165
+ - test/concurrency_test.rb
139
166
  - test/functions_test.rb
140
- - test/output_style_test.rb
141
- - test/sass_test.rb
167
+ - test/importer_test.rb
168
+ - test/include_paths_test.rb
169
+ - test/indented_syntax_test.rb
170
+ - test/input_test.rb
171
+ - test/output_test.rb
172
+ - test/render_error_test.rb
173
+ - test/render_test.rb
174
+ - test/source_maps_test.rb
142
175
  - test/test_helper.rb
143
176
  homepage: https://github.com/ntkme/embedded-host-ruby
144
177
  licenses:
@@ -152,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
185
  requirements:
153
186
  - - ">="
154
187
  - !ruby/object:Gem::Version
155
- version: 2.0.0
188
+ version: '2.6'
156
189
  required_rubygems_version: !ruby/object:Gem::Requirement
157
190
  requirements:
158
191
  - - ">="
@@ -164,10 +197,14 @@ signing_key:
164
197
  specification_version: 4
165
198
  summary: Use dart-sass with Ruby!
166
199
  test_files:
167
- - test/compiler_test.rb
168
- - test/custom_importer_test.rb
169
- - test/error_test.rb
200
+ - test/concurrency_test.rb
170
201
  - test/functions_test.rb
171
- - test/output_style_test.rb
172
- - test/sass_test.rb
202
+ - test/importer_test.rb
203
+ - test/include_paths_test.rb
204
+ - test/indented_syntax_test.rb
205
+ - test/input_test.rb
206
+ - test/output_test.rb
207
+ - test/render_error_test.rb
208
+ - test/render_test.rb
209
+ - test/source_maps_test.rb
173
210
  - test/test_helper.rb
@@ -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