sassc4 2.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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.gitmodules +3 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +97 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +51 -0
- data/ext/depend +4 -0
- data/ext/extconf.rb +92 -0
- data/ext/libsass/VERSION +1 -0
- data/ext/libsass/contrib/plugin.cpp +60 -0
- data/ext/libsass/include/sass/base.h +97 -0
- data/ext/libsass/include/sass/context.h +174 -0
- data/ext/libsass/include/sass/functions.h +139 -0
- data/ext/libsass/include/sass/values.h +145 -0
- data/ext/libsass/include/sass/version.h +12 -0
- data/ext/libsass/include/sass.h +15 -0
- data/ext/libsass/include/sass2scss.h +120 -0
- data/ext/libsass/src/MurmurHash2.hpp +91 -0
- data/ext/libsass/src/ast.cpp +953 -0
- data/ext/libsass/src/ast.hpp +1064 -0
- data/ext/libsass/src/ast2c.cpp +80 -0
- data/ext/libsass/src/ast2c.hpp +39 -0
- data/ext/libsass/src/ast_def_macros.hpp +140 -0
- data/ext/libsass/src/ast_fwd_decl.cpp +31 -0
- data/ext/libsass/src/ast_fwd_decl.hpp +274 -0
- data/ext/libsass/src/ast_helpers.hpp +316 -0
- data/ext/libsass/src/ast_sel_cmp.cpp +396 -0
- data/ext/libsass/src/ast_sel_super.cpp +539 -0
- data/ext/libsass/src/ast_sel_unify.cpp +275 -0
- data/ext/libsass/src/ast_sel_weave.cpp +616 -0
- data/ext/libsass/src/ast_selectors.cpp +1070 -0
- data/ext/libsass/src/ast_selectors.hpp +523 -0
- data/ext/libsass/src/ast_supports.cpp +114 -0
- data/ext/libsass/src/ast_supports.hpp +121 -0
- data/ext/libsass/src/ast_values.cpp +1154 -0
- data/ext/libsass/src/ast_values.hpp +498 -0
- data/ext/libsass/src/b64/cencode.h +32 -0
- data/ext/libsass/src/b64/encode.h +79 -0
- data/ext/libsass/src/backtrace.cpp +50 -0
- data/ext/libsass/src/backtrace.hpp +29 -0
- data/ext/libsass/src/base64vlq.cpp +47 -0
- data/ext/libsass/src/base64vlq.hpp +30 -0
- data/ext/libsass/src/bind.cpp +312 -0
- data/ext/libsass/src/bind.hpp +15 -0
- data/ext/libsass/src/c2ast.cpp +64 -0
- data/ext/libsass/src/c2ast.hpp +14 -0
- data/ext/libsass/src/c99func.c +54 -0
- data/ext/libsass/src/cencode.c +106 -0
- data/ext/libsass/src/check_nesting.cpp +393 -0
- data/ext/libsass/src/check_nesting.hpp +70 -0
- data/ext/libsass/src/color_maps.cpp +652 -0
- data/ext/libsass/src/color_maps.hpp +323 -0
- data/ext/libsass/src/color_spaces.cpp +241 -0
- data/ext/libsass/src/color_spaces.hpp +227 -0
- data/ext/libsass/src/constants.cpp +199 -0
- data/ext/libsass/src/constants.hpp +200 -0
- data/ext/libsass/src/context.cpp +870 -0
- data/ext/libsass/src/context.hpp +140 -0
- data/ext/libsass/src/cssize.cpp +521 -0
- data/ext/libsass/src/cssize.hpp +71 -0
- data/ext/libsass/src/dart_helpers.hpp +199 -0
- data/ext/libsass/src/debug.hpp +43 -0
- data/ext/libsass/src/debugger.hpp +964 -0
- data/ext/libsass/src/emitter.cpp +297 -0
- data/ext/libsass/src/emitter.hpp +101 -0
- data/ext/libsass/src/environment.cpp +260 -0
- data/ext/libsass/src/environment.hpp +124 -0
- data/ext/libsass/src/error_handling.cpp +239 -0
- data/ext/libsass/src/error_handling.hpp +248 -0
- data/ext/libsass/src/eval.cpp +1543 -0
- data/ext/libsass/src/eval.hpp +110 -0
- data/ext/libsass/src/eval_selectors.cpp +75 -0
- data/ext/libsass/src/expand.cpp +875 -0
- data/ext/libsass/src/expand.hpp +98 -0
- data/ext/libsass/src/extender.cpp +1226 -0
- data/ext/libsass/src/extender.hpp +399 -0
- data/ext/libsass/src/extension.cpp +43 -0
- data/ext/libsass/src/extension.hpp +89 -0
- data/ext/libsass/src/file.cpp +531 -0
- data/ext/libsass/src/file.hpp +124 -0
- data/ext/libsass/src/fn_colors.cpp +836 -0
- data/ext/libsass/src/fn_colors.hpp +99 -0
- data/ext/libsass/src/fn_lists.cpp +285 -0
- data/ext/libsass/src/fn_lists.hpp +34 -0
- data/ext/libsass/src/fn_maps.cpp +94 -0
- data/ext/libsass/src/fn_maps.hpp +30 -0
- data/ext/libsass/src/fn_miscs.cpp +248 -0
- data/ext/libsass/src/fn_miscs.hpp +40 -0
- data/ext/libsass/src/fn_numbers.cpp +246 -0
- data/ext/libsass/src/fn_numbers.hpp +45 -0
- data/ext/libsass/src/fn_selectors.cpp +205 -0
- data/ext/libsass/src/fn_selectors.hpp +35 -0
- data/ext/libsass/src/fn_strings.cpp +268 -0
- data/ext/libsass/src/fn_strings.hpp +34 -0
- data/ext/libsass/src/fn_utils.cpp +159 -0
- data/ext/libsass/src/fn_utils.hpp +62 -0
- data/ext/libsass/src/inspect.cpp +1126 -0
- data/ext/libsass/src/inspect.hpp +101 -0
- data/ext/libsass/src/json.cpp +1436 -0
- data/ext/libsass/src/json.hpp +117 -0
- data/ext/libsass/src/kwd_arg_macros.hpp +28 -0
- data/ext/libsass/src/lexer.cpp +122 -0
- data/ext/libsass/src/lexer.hpp +304 -0
- data/ext/libsass/src/listize.cpp +70 -0
- data/ext/libsass/src/listize.hpp +37 -0
- data/ext/libsass/src/mapping.hpp +19 -0
- data/ext/libsass/src/memory/allocator.cpp +48 -0
- data/ext/libsass/src/memory/allocator.hpp +138 -0
- data/ext/libsass/src/memory/config.hpp +20 -0
- data/ext/libsass/src/memory/memory_pool.hpp +186 -0
- data/ext/libsass/src/memory/shared_ptr.cpp +33 -0
- data/ext/libsass/src/memory/shared_ptr.hpp +332 -0
- data/ext/libsass/src/memory.hpp +12 -0
- data/ext/libsass/src/operation.hpp +223 -0
- data/ext/libsass/src/operators.cpp +267 -0
- data/ext/libsass/src/operators.hpp +30 -0
- data/ext/libsass/src/ordered_map.hpp +112 -0
- data/ext/libsass/src/output.cpp +320 -0
- data/ext/libsass/src/output.hpp +47 -0
- data/ext/libsass/src/parser.cpp +3059 -0
- data/ext/libsass/src/parser.hpp +395 -0
- data/ext/libsass/src/parser_selectors.cpp +189 -0
- data/ext/libsass/src/permutate.hpp +164 -0
- data/ext/libsass/src/plugins.cpp +188 -0
- data/ext/libsass/src/plugins.hpp +57 -0
- data/ext/libsass/src/position.cpp +163 -0
- data/ext/libsass/src/position.hpp +147 -0
- data/ext/libsass/src/prelexer.cpp +1780 -0
- data/ext/libsass/src/prelexer.hpp +484 -0
- data/ext/libsass/src/remove_placeholders.cpp +86 -0
- data/ext/libsass/src/remove_placeholders.hpp +37 -0
- data/ext/libsass/src/sass.cpp +156 -0
- data/ext/libsass/src/sass.hpp +147 -0
- data/ext/libsass/src/sass2scss.cpp +895 -0
- data/ext/libsass/src/sass_context.cpp +742 -0
- data/ext/libsass/src/sass_context.hpp +129 -0
- data/ext/libsass/src/sass_functions.cpp +210 -0
- data/ext/libsass/src/sass_functions.hpp +50 -0
- data/ext/libsass/src/sass_values.cpp +362 -0
- data/ext/libsass/src/sass_values.hpp +82 -0
- data/ext/libsass/src/settings.hpp +19 -0
- data/ext/libsass/src/source.cpp +69 -0
- data/ext/libsass/src/source.hpp +95 -0
- data/ext/libsass/src/source_data.hpp +32 -0
- data/ext/libsass/src/source_map.cpp +202 -0
- data/ext/libsass/src/source_map.hpp +65 -0
- data/ext/libsass/src/stylesheet.cpp +22 -0
- data/ext/libsass/src/stylesheet.hpp +57 -0
- data/ext/libsass/src/to_value.cpp +114 -0
- data/ext/libsass/src/to_value.hpp +46 -0
- data/ext/libsass/src/units.cpp +507 -0
- data/ext/libsass/src/units.hpp +110 -0
- data/ext/libsass/src/utf8/checked.h +336 -0
- data/ext/libsass/src/utf8/core.h +332 -0
- data/ext/libsass/src/utf8/unchecked.h +235 -0
- data/ext/libsass/src/utf8.h +34 -0
- data/ext/libsass/src/utf8_string.cpp +104 -0
- data/ext/libsass/src/utf8_string.hpp +38 -0
- data/ext/libsass/src/util.cpp +723 -0
- data/ext/libsass/src/util.hpp +105 -0
- data/ext/libsass/src/util_string.cpp +125 -0
- data/ext/libsass/src/util_string.hpp +73 -0
- data/ext/libsass/src/values.cpp +140 -0
- data/ext/libsass/src/values.hpp +12 -0
- data/lib/sassc/dependency.rb +17 -0
- data/lib/sassc/engine.rb +141 -0
- data/lib/sassc/error.rb +37 -0
- data/lib/sassc/functions_handler.rb +73 -0
- data/lib/sassc/import_handler.rb +50 -0
- data/lib/sassc/importer.rb +31 -0
- data/lib/sassc/native/native_context_api.rb +147 -0
- data/lib/sassc/native/native_functions_api.rb +159 -0
- data/lib/sassc/native/sass2scss_api.rb +10 -0
- data/lib/sassc/native/sass_input_style.rb +13 -0
- data/lib/sassc/native/sass_output_style.rb +12 -0
- data/lib/sassc/native/sass_value.rb +97 -0
- data/lib/sassc/native/string_list.rb +10 -0
- data/lib/sassc/native.rb +64 -0
- data/lib/sassc/sass_2_scss.rb +9 -0
- data/lib/sassc/script/functions.rb +8 -0
- data/lib/sassc/script/value/bool.rb +32 -0
- data/lib/sassc/script/value/color.rb +95 -0
- data/lib/sassc/script/value/list.rb +136 -0
- data/lib/sassc/script/value/map.rb +69 -0
- data/lib/sassc/script/value/number.rb +389 -0
- data/lib/sassc/script/value/string.rb +96 -0
- data/lib/sassc/script/value.rb +137 -0
- data/lib/sassc/script/value_conversion/base.rb +13 -0
- data/lib/sassc/script/value_conversion/bool.rb +13 -0
- data/lib/sassc/script/value_conversion/color.rb +18 -0
- data/lib/sassc/script/value_conversion/list.rb +25 -0
- data/lib/sassc/script/value_conversion/map.rb +21 -0
- data/lib/sassc/script/value_conversion/number.rb +13 -0
- data/lib/sassc/script/value_conversion/string.rb +17 -0
- data/lib/sassc/script/value_conversion.rb +69 -0
- data/lib/sassc/script.rb +17 -0
- data/lib/sassc/util/normalized_map.rb +117 -0
- data/lib/sassc/util.rb +231 -0
- data/lib/sassc/version.rb +5 -0
- data/lib/sassc.rb +57 -0
- data/sassc.gemspec +69 -0
- data/test/css_color_level4_test.rb +168 -0
- data/test/custom_importer_test.rb +127 -0
- data/test/engine_test.rb +314 -0
- data/test/error_test.rb +29 -0
- data/test/fixtures/paths.scss +10 -0
- data/test/functions_test.rb +340 -0
- data/test/native_test.rb +213 -0
- data/test/output_style_test.rb +107 -0
- data/test/sass_2_scss_test.rb +14 -0
- data/test/test_helper.rb +45 -0
- metadata +396 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
module SassC
|
|
6
|
+
class CSSColorLevel4Test < MiniTest::Test
|
|
7
|
+
include FixtureHelper
|
|
8
|
+
|
|
9
|
+
def test_rgb_with_space_separated_values_and_alpha_slash
|
|
10
|
+
assert_sass <<-SCSS, <<-CSS
|
|
11
|
+
div { color: rgb(100% 0% 0% / 50%); }
|
|
12
|
+
SCSS
|
|
13
|
+
div { color: rgba(255, 0, 0, 0.5); }
|
|
14
|
+
CSS
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_rgb_with_space_separated_values_without_alpha
|
|
18
|
+
assert_sass <<-SCSS, <<-CSS
|
|
19
|
+
div { color: rgb(100% 0% 0%); }
|
|
20
|
+
SCSS
|
|
21
|
+
div { color: red; }
|
|
22
|
+
CSS
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_rgb_with_numeric_values_and_alpha_slash
|
|
26
|
+
assert_sass <<-SCSS, <<-CSS
|
|
27
|
+
div { color: rgb(255 0 0 / 0.5); }
|
|
28
|
+
SCSS
|
|
29
|
+
div { color: rgba(255, 0, 0, 0.5); }
|
|
30
|
+
CSS
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_rgb_with_numeric_values_and_percent_alpha
|
|
34
|
+
assert_sass <<-SCSS, <<-CSS
|
|
35
|
+
div { color: rgb(255 0 0 / 100%); }
|
|
36
|
+
SCSS
|
|
37
|
+
div { color: red; }
|
|
38
|
+
CSS
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_rgba_with_space_separated_values_and_alpha_slash
|
|
42
|
+
assert_sass <<-SCSS, <<-CSS
|
|
43
|
+
div { color: rgba(50% 100% 0% / 75%); }
|
|
44
|
+
SCSS
|
|
45
|
+
div { color: rgba(128, 255, 0, 0.75); }
|
|
46
|
+
CSS
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_hsl_with_space_separated_values_and_alpha_slash
|
|
50
|
+
assert_sass <<-SCSS, <<-CSS
|
|
51
|
+
div { color: hsl(120deg 100% 50% / 50%); }
|
|
52
|
+
SCSS
|
|
53
|
+
div { color: rgba(0, 255, 0, 0.5); }
|
|
54
|
+
CSS
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_hsl_with_space_separated_values_without_alpha
|
|
58
|
+
assert_sass <<-SCSS, <<-CSS
|
|
59
|
+
div { color: hsl(240deg 100% 50%); }
|
|
60
|
+
SCSS
|
|
61
|
+
div { color: blue; }
|
|
62
|
+
CSS
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_hsl_without_deg_unit
|
|
66
|
+
assert_sass <<-SCSS, <<-CSS
|
|
67
|
+
div { color: hsl(180 50% 50% / 0.8); }
|
|
68
|
+
SCSS
|
|
69
|
+
div { color: rgba(64, 191, 191, 0.8); }
|
|
70
|
+
CSS
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_hsla_with_space_separated_values_and_alpha_slash
|
|
74
|
+
assert_sass <<-SCSS, <<-CSS
|
|
75
|
+
div { color: hsla(0deg 100% 50% / 25%); }
|
|
76
|
+
SCSS
|
|
77
|
+
div { color: red; }
|
|
78
|
+
CSS
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_mixed_color_syntax_in_same_file
|
|
82
|
+
assert_sass <<-SCSS, <<-CSS
|
|
83
|
+
.old-rgb { color: rgb(255, 0, 0); }
|
|
84
|
+
.new-rgb { color: rgb(255 0 0 / 0.5); }
|
|
85
|
+
.old-hsl { color: hsl(120, 100%, 50%); }
|
|
86
|
+
.new-hsl { color: hsl(120deg 100% 50% / 0.5); }
|
|
87
|
+
SCSS
|
|
88
|
+
.old-rgb { color: red; }
|
|
89
|
+
.new-rgb { color: rgba(255, 0, 0, 0.5); }
|
|
90
|
+
.old-hsl { color: lime; }
|
|
91
|
+
.new-hsl { color: rgba(0, 255, 0, 0.5); }
|
|
92
|
+
CSS
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_rgb_with_zero_alpha
|
|
96
|
+
assert_sass <<-SCSS, <<-CSS
|
|
97
|
+
div { color: rgb(255 128 64 / 0%); }
|
|
98
|
+
SCSS
|
|
99
|
+
div { color: rgba(255, 128, 64, 0); }
|
|
100
|
+
CSS
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_hsl_with_full_alpha
|
|
104
|
+
assert_sass <<-SCSS, <<-CSS
|
|
105
|
+
div { color: hsl(60deg 100% 50% / 100%); }
|
|
106
|
+
SCSS
|
|
107
|
+
div { color: yellow; }
|
|
108
|
+
CSS
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_rgb_with_decimal_alpha
|
|
112
|
+
assert_sass <<-SCSS, <<-CSS
|
|
113
|
+
div { color: rgb(200 100 50 / 0.333); }
|
|
114
|
+
SCSS
|
|
115
|
+
div { color: rgba(200, 100, 50, 0.333); }
|
|
116
|
+
CSS
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_hsl_with_decimal_alpha
|
|
120
|
+
assert_sass <<-SCSS, <<-CSS
|
|
121
|
+
div { color: hsl(90 80% 60% / 0.666); }
|
|
122
|
+
SCSS
|
|
123
|
+
div { color: rgba(153, 235, 71, 0.666); }
|
|
124
|
+
CSS
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_rgb_percent_mixed_with_alpha
|
|
128
|
+
assert_sass <<-SCSS, <<-CSS
|
|
129
|
+
div { color: rgb(50% 25% 75% / 0.5); }
|
|
130
|
+
SCSS
|
|
131
|
+
div { color: rgba(128, 64, 191, 0.5); }
|
|
132
|
+
CSS
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_hsl_with_turn_unit
|
|
136
|
+
assert_sass <<-SCSS, <<-CSS
|
|
137
|
+
div { color: hsl(0.5turn 50% 50% / 50%); }
|
|
138
|
+
SCSS
|
|
139
|
+
div { color: rgba(191, 65, 64, 0.5); }
|
|
140
|
+
CSS
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def test_hsl_with_rad_unit
|
|
144
|
+
assert_sass <<-SCSS, <<-CSS
|
|
145
|
+
div { color: hsl(3.14159rad 100% 50% / 80%); }
|
|
146
|
+
SCSS
|
|
147
|
+
div { color: rgba(255, 13, 0, 0.8); }
|
|
148
|
+
CSS
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_hsl_with_grad_unit
|
|
152
|
+
assert_sass <<-SCSS, <<-CSS
|
|
153
|
+
div { color: hsl(200grad 50% 50% / 60%); }
|
|
154
|
+
SCSS
|
|
155
|
+
div { color: rgba(64, 149, 191, 0.6); }
|
|
156
|
+
CSS
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
private
|
|
160
|
+
|
|
161
|
+
def assert_sass(sass, expected_css)
|
|
162
|
+
engine = Engine.new(sass)
|
|
163
|
+
assert_equal expected_css.strip.gsub(/\s+/, " "), # poor man's String#squish
|
|
164
|
+
engine.render.strip.gsub(/\s+/, " ")
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
module SassC
|
|
6
|
+
class CustomImporterTest < MiniTest::Test
|
|
7
|
+
include TempFileTest
|
|
8
|
+
|
|
9
|
+
class CustomImporter < Importer
|
|
10
|
+
def imports(path, parent_path)
|
|
11
|
+
if path =~ /styles/
|
|
12
|
+
[
|
|
13
|
+
Import.new("#{path}1.scss", source: "$var1: #000;"),
|
|
14
|
+
Import.new("#{path}2.scss")
|
|
15
|
+
]
|
|
16
|
+
else
|
|
17
|
+
Import.new(path)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class NoFilesImporter < Importer
|
|
23
|
+
def imports(path, parent_path)
|
|
24
|
+
[]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class OptionsImporter < Importer
|
|
29
|
+
def imports(path, parent_path)
|
|
30
|
+
Import.new("name.scss", source: options[:custom_option_source])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class ParentImporter < Importer
|
|
35
|
+
def imports(path, parent_path)
|
|
36
|
+
Import.new("name.scss", source: ".#{parent_path} { color: red; }")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_custom_importer_works
|
|
41
|
+
temp_file("styles2.scss", ".hi { color: $var1; }")
|
|
42
|
+
temp_file("fonts.scss", ".font { color: $var1; }")
|
|
43
|
+
|
|
44
|
+
data = <<SCSS
|
|
45
|
+
@import "styles";
|
|
46
|
+
@import "fonts";
|
|
47
|
+
SCSS
|
|
48
|
+
|
|
49
|
+
engine = Engine.new(data, {
|
|
50
|
+
importer: CustomImporter
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
assert_equal <<CSS, engine.render
|
|
54
|
+
.hi {
|
|
55
|
+
color: #000; }
|
|
56
|
+
|
|
57
|
+
.font {
|
|
58
|
+
color: #000; }
|
|
59
|
+
CSS
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_dependency_list
|
|
63
|
+
base = temp_dir("").to_s
|
|
64
|
+
|
|
65
|
+
temp_dir("fonts")
|
|
66
|
+
temp_dir("fonts/sub")
|
|
67
|
+
temp_file("fonts/sub/sub_fonts.scss", "$font: arial;")
|
|
68
|
+
temp_file("styles2.scss", ".hi { color: $var1; }")
|
|
69
|
+
temp_file "fonts/fonts.scss", <<SCSS
|
|
70
|
+
@import "sub/sub_fonts";
|
|
71
|
+
.font { font-familiy: $font; color: $var1; }
|
|
72
|
+
SCSS
|
|
73
|
+
|
|
74
|
+
data = <<SCSS
|
|
75
|
+
@import "styles";
|
|
76
|
+
@import "fonts";
|
|
77
|
+
SCSS
|
|
78
|
+
|
|
79
|
+
engine = Engine.new(data, {
|
|
80
|
+
importer: CustomImporter,
|
|
81
|
+
load_paths: ["fonts"]
|
|
82
|
+
})
|
|
83
|
+
engine.render
|
|
84
|
+
|
|
85
|
+
dependencies = engine.dependencies.map(&:filename).map { |f| f.gsub(base, "") }
|
|
86
|
+
|
|
87
|
+
assert_equal [
|
|
88
|
+
"/fonts/sub/sub_fonts.scss",
|
|
89
|
+
"/styles2.scss",
|
|
90
|
+
"fonts/fonts.scss",
|
|
91
|
+
"styles1.scss"
|
|
92
|
+
], dependencies
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_custom_importer_works_with_no_files
|
|
96
|
+
engine = Engine.new("@import 'fake.scss';", {
|
|
97
|
+
importer: NoFilesImporter
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
assert_equal "", engine.render
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_custom_importer_can_access_sassc_options
|
|
104
|
+
engine = Engine.new("@import 'fake.scss';", {
|
|
105
|
+
importer: OptionsImporter,
|
|
106
|
+
custom_option_source: ".test { width: 30px; }"
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
assert_equal <<CSS, engine.render
|
|
110
|
+
.test {
|
|
111
|
+
width: 30px; }
|
|
112
|
+
CSS
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_parent_path_is_accessible
|
|
116
|
+
engine = Engine.new("@import 'parent.scss';", {
|
|
117
|
+
importer: ParentImporter,
|
|
118
|
+
filename: "import-parent-filename.scss"
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
assert_equal <<CSS, engine.render
|
|
122
|
+
.import-parent-filename.scss {
|
|
123
|
+
color: red; }
|
|
124
|
+
CSS
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
data/test/engine_test.rb
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
module SassC
|
|
6
|
+
class EngineTest < MiniTest::Test
|
|
7
|
+
include TempFileTest
|
|
8
|
+
|
|
9
|
+
def render(data)
|
|
10
|
+
Engine.new(data).render
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_line_comments
|
|
14
|
+
template = <<-SCSS
|
|
15
|
+
.foo {
|
|
16
|
+
baz: bang; }
|
|
17
|
+
SCSS
|
|
18
|
+
expected_output = <<-CSS
|
|
19
|
+
/* line 1, stdin */
|
|
20
|
+
.foo {
|
|
21
|
+
baz: bang; }
|
|
22
|
+
CSS
|
|
23
|
+
output = Engine.new(template, line_comments: true).render
|
|
24
|
+
assert_equal expected_output, output
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_one_line_comments
|
|
28
|
+
assert_equal <<CSS, render(<<SCSS)
|
|
29
|
+
.foo {
|
|
30
|
+
baz: bang; }
|
|
31
|
+
CSS
|
|
32
|
+
.foo {// bar: baz;}
|
|
33
|
+
baz: bang; //}
|
|
34
|
+
}
|
|
35
|
+
SCSS
|
|
36
|
+
assert_equal <<CSS, render(<<SCSS)
|
|
37
|
+
.foo bar[val="//"] {
|
|
38
|
+
baz: bang; }
|
|
39
|
+
CSS
|
|
40
|
+
.foo bar[val="//"] {
|
|
41
|
+
baz: bang; //}
|
|
42
|
+
}
|
|
43
|
+
SCSS
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_variables
|
|
47
|
+
assert_equal <<CSS, render(<<SCSS)
|
|
48
|
+
blat {
|
|
49
|
+
a: foo; }
|
|
50
|
+
CSS
|
|
51
|
+
$var: foo;
|
|
52
|
+
|
|
53
|
+
blat {a: $var}
|
|
54
|
+
SCSS
|
|
55
|
+
|
|
56
|
+
assert_equal <<CSS, render(<<SCSS)
|
|
57
|
+
foo {
|
|
58
|
+
a: 2;
|
|
59
|
+
b: 6; }
|
|
60
|
+
CSS
|
|
61
|
+
foo {
|
|
62
|
+
$var: 2;
|
|
63
|
+
$another-var: 4;
|
|
64
|
+
a: $var;
|
|
65
|
+
b: $var + $another-var;}
|
|
66
|
+
SCSS
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_precision
|
|
70
|
+
template = <<-SCSS
|
|
71
|
+
$var: 1;
|
|
72
|
+
.foo {
|
|
73
|
+
baz: $var / 3; }
|
|
74
|
+
SCSS
|
|
75
|
+
expected_output = <<-CSS
|
|
76
|
+
.foo {
|
|
77
|
+
baz: 0.33333333; }
|
|
78
|
+
CSS
|
|
79
|
+
output = Engine.new(template, precision: 8).render
|
|
80
|
+
assert_equal expected_output, output
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_precision_not_specified
|
|
84
|
+
template = <<-SCSS
|
|
85
|
+
$var: 1;
|
|
86
|
+
.foo {
|
|
87
|
+
baz: $var / 3; }
|
|
88
|
+
SCSS
|
|
89
|
+
expected_output = <<-CSS
|
|
90
|
+
.foo {
|
|
91
|
+
baz: 0.3333333333; }
|
|
92
|
+
CSS
|
|
93
|
+
output = Engine.new(template).render
|
|
94
|
+
assert_equal expected_output, output
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_dependency_filenames_are_reported
|
|
98
|
+
base = temp_dir("").to_s
|
|
99
|
+
|
|
100
|
+
temp_file("not_included.scss", "$size: 30px;")
|
|
101
|
+
temp_file("import_parent.scss", "$size: 30px;")
|
|
102
|
+
temp_file("import.scss", "@import 'import_parent'; $size: 30px;")
|
|
103
|
+
temp_file("styles.scss", "@import 'import.scss'; .hi { width: $size; }")
|
|
104
|
+
|
|
105
|
+
engine = Engine.new(File.read("styles.scss"))
|
|
106
|
+
engine.render
|
|
107
|
+
deps = engine.dependencies
|
|
108
|
+
|
|
109
|
+
expected = ["/import.scss", "/import_parent.scss"]
|
|
110
|
+
assert_equal expected, deps.map { |dep| dep.options[:filename].gsub(base, "") }.sort
|
|
111
|
+
assert_equal expected, deps.map { |dep| dep.filename.gsub(base, "") }.sort
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_no_dependencies
|
|
115
|
+
engine = Engine.new("$size: 30px;")
|
|
116
|
+
engine.render
|
|
117
|
+
deps = engine.dependencies
|
|
118
|
+
assert_equal [], deps
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_not_rendered_error
|
|
122
|
+
engine = Engine.new("$size: 30px;")
|
|
123
|
+
assert_raises(NotRenderedError) { engine.dependencies }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_source_map
|
|
127
|
+
temp_dir('admin')
|
|
128
|
+
|
|
129
|
+
temp_file('admin/text-color.scss', <<SCSS)
|
|
130
|
+
p {
|
|
131
|
+
color: red;
|
|
132
|
+
}
|
|
133
|
+
SCSS
|
|
134
|
+
temp_file('style.scss', <<SCSS)
|
|
135
|
+
@import 'admin/text-color';
|
|
136
|
+
|
|
137
|
+
p {
|
|
138
|
+
padding: 20px;
|
|
139
|
+
}
|
|
140
|
+
SCSS
|
|
141
|
+
engine = Engine.new(File.read('style.scss'), {
|
|
142
|
+
source_map_file: "style.scss.map",
|
|
143
|
+
source_map_contents: true
|
|
144
|
+
})
|
|
145
|
+
engine.render
|
|
146
|
+
|
|
147
|
+
assert_equal <<MAP.strip, engine.source_map
|
|
148
|
+
{
|
|
149
|
+
\t"version": 3,
|
|
150
|
+
\t"file": "stdin.css",
|
|
151
|
+
\t"sources": [
|
|
152
|
+
\t\t"stdin",
|
|
153
|
+
\t\t"admin/text-color.scss"
|
|
154
|
+
\t],
|
|
155
|
+
\t"sourcesContent": [
|
|
156
|
+
\t\t"@import 'admin/text-color';\\n\\np {\\n padding: 20px;\\n}\\n",
|
|
157
|
+
\t\t"p {\\n color: red;\\n}\\n"
|
|
158
|
+
\t],
|
|
159
|
+
\t"names": [],
|
|
160
|
+
\t"mappings": "ACAA,AAAA,CAAC,CAAC;EACA,KAAK,EAAE,GAAG,GACX;;ADAD,AAAA,CAAC,CAAC;EACA,OAAO,EAAE,IAAI,GACd"
|
|
161
|
+
}
|
|
162
|
+
MAP
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def test_no_source_map
|
|
166
|
+
engine = Engine.new("$size: 30px;")
|
|
167
|
+
engine.render
|
|
168
|
+
assert_raises(NotRenderedError) { engine.source_map }
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def test_omit_source_map_url
|
|
172
|
+
temp_file('style.scss', <<SCSS)
|
|
173
|
+
p {
|
|
174
|
+
padding: 20px;
|
|
175
|
+
}
|
|
176
|
+
SCSS
|
|
177
|
+
engine = Engine.new(File.read('style.scss'), {
|
|
178
|
+
source_map_file: "style.scss.map",
|
|
179
|
+
source_map_contents: true,
|
|
180
|
+
omit_source_map_url: true
|
|
181
|
+
})
|
|
182
|
+
output = engine.render
|
|
183
|
+
|
|
184
|
+
refute_match /sourceMappingURL/, output
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def test_load_paths
|
|
188
|
+
temp_dir("included_1")
|
|
189
|
+
temp_dir("included_2")
|
|
190
|
+
|
|
191
|
+
temp_file("included_1/import_parent.scss", "$s: 30px;")
|
|
192
|
+
temp_file("included_2/import.scss", "@import 'import_parent'; $size: $s;")
|
|
193
|
+
temp_file("styles.scss", "@import 'import.scss'; .hi { width: $size; }")
|
|
194
|
+
|
|
195
|
+
assert_equal ".hi {\n width: 30px; }\n", Engine.new(
|
|
196
|
+
File.read("styles.scss"),
|
|
197
|
+
load_paths: [ "included_1", "included_2" ]
|
|
198
|
+
).render
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def test_global_load_paths
|
|
202
|
+
temp_dir("included_1")
|
|
203
|
+
temp_dir("included_2")
|
|
204
|
+
|
|
205
|
+
temp_file("included_1/import_parent.scss", "$s: 30px;")
|
|
206
|
+
temp_file("included_2/import.scss", "@import 'import_parent'; $size: $s;")
|
|
207
|
+
temp_file("styles.scss", "@import 'import.scss'; .hi { width: $size; }")
|
|
208
|
+
|
|
209
|
+
::SassC.load_paths << "included_1"
|
|
210
|
+
::SassC.load_paths << "included_2"
|
|
211
|
+
|
|
212
|
+
assert_equal ".hi {\n width: 30px; }\n", Engine.new(
|
|
213
|
+
File.read("styles.scss"),
|
|
214
|
+
).render
|
|
215
|
+
::SassC.load_paths.clear
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def test_env_load_paths
|
|
219
|
+
expected_load_paths = [ "included_1", "included_2" ]
|
|
220
|
+
::SassC.instance_eval { @load_paths = nil }
|
|
221
|
+
ENV['SASS_PATH'] = expected_load_paths.join(File::PATH_SEPARATOR)
|
|
222
|
+
assert_equal expected_load_paths, ::SassC.load_paths
|
|
223
|
+
::SassC.load_paths.clear
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def test_load_paths_not_configured
|
|
227
|
+
temp_file("included_1/import_parent.scss", "$s: 30px;")
|
|
228
|
+
temp_file("included_2/import.scss", "@import 'import_parent'; $size: $s;")
|
|
229
|
+
temp_file("styles.scss", "@import 'import.scss'; .hi { width: $size; }")
|
|
230
|
+
|
|
231
|
+
assert_raises(SyntaxError) do
|
|
232
|
+
Engine.new(File.read("styles.scss")).render
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def test_sass_variation
|
|
237
|
+
sass = <<SASS
|
|
238
|
+
$size: 30px
|
|
239
|
+
.foo
|
|
240
|
+
width: $size
|
|
241
|
+
SASS
|
|
242
|
+
|
|
243
|
+
css = <<CSS
|
|
244
|
+
.foo {
|
|
245
|
+
width: 30px; }
|
|
246
|
+
CSS
|
|
247
|
+
|
|
248
|
+
assert_equal css, Engine.new(sass, syntax: :sass).render
|
|
249
|
+
assert_equal css, Engine.new(sass, syntax: "sass").render
|
|
250
|
+
assert_raises(SyntaxError) { Engine.new(sass).render }
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def test_encoding_matches_input
|
|
254
|
+
input = String.new("$size: 30px;")
|
|
255
|
+
input.force_encoding("UTF-8")
|
|
256
|
+
output = Engine.new(input).render
|
|
257
|
+
assert_equal input.encoding, output.encoding
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def test_inline_source_maps
|
|
261
|
+
template = <<-SCSS
|
|
262
|
+
.foo {
|
|
263
|
+
baz: bang; }
|
|
264
|
+
SCSS
|
|
265
|
+
expected_output = <<-CSS
|
|
266
|
+
/* line 1, stdin */
|
|
267
|
+
.foo {
|
|
268
|
+
baz: bang; }
|
|
269
|
+
CSS
|
|
270
|
+
|
|
271
|
+
output = Engine.new(template, {
|
|
272
|
+
source_map_file: ".",
|
|
273
|
+
source_map_embed: true,
|
|
274
|
+
source_map_contents: true
|
|
275
|
+
}).render
|
|
276
|
+
|
|
277
|
+
assert_match /sourceMappingURL/, output
|
|
278
|
+
assert_match /.foo/, output
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def test_empty_template
|
|
282
|
+
output = Engine.new('').render
|
|
283
|
+
assert_equal '', output
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def test_empty_template_returns_a_new_object
|
|
287
|
+
input = String.new
|
|
288
|
+
output = Engine.new(input).render
|
|
289
|
+
assert !input.equal?(output), 'empty template must return a new object'
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def test_empty_template_encoding_matches_input
|
|
293
|
+
input = String.new.force_encoding("ISO-8859-1")
|
|
294
|
+
output = Engine.new(input).render
|
|
295
|
+
assert_equal input.encoding, output.encoding
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def test_handling_of_frozen_strings
|
|
299
|
+
output = Engine.new("body { background-color: red; }".freeze).render
|
|
300
|
+
assert_equal output, "body {\n background-color: red; }\n"
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def test_import_plain_css
|
|
304
|
+
temp_file("test.css", ".something{color: red}")
|
|
305
|
+
expected_output = <<-CSS
|
|
306
|
+
.something {
|
|
307
|
+
color: red; }
|
|
308
|
+
CSS
|
|
309
|
+
|
|
310
|
+
output = Engine.new("@import 'test'").render
|
|
311
|
+
assert_equal expected_output, output
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
end
|
data/test/error_test.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
module SassC
|
|
6
|
+
class ErrorTest < MiniTest::Test
|
|
7
|
+
def render(data, opts={})
|
|
8
|
+
Engine.new(data, opts).render
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_first_backtrace_is_sass
|
|
12
|
+
filename = "app/assets/stylesheets/application.scss"
|
|
13
|
+
|
|
14
|
+
begin
|
|
15
|
+
template = <<-SCSS
|
|
16
|
+
.foo {
|
|
17
|
+
baz: bang;
|
|
18
|
+
padding top: 10px;
|
|
19
|
+
}
|
|
20
|
+
SCSS
|
|
21
|
+
|
|
22
|
+
render(template, filename: filename)
|
|
23
|
+
rescue SassC::SyntaxError => err
|
|
24
|
+
expected = "#{filename}:3"
|
|
25
|
+
assert_equal expected, err.backtrace.first
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
div {
|
|
2
|
+
url: url(asset-path("foo.svg"));
|
|
3
|
+
url: url(image-path("foo.png"));
|
|
4
|
+
url: url(video-path("foo.mov"));
|
|
5
|
+
url: url(audio-path("foo.mp3"));
|
|
6
|
+
url: url(font-path("foo.woff"));
|
|
7
|
+
url: url(javascript-path('foo.js'));
|
|
8
|
+
url: url(javascript-path("foo.js"));
|
|
9
|
+
url: url(stylesheet-path("foo.css"));
|
|
10
|
+
}
|