SassyCast 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -4
- data/README.md +123 -119
- data/lib/SassyCast.rb +14 -14
- data/stylesheets/SassyCast.scss +2 -7
- data/stylesheets/private/_all.scss +16 -0
- data/stylesheets/private/bool/_bool.scss +16 -0
- data/stylesheets/{types → private}/color/_color.scss +59 -63
- data/stylesheets/{types → private}/color/helpers/_from-hex.scss +41 -39
- data/stylesheets/{types → private}/color/helpers/_from-hsl.scss +48 -46
- data/stylesheets/{types → private}/color/helpers/_from-rgb.scss +49 -47
- data/stylesheets/private/color/helpers/_get-color-value.scss +20 -0
- data/stylesheets/private/color/helpers/_hex-to-dec.scss +22 -0
- data/stylesheets/{types → private}/list/_list.scss +33 -29
- data/stylesheets/private/map/_map.scss +23 -0
- data/stylesheets/private/null/_null.scss +13 -0
- data/stylesheets/{types → private}/number/_number.scss +63 -66
- data/stylesheets/{types → private}/number/helpers/_find-digits.scss +35 -33
- data/stylesheets/{types → private}/number/helpers/_find-integer.scss +35 -33
- data/stylesheets/private/number/helpers/_length.scss +21 -0
- data/stylesheets/private/number/helpers/_pow.scss +24 -0
- data/stylesheets/private/string/_string.scss +15 -0
- data/stylesheets/public/_all.scss +7 -0
- data/stylesheets/public/bool/_bool.scss +13 -0
- data/stylesheets/public/color/_color.scss +13 -0
- data/stylesheets/public/list/_list.scss +13 -0
- data/stylesheets/public/map/_map.scss +13 -0
- data/stylesheets/public/null/_null.scss +13 -0
- data/stylesheets/public/number/_number.scss +13 -0
- data/stylesheets/public/string/_string.scss +12 -0
- metadata +28 -19
- data/stylesheets/types/bool/_bool.scss +0 -12
- data/stylesheets/types/color/helpers/_get-color-value.scss +0 -18
- data/stylesheets/types/color/helpers/_hex-to-dec.scss +0 -20
- data/stylesheets/types/map/_map.scss +0 -17
- data/stylesheets/types/null/_null.scss +0 -9
- data/stylesheets/types/number/helpers/_length.scss +0 -19
- data/stylesheets/types/number/helpers/_pow.scss +0 -22
- data/stylesheets/types/string/_string.scss +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a2f1dc189fde28c3eab8bdc0d8437f41f2bde33
|
4
|
+
data.tar.gz: 48f936048f7a036c01ede59ed44347f2f5410dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6f42c4059bd809b9ac44695b689695cf2ad22e1e61825f84990b56d6dd329d0752159fdb3de8df685942a586eb4ae7ac005a3bba079222f3c0a53074a37be85
|
7
|
+
data.tar.gz: 51d15bcb539e4796ebca7d86237471acc2f0085fb78f66db35f89d7fb2f9d51e82de138a02f14ddb7495bc03e0c93a5de55cb3057069fea26725434a9ff3e7dd
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
* `1.
|
4
|
-
* `0.0
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
* `1.1.0`: dissociated error checking from function logic, and fixed some minor things
|
4
|
+
* `1.0.0`: `to-list` improvements, stable API
|
5
|
+
* `0.0.1`: initial commit
|
data/README.md
CHANGED
@@ -1,119 +1,123 @@
|
|
1
|
-
SassyCast
|
2
|
-
=========
|
3
|
-
|
4
|
-
SassyCast is a simple API for type conversion in Sass.
|
5
|
-
|
6
|
-
## `to-bool`
|
7
|
-
|
8
|
-
``` scss
|
9
|
-
to-bool(false); // false
|
10
|
-
to-bool(0); // false
|
11
|
-
to-bool(null); // false
|
12
|
-
to-bool(""); // false
|
13
|
-
to-bool(true); // true
|
14
|
-
to-bool(1); // true
|
15
|
-
to-bool(()); // true
|
16
|
-
to-bool(string); // true
|
17
|
-
to-bool("quoted string"); // true
|
18
|
-
to-bool(this is a list); // true
|
19
|
-
to-bool((this: is a map)); // true
|
20
|
-
to-bool(1337); // true
|
21
|
-
to-bool(#000); // true
|
22
|
-
```
|
23
|
-
|
24
|
-
## `to-number`
|
25
|
-
|
26
|
-
``` scss
|
27
|
-
to-number(1337); // 1337
|
28
|
-
to-number("0"); // 0
|
29
|
-
to-number("42"); // 42
|
30
|
-
to-number("4.2"); // 4.2
|
31
|
-
to-number("-10"); // -10
|
32
|
-
to-number("-10px"); // -10px
|
33
|
-
to-number(true); // 1
|
34
|
-
to-number(false); // 0
|
35
|
-
to-number(string); // 0
|
36
|
-
to-number(this is a list); // 0
|
37
|
-
to-number((this: is a map)); // 0
|
38
|
-
to-number(null); // 0
|
39
|
-
to-number(#000); // 0
|
40
|
-
```
|
41
|
-
|
42
|
-
## `to-list`
|
43
|
-
|
44
|
-
``` scss
|
45
|
-
to-list(0); // 0
|
46
|
-
to-list(1); // 1
|
47
|
-
to-list(string); // string
|
48
|
-
to-list(this is a list); // this is a list
|
49
|
-
to-list(this: is a map); // this, is a map
|
50
|
-
to-list(true); // true
|
51
|
-
to-list(false); // false
|
52
|
-
to-list(null); // null
|
53
|
-
to-list(#000); // #333
|
54
|
-
```
|
55
|
-
|
56
|
-
## `to-string`
|
57
|
-
|
58
|
-
``` scss
|
59
|
-
to-string(0); // "0"
|
60
|
-
to-string(1); // "1"
|
61
|
-
to-string(true); // "true"
|
62
|
-
to-string(false); // "false"
|
63
|
-
to-string(null); // "null"
|
64
|
-
to-string(this is a list); // "this is a list"
|
65
|
-
to-string(this, is, a, list); // "this, is, a, list"
|
66
|
-
to-string((this: is a map)); // "(this: is a map)"
|
67
|
-
to-string((this: is, a, map)); // "(this: is, a, map)"
|
68
|
-
to-string(#000); // "#333"
|
69
|
-
```
|
70
|
-
|
71
|
-
## `to-null`
|
72
|
-
|
73
|
-
``` scss
|
74
|
-
to-null(null); // null
|
75
|
-
to-null(0); // null
|
76
|
-
to-null(1); // null
|
77
|
-
to-null(string); // null
|
78
|
-
to-null(this is a list); // null
|
79
|
-
to-null(this: is a map); // null
|
80
|
-
to-null(true); // null
|
81
|
-
to-null(false); // null
|
82
|
-
to-null(#333); // null
|
83
|
-
```
|
84
|
-
|
85
|
-
## `to-map`
|
86
|
-
|
87
|
-
``` scss
|
88
|
-
to-map(0); // (1: 0)
|
89
|
-
to-map(1); // (1: 1)
|
90
|
-
to-map(true); // (1: true)
|
91
|
-
to-map(false); // (1: false)
|
92
|
-
to-map(null); // (1: null)
|
93
|
-
to-map(string); // (1: string)
|
94
|
-
to-map(this is a list); // (1: this, 2: is, 3: a, 4: map)
|
95
|
-
to-map(this: is a map); // (this: is a map)
|
96
|
-
```
|
97
|
-
|
98
|
-
## `to-color`
|
99
|
-
|
100
|
-
``` scss
|
101
|
-
to-color(0); // null
|
102
|
-
to-color(1); // null
|
103
|
-
to-color(black); // black
|
104
|
-
to-color(#000); // black
|
105
|
-
to-color("#000"); // black
|
106
|
-
to-color(true); // null
|
107
|
-
to-color(false); // null
|
108
|
-
to-color(null); // null
|
109
|
-
to-color(string); // null
|
110
|
-
to-color(this is a list); // null
|
111
|
-
to-color((this: is a map)); // null
|
112
|
-
```
|
113
|
-
|
114
|
-
## A few things to note:
|
115
|
-
|
116
|
-
* When trying to cast something to a number that cannot be converted, it returns `0`
|
117
|
-
* When trying to cast something to a color that cannot be converted, it returns `null`
|
118
|
-
* Casting to a map use `1` as key (and index in case of a list)
|
119
|
-
* Color formats are converted automatically by Sass; when casting a color to string, the resulting string can be different from the color input
|
1
|
+
SassyCast
|
2
|
+
=========
|
3
|
+
|
4
|
+
SassyCast is a simple API for type conversion in Sass.
|
5
|
+
|
6
|
+
## `to-bool`
|
7
|
+
|
8
|
+
``` scss
|
9
|
+
to-bool(false); // false
|
10
|
+
to-bool(0); // false
|
11
|
+
to-bool(null); // false
|
12
|
+
to-bool(""); // false
|
13
|
+
to-bool(true); // true
|
14
|
+
to-bool(1); // true
|
15
|
+
to-bool(()); // true
|
16
|
+
to-bool(string); // true
|
17
|
+
to-bool("quoted string"); // true
|
18
|
+
to-bool(this is a list); // true
|
19
|
+
to-bool((this: is a map)); // true
|
20
|
+
to-bool(1337); // true
|
21
|
+
to-bool(#000); // true
|
22
|
+
```
|
23
|
+
|
24
|
+
## `to-number`
|
25
|
+
|
26
|
+
``` scss
|
27
|
+
to-number(1337); // 1337
|
28
|
+
to-number("0"); // 0
|
29
|
+
to-number("42"); // 42
|
30
|
+
to-number("4.2"); // 4.2
|
31
|
+
to-number("-10"); // -10
|
32
|
+
to-number("-10px"); // -10px
|
33
|
+
to-number(true); // 1
|
34
|
+
to-number(false); // 0
|
35
|
+
to-number(string); // 0
|
36
|
+
to-number(this is a list); // 0
|
37
|
+
to-number((this: is a map)); // 0
|
38
|
+
to-number(null); // 0
|
39
|
+
to-number(#000); // 0
|
40
|
+
```
|
41
|
+
|
42
|
+
## `to-list`
|
43
|
+
|
44
|
+
``` scss
|
45
|
+
to-list(0); // 0
|
46
|
+
to-list(1); // 1
|
47
|
+
to-list(string); // string
|
48
|
+
to-list(this is a list); // this is a list
|
49
|
+
to-list(this: is a map); // this, is a map
|
50
|
+
to-list(true); // true
|
51
|
+
to-list(false); // false
|
52
|
+
to-list(null); // null
|
53
|
+
to-list(#000); // #333
|
54
|
+
```
|
55
|
+
|
56
|
+
## `to-string`
|
57
|
+
|
58
|
+
``` scss
|
59
|
+
to-string(0); // "0"
|
60
|
+
to-string(1); // "1"
|
61
|
+
to-string(true); // "true"
|
62
|
+
to-string(false); // "false"
|
63
|
+
to-string(null); // "null"
|
64
|
+
to-string(this is a list); // "this is a list"
|
65
|
+
to-string(this, is, a, list); // "this, is, a, list"
|
66
|
+
to-string((this: is a map)); // "(this: is a map)"
|
67
|
+
to-string((this: is, a, map)); // "(this: is, a, map)"
|
68
|
+
to-string(#000); // "#333"
|
69
|
+
```
|
70
|
+
|
71
|
+
## `to-null`
|
72
|
+
|
73
|
+
``` scss
|
74
|
+
to-null(null); // null
|
75
|
+
to-null(0); // null
|
76
|
+
to-null(1); // null
|
77
|
+
to-null(string); // null
|
78
|
+
to-null(this is a list); // null
|
79
|
+
to-null(this: is a map); // null
|
80
|
+
to-null(true); // null
|
81
|
+
to-null(false); // null
|
82
|
+
to-null(#333); // null
|
83
|
+
```
|
84
|
+
|
85
|
+
## `to-map`
|
86
|
+
|
87
|
+
``` scss
|
88
|
+
to-map(0); // (1: 0)
|
89
|
+
to-map(1); // (1: 1)
|
90
|
+
to-map(true); // (1: true)
|
91
|
+
to-map(false); // (1: false)
|
92
|
+
to-map(null); // (1: null)
|
93
|
+
to-map(string); // (1: string)
|
94
|
+
to-map(this is a list); // (1: this, 2: is, 3: a, 4: map)
|
95
|
+
to-map(this: is a map); // (this: is a map)
|
96
|
+
```
|
97
|
+
|
98
|
+
## `to-color`
|
99
|
+
|
100
|
+
``` scss
|
101
|
+
to-color(0); // null
|
102
|
+
to-color(1); // null
|
103
|
+
to-color(black); // black
|
104
|
+
to-color(#000); // black
|
105
|
+
to-color("#000"); // black
|
106
|
+
to-color(true); // null
|
107
|
+
to-color(false); // null
|
108
|
+
to-color(null); // null
|
109
|
+
to-color(string); // null
|
110
|
+
to-color(this is a list); // null
|
111
|
+
to-color((this: is a map)); // null
|
112
|
+
```
|
113
|
+
|
114
|
+
## A few things to note:
|
115
|
+
|
116
|
+
* When trying to cast something to a number that cannot be converted, it returns `0`
|
117
|
+
* When trying to cast something to a color that cannot be converted, it returns `null`
|
118
|
+
* Casting to a map use `1` as key (and index in case of a list)
|
119
|
+
* Color formats are sometimes converted automatically by Sass; when casting a color to string, the resulting string can be different from the color input
|
120
|
+
|
121
|
+
## Credits
|
122
|
+
|
123
|
+
Huge thanks to [Marc Mintel](http://twitter.com/marcmintel) for his help.
|
data/lib/SassyCast.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'compass'
|
2
|
-
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
3
|
-
Compass::Frameworks.register('SassyCast', :path => extension_path)
|
4
|
-
|
5
|
-
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
6
|
-
# Date is in the form of YYYY-MM-DD
|
7
|
-
module SassyCast
|
8
|
-
VERSION = "1.
|
9
|
-
DATE = "2014-
|
10
|
-
end
|
11
|
-
|
12
|
-
module Sass::Script::Functions
|
13
|
-
|
14
|
-
end
|
1
|
+
require 'compass'
|
2
|
+
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
3
|
+
Compass::Frameworks.register('SassyCast', :path => extension_path)
|
4
|
+
|
5
|
+
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
6
|
+
# Date is in the form of YYYY-MM-DD
|
7
|
+
module SassyCast
|
8
|
+
VERSION = "1.1.0"
|
9
|
+
DATE = "2014-10-03"
|
10
|
+
end
|
11
|
+
|
12
|
+
module Sass::Script::Functions
|
13
|
+
|
14
|
+
end
|
data/stylesheets/SassyCast.scss
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
@import "bool/bool";
|
2
|
+
@import "number/helpers/find-integer";
|
3
|
+
@import "number/helpers/find-digits";
|
4
|
+
@import "number/helpers/pow";
|
5
|
+
@import "number/helpers/length";
|
6
|
+
@import "number/number";
|
7
|
+
@import "string/string";
|
8
|
+
@import "list/list";
|
9
|
+
@import "map/map";
|
10
|
+
@import "null/null";
|
11
|
+
@import "color/helpers/from-rgb";
|
12
|
+
@import "color/helpers/from-hsl";
|
13
|
+
@import "color/helpers/from-hex";
|
14
|
+
@import "color/helpers/get-color-value";
|
15
|
+
@import "color/helpers/hex-to-dec";
|
16
|
+
@import "color/color";
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* Convert to bool
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @param {*} $value - value to cast
|
7
|
+
* ---
|
8
|
+
* @return {bool}
|
9
|
+
*/
|
10
|
+
|
11
|
+
@function _sc-to-bool($value) {
|
12
|
+
@if not $value or $value == "" or $value == 0 {
|
13
|
+
@return false;
|
14
|
+
}
|
15
|
+
@return true;
|
16
|
+
}
|
@@ -1,64 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
@
|
5
|
-
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@if type-of($value)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
$
|
26
|
-
$
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
@else {
|
61
|
-
//@warn "Could not cast `#{inspect($value)}` to color.";
|
62
|
-
@return null;
|
63
|
-
}
|
1
|
+
/**
|
2
|
+
* Convert to color
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @param {*} $value - value to cast
|
7
|
+
* ---
|
8
|
+
* @return {color | null}
|
9
|
+
*/
|
10
|
+
|
11
|
+
@function _sc-to-color($value) {
|
12
|
+
@if type-of($value) == color {
|
13
|
+
@return $value;
|
14
|
+
}
|
15
|
+
|
16
|
+
@if type-of($value) != string {
|
17
|
+
//@warn "Could not cast `#{inspect($value)}` to color.";
|
18
|
+
@return null;
|
19
|
+
}
|
20
|
+
|
21
|
+
$value-lower: to-lower-case($value);
|
22
|
+
$colors: transparent black silver gray white maroon red purple fuchsia green lime olive yellow navy blue teal aqua aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen;
|
23
|
+
$keywords: ();
|
24
|
+
|
25
|
+
// Filling $keywords with stringified color keywords
|
26
|
+
@each $color in $colors {
|
27
|
+
$keywords: append($keywords, $color + "");
|
28
|
+
}
|
29
|
+
|
30
|
+
// Deal with inherit keyword
|
31
|
+
@if $value-lower == "inherit" {
|
32
|
+
@return unquote($value);
|
33
|
+
}
|
34
|
+
|
35
|
+
// Deal with color keywords
|
36
|
+
@if index($keywords, $value-lower) {
|
37
|
+
@return nth($colors, index($keywords, $value-lower));
|
38
|
+
}
|
39
|
+
|
40
|
+
// Deal with hexadecimal triplets
|
41
|
+
@else if str-slice($value-lower, 1, 1) == '#' {
|
42
|
+
@return _sc-from-hex($value);
|
43
|
+
}
|
44
|
+
|
45
|
+
// Deal with rgb(a) colors
|
46
|
+
@else if str-slice($value-lower, 1, 3) == 'rgb' {
|
47
|
+
@return _sc-from-rgb($value);
|
48
|
+
}
|
49
|
+
|
50
|
+
// Deal with hsl(a) colors
|
51
|
+
@else if str-slice($value-lower, 1, 3) == 'hsl' {
|
52
|
+
@return _sc-from-hsl($value);
|
53
|
+
}
|
54
|
+
|
55
|
+
// Return value
|
56
|
+
@else {
|
57
|
+
//@warn "Could not cast `#{inspect($value)}` to color.";
|
58
|
+
@return null;
|
59
|
+
}
|
64
60
|
}
|