on master help sign in
Add Stylus syntax test file
commit768189859ab7737dc5a071a4126f90ad944f99dd authorMohamed Abdelnour <mohamed.k.abdelnour@gmail.com> dateSun 30 May 2021, 10:07 (5 years ago) parent6e5a2a5
3 files changed+204
tests/syntax-tests/highlighted/Stylus/gradients.styl+90 tests/syntax-tests/source/Stylus/LICENSE.md+24 tests/syntax-tests/source/Stylus/gradients.styl+90
tests/syntax-tests/highlighted/Stylus/gradients.stylnew file+90
@@ -0,0 +1,90 @@
1+@import 'config'
2+
3+/*
4+ * Implicit color stop position.
5+ */
6+
7+pos-in-stops(i, stops)
8+ len = length(stops)
9+ if len - 1 == i
10+ 100%
11+ else if i
12+ unit(i / len * 100, '%')
13+ else
14+ 0
15+
16+/*
17+ * Normalize color stops:
18+ *
19+ * - (color pos) -> (pos color)
20+ * - (color) -> (implied-pos color)
21+ *
22+ */
23+
24+normalize-stops(stops)
25+ stops = clone(stops)
26+ for stop, i in stops
27+ if length(stop) == 1
28+ color = stop[0]
29+ stop[0] = pos-in-stops(i, stops)
30+ stop[1] = color
31+ else if typeof(stop[1]) == 'unit'
32+ pos = stop[1]
33+ stop[1] = stop[0]
34+ stop[0] = pos
35+ stops
36+
37+/*
38+ * Join color stops with the given translation function.
39+ */
40+
41+join-stops(stops, translate)
42+ str = ''
43+ len = length(stops)
44+ for stop, i in stops
45+ str += ', ' if i
46+ pos = stop[0]
47+ color = stop[1]
48+ str += translate(color, pos)
49+ unquote(str)
50+
51+/*
52+ * Standard color stop.
53+ */
54+
55+std-stop(color, pos)
56+ '%s %s' % (color pos)
57+
58+/*
59+ * Create a linear gradient with the given start position
60+ * and variable number of color stops.
61+ *
62+ * Examples:
63+ *
64+ * background: linear-gradient(top, red, green, blue)
65+ * background: linear-gradient(bottom, red, green 50%, blue)
66+ * background: linear-gradient(bottom, red, 50% green, blue)
67+ * background: linear-gradient(bottom, red, 50% green, 90% white, blue)
68+ *
69+ */
70+
71+linear-gradient(start, stops...)
72+ error('color stops required') unless length(stops)
73+
74+ unquote('linear-gradient(' + join(', ',arguments) + ')')
75+
76+/*
77+ * Create a linear gradient image with the given start position
78+ * and variable number of color stops.
79+ */
80+
81+linear-gradient-image(start, stops...)
82+ error('node-canvas is required for linear-gradient-image()') unless has-canvas
83+ stops = stops[0] if length(stops) == 1
84+ error('gradient image size required') unless start[0] is a 'unit'
85+ size = start[0]
86+ start = start[1] or 'top'
87+ grad = create-gradient-image(size, start)
88+ stops = normalize-stops(stops)
89+ add-color-stop(grad, stop[0], stop[1]) for stop in stops
90+ 'url(%s)' % gradient-data-uri(grad)
tests/syntax-tests/source/Stylus/LICENSE.mdnew file+24
@@ -0,0 +1,24 @@
1+The `gradients.styl` file has been added from https://github.com/stylus/nib under the following license:
2+
3+```text
4+The MIT License (MIT)
5+
6+Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
7+
8+Permission is hereby granted, free of charge, to any person obtaining a copy of
9+this software and associated documentation files (the "Software"), to deal in
10+the Software without restriction, including without limitation the rights to
11+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12+the Software, and to permit persons to whom the Software is furnished to do so,
13+subject to the following conditions:
14+
15+The above copyright notice and this permission notice shall be included in all
16+copies or substantial portions of the Software.
17+
18+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+```
tests/syntax-tests/source/Stylus/gradients.stylnew file+90
@@ -0,0 +1,90 @@
1+@import 'config'
2+
3+/*
4+ * Implicit color stop position.
5+ */
6+
7+pos-in-stops(i, stops)
8+ len = length(stops)
9+ if len - 1 == i
10+ 100%
11+ else if i
12+ unit(i / len * 100, '%')
13+ else
14+ 0
15+
16+/*
17+ * Normalize color stops:
18+ *
19+ * - (color pos) -> (pos color)
20+ * - (color) -> (implied-pos color)
21+ *
22+ */
23+
24+normalize-stops(stops)
25+ stops = clone(stops)
26+ for stop, i in stops
27+ if length(stop) == 1
28+ color = stop[0]
29+ stop[0] = pos-in-stops(i, stops)
30+ stop[1] = color
31+ else if typeof(stop[1]) == 'unit'
32+ pos = stop[1]
33+ stop[1] = stop[0]
34+ stop[0] = pos
35+ stops
36+
37+/*
38+ * Join color stops with the given translation function.
39+ */
40+
41+join-stops(stops, translate)
42+ str = ''
43+ len = length(stops)
44+ for stop, i in stops
45+ str += ', ' if i
46+ pos = stop[0]
47+ color = stop[1]
48+ str += translate(color, pos)
49+ unquote(str)
50+
51+/*
52+ * Standard color stop.
53+ */
54+
55+std-stop(color, pos)
56+ '%s %s' % (color pos)
57+
58+/*
59+ * Create a linear gradient with the given start position
60+ * and variable number of color stops.
61+ *
62+ * Examples:
63+ *
64+ * background: linear-gradient(top, red, green, blue)
65+ * background: linear-gradient(bottom, red, green 50%, blue)
66+ * background: linear-gradient(bottom, red, 50% green, blue)
67+ * background: linear-gradient(bottom, red, 50% green, 90% white, blue)
68+ *
69+ */
70+
71+linear-gradient(start, stops...)
72+ error('color stops required') unless length(stops)
73+
74+ unquote('linear-gradient(' + join(', ',arguments) + ')')
75+
76+/*
77+ * Create a linear gradient image with the given start position
78+ * and variable number of color stops.
79+ */
80+
81+linear-gradient-image(start, stops...)
82+ error('node-canvas is required for linear-gradient-image()') unless has-canvas
83+ stops = stops[0] if length(stops) == 1
84+ error('gradient image size required') unless start[0] is a 'unit'
85+ size = start[0]
86+ start = start[1] or 'top'
87+ grad = create-gradient-image(size, start)
88+ stops = normalize-stops(stops)
89+ add-color-stop(grad, stop[0], stop[1]) for stop in stops
90+ 'url(%s)' % gradient-data-uri(grad)