sass-embedded 0.1.3 → 0.3.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.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +2 -2
- data/.rubocop.yml +14 -0
- data/README.md +3 -3
- data/Rakefile +11 -4
- data/ext/{sass_embedded/.gitignore → .gitignore} +0 -0
- data/ext/Makefile +51 -0
- data/ext/extconf.rb +160 -0
- data/lib/sass.rb +18 -10
- data/lib/sass/embedded.rb +317 -0
- data/lib/sass/error.rb +4 -9
- data/lib/sass/transport.rb +150 -0
- data/lib/sass/util.rb +1 -0
- data/lib/sass/version.rb +1 -1
- data/sass-embedded.gemspec +4 -2
- data/test/compiler_test.rb +25 -39
- data/test/custom_importer_test.rb +26 -33
- data/test/error_test.rb +4 -6
- data/test/functions_test.rb +151 -159
- data/test/output_style_test.rb +12 -12
- data/test/sass_test.rb +2 -6
- metadata +38 -9
- data/ext/sass_embedded/Makefile +0 -35
- data/ext/sass_embedded/extconf.rb +0 -124
- data/lib/sass/embedded/compiler.rb +0 -238
- data/lib/sass/embedded/transport.rb +0 -140
data/test/error_test.rb
CHANGED
@@ -5,11 +5,11 @@ require_relative 'test_helper'
|
|
5
5
|
module Sass
|
6
6
|
class ErrorTest < MiniTest::Test
|
7
7
|
def setup
|
8
|
-
@
|
8
|
+
@embedded = Embedded.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def teardown
|
12
|
-
@
|
12
|
+
@embedded.close
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_first_backtrace_is_sass
|
@@ -20,10 +20,8 @@ module Sass
|
|
20
20
|
}
|
21
21
|
SCSS
|
22
22
|
|
23
|
-
@
|
24
|
-
|
25
|
-
})
|
26
|
-
rescue Sass::CompilationError => e
|
23
|
+
@embedded.render(data: template)
|
24
|
+
rescue RenderError => e
|
27
25
|
expected = 'stdin:3:20'
|
28
26
|
assert_equal expected, e.backtrace.first
|
29
27
|
end
|
data/test/functions_test.rb
CHANGED
@@ -5,163 +5,161 @@ require_relative 'test_helper'
|
|
5
5
|
module Sass
|
6
6
|
class FunctionsTest < MiniTest::Test
|
7
7
|
def setup
|
8
|
-
@
|
8
|
+
@embedded = Embedded.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def teardown
|
12
|
-
@
|
12
|
+
@embedded.close
|
13
13
|
end
|
14
14
|
|
15
15
|
def render(sass)
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
74
|
-
|
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
|
83
|
+
'passed value is not a EmbeddedProtocol::Value::Number'
|
77
84
|
end
|
78
85
|
|
79
86
|
argument
|
80
87
|
},
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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(
|
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 = @
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
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 = @
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
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(
|
368
|
-
@
|
369
|
-
|
370
|
-
|
371
|
-
|
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
|
data/test/output_style_test.rb
CHANGED
@@ -5,11 +5,11 @@ require_relative 'test_helper'
|
|
5
5
|
module Sass
|
6
6
|
class OutputStyleTest < MiniTest::Test
|
7
7
|
def setup
|
8
|
-
@
|
8
|
+
@embedded = Embedded.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def teardown
|
12
|
-
@
|
12
|
+
@embedded.close
|
13
13
|
end
|
14
14
|
|
15
15
|
def input_scss
|
@@ -51,40 +51,40 @@ module Sass
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_expanded_output_is_default
|
54
|
-
output = @
|
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 = @
|
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(
|
65
|
-
@
|
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(
|
71
|
-
@
|
70
|
+
assert_raises(ArgumentError) do
|
71
|
+
@embedded.render(data: input_scss, output_style: :nested)[:css]
|
72
72
|
end
|
73
73
|
|
74
|
-
assert_raises(
|
75
|
-
@
|
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 = @
|
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 = @
|
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
|