sass-embedded 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,155 +13,153 @@ module Sass
13
13
  end
14
14
 
15
15
  def render(sass)
16
- @embedded.render({
17
- data: sass,
18
- functions: {
19
- 'javascript_path($path)': lambda { |path|
20
- path.string.text = "/js/#{path.string.text}"
21
- path
22
- },
23
- 'stylesheet_path($path)': lambda { |path|
24
- path.string.text = "/css/#{path.string.text}"
25
- path
26
- },
27
- 'sass_return_path($path)': lambda { |path|
28
- path
29
- },
30
- 'no_return_path($path)': lambda { |_path|
31
- Sass::EmbeddedProtocol::Value.new(
32
- singleton: Sass::EmbeddedProtocol::SingletonValue::NULL
33
- )
16
+ @embedded.render(data: sass,
17
+ functions: {
18
+ 'javascript_path($path)': lambda { |path|
19
+ path.string.text = "/js/#{path.string.text}"
20
+ path
21
+ },
22
+ 'stylesheet_path($path)': lambda { |path|
23
+ path.string.text = "/css/#{path.string.text}"
24
+ path
25
+ },
26
+ 'sass_return_path($path)': lambda { |path|
27
+ path
34
28
  },
35
- 'optional_arguments($path, $optional: null)': lambda { |path, optional|
36
- Sass::EmbeddedProtocol::Value.new(
37
- string: Sass::EmbeddedProtocol::Value::String.new(
38
- text: "#{path.string.text}/#{optional.singleton == :NULL ? 'bar' : optional.string.text}",
39
- quoted: true
40
- )
29
+ 'no_return_path($path)': lambda { |_path|
30
+ EmbeddedProtocol::Value.new(
31
+ singleton: EmbeddedProtocol::SingletonValue::NULL
32
+ )
33
+ },
34
+ 'optional_arguments($path, $optional: null)': lambda { |path, optional|
35
+ EmbeddedProtocol::Value.new(
36
+ string: EmbeddedProtocol::Value::String.new(
37
+ text: "#{path.string.text}/#{optional.singleton == :NULL ? 'bar' : optional.string.text}",
38
+ quoted: true
41
39
  )
42
- },
43
- 'function_that_raises_errors()': lambda {
44
- raise StandardError,
45
- 'Intentional wrong thing happened somewhere inside the custom function'
46
- },
47
- 'nice_color_argument($color)': lambda { |color|
48
- color
40
+ )
41
+ },
42
+ 'function_that_raises_errors()': lambda {
43
+ raise StandardError,
44
+ 'Intentional wrong thing happened somewhere inside the custom function'
49
45
  },
50
- 'returns_a_color()': lambda {
51
- Sass::EmbeddedProtocol::Value.new(
52
- rgb_color: Sass::EmbeddedProtocol::Value::RgbColor.new(
53
- red: 0,
54
- green: 0,
55
- blue: 0,
56
- alpha: 1
57
- )
46
+ 'nice_color_argument($color)': lambda { |color|
47
+ color
48
+ },
49
+ 'returns_a_color()': lambda {
50
+ EmbeddedProtocol::Value.new(
51
+ rgb_color: EmbeddedProtocol::Value::RgbColor.new(
52
+ red: 0,
53
+ green: 0,
54
+ blue: 0,
55
+ alpha: 1
58
56
  )
59
- },
60
- 'returns_a_number()': lambda {
61
- Sass::EmbeddedProtocol::Value.new(
62
- number: Sass::EmbeddedProtocol::Value::Number.new(
63
- value: -312,
64
- numerators: ['rem']
65
- )
57
+ )
58
+ },
59
+ 'returns_a_number()': lambda {
60
+ EmbeddedProtocol::Value.new(
61
+ number: EmbeddedProtocol::Value::Number.new(
62
+ value: -312,
63
+ numerators: ['rem']
66
64
  )
67
- },
68
- 'returns_a_bool()': lambda {
69
- Sass::EmbeddedProtocol::Value.new(
70
- singleton: Sass::EmbeddedProtocol::SingletonValue::TRUE
71
65
  )
72
66
  },
73
- 'inspect_bool($argument)': lambda { |argument|
74
- unless argument&.singleton == :TRUE || argument.singleton == :FALSE
67
+ 'returns_a_bool()': lambda {
68
+ EmbeddedProtocol::Value.new(
69
+ singleton: EmbeddedProtocol::SingletonValue::TRUE
70
+ )
71
+ },
72
+ 'inspect_bool($argument)': lambda { |argument|
73
+ unless argument&.singleton == :TRUE || argument.singleton == :FALSE
74
+ raise StandardError,
75
+ 'passed value is not a EmbeddedProtocol::SingletonValue::TRUE or EmbeddedProtocol::SingletonValue::FALSE'
76
+ end
77
+
78
+ argument
79
+ },
80
+ 'inspect_number($argument)': lambda { |argument|
81
+ unless argument&.number.is_a? EmbeddedProtocol::Value::Number
75
82
  raise StandardError,
76
- 'passed value is not a Sass::EmbeddedProtocol::SingletonValue::TRUE or Sass::EmbeddedProtocol::SingletonValue::FALSE'
83
+ 'passed value is not a EmbeddedProtocol::Value::Number'
77
84
  end
78
85
 
79
86
  argument
80
87
  },
81
- 'inspect_number($argument)': lambda { |argument|
82
- unless argument&.number.is_a? Sass::EmbeddedProtocol::Value::Number
83
- raise StandardError,
84
- 'passed value is not a Sass::EmbeddedProtocol::Value::Number'
85
- end
86
-
87
- argument
88
- },
89
- 'inspect_map($argument)': lambda { |argument|
90
- unless argument&.map.is_a? Sass::EmbeddedProtocol::Value::Map
91
- raise StandardError,
92
- 'passed value is not a Sass::EmbeddedProtocol::Value::Map'
93
- end
88
+ 'inspect_map($argument)': lambda { |argument|
89
+ unless argument&.map.is_a? EmbeddedProtocol::Value::Map
90
+ raise StandardError,
91
+ 'passed value is not a EmbeddedProtocol::Value::Map'
92
+ end
94
93
 
95
- argument
96
- },
97
- 'inspect_list($argument)': lambda { |argument|
98
- unless argument&.list.is_a? Sass::EmbeddedProtocol::Value::List
99
- raise StandardError,
100
- 'passed value is not a Sass::EmbeddedProtocol::Value::List'
101
- end
94
+ argument
95
+ },
96
+ 'inspect_list($argument)': lambda { |argument|
97
+ unless argument&.list.is_a? EmbeddedProtocol::Value::List
98
+ raise StandardError,
99
+ 'passed value is not a EmbeddedProtocol::Value::List'
100
+ end
102
101
 
103
- argument
104
- },
105
- 'returns_sass_value()': lambda {
106
- Sass::EmbeddedProtocol::Value.new(
107
- rgb_color: Sass::EmbeddedProtocol::Value::RgbColor.new(
108
- red: 0,
109
- green: 0,
110
- blue: 0,
111
- alpha: 1
112
- )
102
+ argument
103
+ },
104
+ 'returns_sass_value()': lambda {
105
+ EmbeddedProtocol::Value.new(
106
+ rgb_color: EmbeddedProtocol::Value::RgbColor.new(
107
+ red: 0,
108
+ green: 0,
109
+ blue: 0,
110
+ alpha: 1
113
111
  )
114
- },
115
- 'returns_sass_map()': lambda {
116
- Sass::EmbeddedProtocol::Value.new(
117
- map: Sass::EmbeddedProtocol::Value::Map.new(
118
- entries: [
119
- Sass::EmbeddedProtocol::Value::Map::Entry.new(
120
- key: Sass::EmbeddedProtocol::Value.new(
121
- string: Sass::EmbeddedProtocol::Value::String.new(
122
- text: 'color',
123
- quoted: true
124
- )
125
- ),
126
- value: Sass::EmbeddedProtocol::Value.new(
127
- rgb_color: Sass::EmbeddedProtocol::Value::RgbColor.new(
128
- red: 0,
129
- green: 0,
130
- blue: 0,
131
- alpha: 1
132
- )
112
+ )
113
+ },
114
+ 'returns_sass_map()': lambda {
115
+ EmbeddedProtocol::Value.new(
116
+ map: EmbeddedProtocol::Value::Map.new(
117
+ entries: [
118
+ EmbeddedProtocol::Value::Map::Entry.new(
119
+ key: EmbeddedProtocol::Value.new(
120
+ string: EmbeddedProtocol::Value::String.new(
121
+ text: 'color',
122
+ quoted: true
123
+ )
124
+ ),
125
+ value: EmbeddedProtocol::Value.new(
126
+ rgb_color: EmbeddedProtocol::Value::RgbColor.new(
127
+ red: 0,
128
+ green: 0,
129
+ blue: 0,
130
+ alpha: 1
133
131
  )
134
132
  )
135
- ]
136
- )
133
+ )
134
+ ]
137
135
  )
138
- },
139
- 'returns_sass_list()': lambda {
140
- Sass::EmbeddedProtocol::Value.new(
141
- list: Sass::EmbeddedProtocol::Value::List.new(
142
- separator: Sass::EmbeddedProtocol::ListSeparator::COMMA,
143
- has_brackets: true,
144
- contents: [
145
- Sass::EmbeddedProtocol::Value.new(
146
- number: Sass::EmbeddedProtocol::Value::Number.new(
147
- value: 10
148
- )
149
- ),
150
- Sass::EmbeddedProtocol::Value.new(
151
- number: Sass::EmbeddedProtocol::Value::Number.new(
152
- value: 20
153
- )
154
- ),
155
- Sass::EmbeddedProtocol::Value.new(
156
- number: Sass::EmbeddedProtocol::Value::Number.new(
157
- value: 30
158
- )
136
+ )
137
+ },
138
+ 'returns_sass_list()': lambda {
139
+ EmbeddedProtocol::Value.new(
140
+ list: EmbeddedProtocol::Value::List.new(
141
+ separator: EmbeddedProtocol::ListSeparator::COMMA,
142
+ has_brackets: true,
143
+ contents: [
144
+ EmbeddedProtocol::Value.new(
145
+ number: EmbeddedProtocol::Value::Number.new(
146
+ value: 10
159
147
  )
160
- ]
161
- )
148
+ ),
149
+ EmbeddedProtocol::Value.new(
150
+ number: EmbeddedProtocol::Value::Number.new(
151
+ value: 20
152
+ )
153
+ ),
154
+ EmbeddedProtocol::Value.new(
155
+ number: EmbeddedProtocol::Value::Number.new(
156
+ value: 30
157
+ )
158
+ )
159
+ ]
162
160
  )
163
- }
164
- }
161
+ )
162
+ }
165
163
  })[:css]
166
164
  end
167
165
 
@@ -270,7 +268,7 @@ module Sass
270
268
  end
271
269
 
272
270
  def test_function_with_error
273
- assert_raises(Sass::CompilationError) do
271
+ assert_raises(RenderError) do
274
272
  render('div {url: function_that_raises_errors();}')
275
273
  end
276
274
  end
@@ -322,17 +320,15 @@ module Sass
322
320
  threads = []
323
321
  10.times do |i|
324
322
  threads << Thread.new(i) do |id|
325
- output = @embedded.render({
326
- data: 'div { url: test-function() }',
327
- functions: {
328
- 'test_function()': lambda {
329
- Sass::EmbeddedProtocol::Value.new(
330
- string: Sass::EmbeddedProtocol::Value::String.new(
331
- text: "{test_key1: 'test_value', test_key2: #{id}}",
332
- quoted: true
333
- )
323
+ output = @embedded.render(data: 'div { url: test-function() }',
324
+ functions: {
325
+ 'test_function()': lambda {
326
+ EmbeddedProtocol::Value.new(
327
+ string: EmbeddedProtocol::Value::String.new(
328
+ text: "{test_key1: 'test_value', test_key2: #{id}}",
329
+ quoted: true
334
330
  )
335
- }
331
+ )
336
332
  }
337
333
  })[:css]
338
334
  assert_match(/test_key1/, output)
@@ -346,17 +342,15 @@ module Sass
346
342
  end
347
343
 
348
344
  def test_pass_custom_functions_as_a_parameter
349
- output = @embedded.render({
350
- data: 'div { url: test-function(); }',
351
- functions: {
352
- 'test_function()': lambda {
353
- Sass::EmbeddedProtocol::Value.new(
354
- string: Sass::EmbeddedProtocol::Value::String.new(
355
- text: 'custom_function',
356
- quoted: true
357
- )
345
+ output = @embedded.render(data: 'div { url: test-function(); }',
346
+ functions: {
347
+ 'test_function()': lambda {
348
+ EmbeddedProtocol::Value.new(
349
+ string: EmbeddedProtocol::Value::String.new(
350
+ text: 'custom_function',
351
+ quoted: true
358
352
  )
359
- }
353
+ )
360
354
  }
361
355
  })[:css]
362
356
 
@@ -364,13 +358,11 @@ module Sass
364
358
  end
365
359
 
366
360
  def test_pass_incompatible_type_to_custom_functions
367
- assert_raises(CompilationError) do
368
- @embedded.render({
369
- data: 'div { url: test-function(); }',
370
- functions: {
371
- 'test_function()': lambda {
372
- Class.new
373
- }
361
+ assert_raises(RenderError) do
362
+ @embedded.render(data: 'div { url: test-function(); }',
363
+ functions: {
364
+ 'test_function()': lambda {
365
+ Class.new
374
366
  }
375
367
  })[:css]
376
368
  end
@@ -51,40 +51,40 @@ module Sass
51
51
  end
52
52
 
53
53
  def test_expanded_output_is_default
54
- output = @embedded.render({ data: input_scss })[:css]
54
+ output = @embedded.render(data: input_scss)[:css]
55
55
  assert_equal expected_expanded_output, output
56
56
  end
57
57
 
58
58
  def test_output_style_accepts_strings
59
- output = @embedded.render({ data: input_scss, output_style: :expanded })[:css]
59
+ output = @embedded.render(data: input_scss, output_style: :expanded)[:css]
60
60
  assert_equal expected_expanded_output, output
61
61
  end
62
62
 
63
63
  def test_invalid_output_style
64
- assert_raises(InvalidStyleError) do
65
- @embedded.render({ data: input_scss, output_style: :totally_wrong })[:css]
64
+ assert_raises(ArgumentError) do
65
+ @embedded.render(data: input_scss, output_style: :totally_wrong)[:css]
66
66
  end
67
67
  end
68
68
 
69
69
  def test_unsupported_output_style
70
- assert_raises(UnsupportedValue) do
71
- @embedded.render({ data: input_scss, output_style: :nested })[:css]
70
+ assert_raises(ArgumentError) do
71
+ @embedded.render(data: input_scss, output_style: :nested)[:css]
72
72
  end
73
73
 
74
- assert_raises(UnsupportedValue) do
75
- @embedded.render({ data: input_scss, output_style: :compact })[:css]
74
+ assert_raises(ArgumentError) do
75
+ @embedded.render(data: input_scss, output_style: :compact)[:css]
76
76
  end
77
77
  end
78
78
 
79
79
  def test_compressed_output
80
- output = @embedded.render({ data: input_scss, output_style: :compressed })[:css]
80
+ output = @embedded.render(data: input_scss, output_style: :compressed)[:css]
81
81
  assert_equal <<~CSS.chomp, output
82
82
  #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
83
83
  CSS
84
84
  end
85
85
 
86
86
  def test_string_output_style_names
87
- output = @embedded.render({ data: input_scss, output_style: 'compressed' })[:css]
87
+ output = @embedded.render(data: input_scss, output_style: 'compressed')[:css]
88
88
  assert_equal <<~CSS.chomp, output
89
89
  #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
90
90
  CSS
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.2.4
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-25 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,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
@@ -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
  - - ">="