SassyCast 1.0.0 → 1.1.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/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
@@ -1,34 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
$
|
12
|
-
$
|
13
|
-
$
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
1
|
+
/**
|
2
|
+
* Finding the digits part of a stringified number
|
3
|
+
* ---
|
4
|
+
* @param {string} $source - string source
|
5
|
+
* @param {number} $pointer - current pointer
|
6
|
+
* ---
|
7
|
+
* @return {list} - new pointer, parsed number
|
8
|
+
*/
|
9
|
+
|
10
|
+
@function _sc-find-digits($source, $pointer) {
|
11
|
+
$source: to-lower-case($source);
|
12
|
+
$length: str-length($source);
|
13
|
+
$numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
|
14
|
+
$result: 0;
|
15
|
+
$runs: 1;
|
16
|
+
|
17
|
+
@while $pointer <= $length {
|
18
|
+
$token: str-slice($source, $pointer, $pointer);
|
19
|
+
$index: index($numbers, $token);
|
20
|
+
|
21
|
+
@if $token == '.' {
|
22
|
+
// @continue;
|
23
|
+
}
|
24
|
+
@else if $index and $index > 0 {
|
25
|
+
$runs: $runs * 10;
|
26
|
+
$result: $result * 10 + ($index - 1);
|
27
|
+
}
|
28
|
+
@else {
|
29
|
+
@return $pointer, $result / $runs;
|
30
|
+
}
|
31
|
+
|
32
|
+
$pointer: $pointer + 1;
|
33
|
+
}
|
34
|
+
|
35
|
+
@return $pointer, $result / $runs;
|
34
36
|
}
|
@@ -1,33 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
$
|
12
|
-
$
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
1
|
+
/**
|
2
|
+
* Finding the integer part of a stringified number
|
3
|
+
* ---
|
4
|
+
* @param {string} $source - string source
|
5
|
+
* @param {number} $pointer - current pointer
|
6
|
+
* ---
|
7
|
+
* @return {list} new pointer, parsed number
|
8
|
+
*/
|
9
|
+
|
10
|
+
@function _sc-find-integer($source, $pointer) {
|
11
|
+
$source: to-lower-case($source);
|
12
|
+
$length: str-length($source);
|
13
|
+
$numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
|
14
|
+
$result: 0;
|
15
|
+
|
16
|
+
@while $pointer <= $length {
|
17
|
+
$token: str-slice($source, $pointer, $pointer);
|
18
|
+
$index: index($numbers, $token);
|
19
|
+
|
20
|
+
@if $token == '-' {
|
21
|
+
// @continue;
|
22
|
+
}
|
23
|
+
@else if $index {
|
24
|
+
$result: $result * 10 + ($index - 1);
|
25
|
+
}
|
26
|
+
@else {
|
27
|
+
@return $pointer, $result;
|
28
|
+
}
|
29
|
+
|
30
|
+
$pointer: $pointer + 1;
|
31
|
+
}
|
32
|
+
|
33
|
+
@return $pointer, $result;
|
34
|
+
}
|
35
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* Tries to find a unit that would match a CSS length
|
3
|
+
* ---
|
4
|
+
* @param {number} $number - number
|
5
|
+
* @param {unit} $unit - potential unit
|
6
|
+
* ---
|
7
|
+
* @return {number} length (0 if cast failed)
|
8
|
+
*/
|
9
|
+
|
10
|
+
@function _sc-length($number, $unit) {
|
11
|
+
$strings: 'px' 'cm' 'mm' '%' 'ch' 'pica' 'in' 'em' 'rem' 'pt' 'pc' 'ex' 'vw' 'vh' 'vmin' 'vmax';
|
12
|
+
$units: 1px 1cm 1mm 1% 1ch 1pica 1in 1em 1rem 1pt 1pc 1ex 1vw 1vh 1vmin 1vmax;
|
13
|
+
$index: index($strings, $unit);
|
14
|
+
|
15
|
+
@if not $index {
|
16
|
+
@warn "Unknown unit `#{inspect($unit)}`.";
|
17
|
+
@return 0;
|
18
|
+
}
|
19
|
+
|
20
|
+
@return $number * nth($units, $index);
|
21
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* Power function
|
3
|
+
* ---
|
4
|
+
* @param {number} $x - number
|
5
|
+
* @param {number} $n - power
|
6
|
+
* ---
|
7
|
+
* @return [number] $x ^ $n
|
8
|
+
*/
|
9
|
+
|
10
|
+
@function _sc-pow($x, $n) {
|
11
|
+
$ret: 1;
|
12
|
+
|
13
|
+
@if $n >= 0 {
|
14
|
+
@for $i from 1 through $n {
|
15
|
+
$ret: $ret * $x;
|
16
|
+
}
|
17
|
+
} @else {
|
18
|
+
@for $i from $n to 0 {
|
19
|
+
$ret: $ret / $x;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
@return $ret;
|
24
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/* Convert to string
|
2
|
+
* ---
|
3
|
+
* @access private
|
4
|
+
* ---
|
5
|
+
* @param {*} $value - value to cast
|
6
|
+
* ---
|
7
|
+
* @return {string}
|
8
|
+
*/
|
9
|
+
|
10
|
+
@function _sc-to-string($value) {
|
11
|
+
@if type-of($value) == color {
|
12
|
+
@warn "Beware! Sass does some color conversion. The resulting string may be different from the color input.";
|
13
|
+
}
|
14
|
+
@return if(type-of($value) != string, inspect($value), $value);
|
15
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SassyCast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugo Giraudel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Sass API for type conversion.
|
14
14
|
email:
|
@@ -20,23 +20,32 @@ files:
|
|
20
20
|
- README.md
|
21
21
|
- CHANGELOG.md
|
22
22
|
- lib/SassyCast.rb
|
23
|
+
- stylesheets/private/_all.scss
|
24
|
+
- stylesheets/private/bool/_bool.scss
|
25
|
+
- stylesheets/private/color/_color.scss
|
26
|
+
- stylesheets/private/color/helpers/_from-hex.scss
|
27
|
+
- stylesheets/private/color/helpers/_from-hsl.scss
|
28
|
+
- stylesheets/private/color/helpers/_from-rgb.scss
|
29
|
+
- stylesheets/private/color/helpers/_get-color-value.scss
|
30
|
+
- stylesheets/private/color/helpers/_hex-to-dec.scss
|
31
|
+
- stylesheets/private/list/_list.scss
|
32
|
+
- stylesheets/private/map/_map.scss
|
33
|
+
- stylesheets/private/null/_null.scss
|
34
|
+
- stylesheets/private/number/_number.scss
|
35
|
+
- stylesheets/private/number/helpers/_find-digits.scss
|
36
|
+
- stylesheets/private/number/helpers/_find-integer.scss
|
37
|
+
- stylesheets/private/number/helpers/_length.scss
|
38
|
+
- stylesheets/private/number/helpers/_pow.scss
|
39
|
+
- stylesheets/private/string/_string.scss
|
40
|
+
- stylesheets/public/_all.scss
|
41
|
+
- stylesheets/public/bool/_bool.scss
|
42
|
+
- stylesheets/public/color/_color.scss
|
43
|
+
- stylesheets/public/list/_list.scss
|
44
|
+
- stylesheets/public/map/_map.scss
|
45
|
+
- stylesheets/public/null/_null.scss
|
46
|
+
- stylesheets/public/number/_number.scss
|
47
|
+
- stylesheets/public/string/_string.scss
|
23
48
|
- stylesheets/SassyCast.scss
|
24
|
-
- stylesheets/types/bool/_bool.scss
|
25
|
-
- stylesheets/types/color/helpers/_from-hex.scss
|
26
|
-
- stylesheets/types/color/helpers/_from-hsl.scss
|
27
|
-
- stylesheets/types/color/helpers/_from-rgb.scss
|
28
|
-
- stylesheets/types/color/helpers/_get-color-value.scss
|
29
|
-
- stylesheets/types/color/helpers/_hex-to-dec.scss
|
30
|
-
- stylesheets/types/color/_color.scss
|
31
|
-
- stylesheets/types/list/_list.scss
|
32
|
-
- stylesheets/types/map/_map.scss
|
33
|
-
- stylesheets/types/null/_null.scss
|
34
|
-
- stylesheets/types/number/helpers/_find-digits.scss
|
35
|
-
- stylesheets/types/number/helpers/_find-integer.scss
|
36
|
-
- stylesheets/types/number/helpers/_length.scss
|
37
|
-
- stylesheets/types/number/helpers/_pow.scss
|
38
|
-
- stylesheets/types/number/_number.scss
|
39
|
-
- stylesheets/types/string/_string.scss
|
40
49
|
homepage: https://github.com/HugoGiraudel/SassyCast/
|
41
50
|
licenses: []
|
42
51
|
metadata: {}
|
@@ -56,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
65
|
version: 1.3.6
|
57
66
|
requirements: []
|
58
67
|
rubyforge_project: SassyCast
|
59
|
-
rubygems_version: 2.0.
|
68
|
+
rubygems_version: 2.0.14
|
60
69
|
signing_key:
|
61
70
|
specification_version: 4
|
62
71
|
summary: SassyCast is a Sass-powered API for type conversion.
|
@@ -1,12 +0,0 @@
|
|
1
|
-
// Convert to bool
|
2
|
-
// --------------------------------------------------------------------------------
|
3
|
-
// @param $value: value to cast
|
4
|
-
// --------------------------------------------------------------------------------
|
5
|
-
// @return [bool]
|
6
|
-
|
7
|
-
@function to-bool($value) {
|
8
|
-
@if not $value or $value == "" or $value == 0 {
|
9
|
-
@return false;
|
10
|
-
}
|
11
|
-
@return true;
|
12
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
// Cast a stringified number / stringified percentage into number type
|
2
|
-
// --------------------------------------------------------------------------------
|
3
|
-
// @param [string] $string: string
|
4
|
-
// --------------------------------------------------------------------------------
|
5
|
-
// @return [number] unitless number or percentage
|
6
|
-
|
7
|
-
@function _get-color-value($string) {
|
8
|
-
$first: str-slice($string, 1, 1);
|
9
|
-
|
10
|
-
// Pad <1 values with a leading 0
|
11
|
-
@if $first == '.' {
|
12
|
-
$string: '0' + $string;
|
13
|
-
}
|
14
|
-
|
15
|
-
$last: str-slice($string, -1, -1);
|
16
|
-
|
17
|
-
@return if($last == '%', to-number(str-slice($string, 1, -2), 2) * 1%, to-number($string));
|
18
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
// Convert an hexadecimal number to a decimal number
|
2
|
-
// --------------------------------------------------------------------------------
|
3
|
-
// @param [string] $string: hexadecimal value
|
4
|
-
// --------------------------------------------------------------------------------
|
5
|
-
// @return [number] decimal number
|
6
|
-
|
7
|
-
@function _hex-to-dec($string){
|
8
|
-
$hex: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f";
|
9
|
-
$string: to-lower-case($string);
|
10
|
-
$length: str-length($string);
|
11
|
-
|
12
|
-
$dec: 0;
|
13
|
-
@for $i from 1 through $length {
|
14
|
-
$factor: 1 + ( 15 * ( $length - $i ));
|
15
|
-
$index: index($hex, str-slice($string, $i, $i));
|
16
|
-
$dec: $dec + $factor * ($index - 1);
|
17
|
-
}
|
18
|
-
|
19
|
-
@return $dec;
|
20
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
// Convert to map
|
2
|
-
// --------------------------------------------------------------------------------
|
3
|
-
// @param $value: value to cast
|
4
|
-
// --------------------------------------------------------------------------------
|
5
|
-
// @return [map]
|
6
|
-
|
7
|
-
@function to-map($value) {
|
8
|
-
@if type-of($value) == list {
|
9
|
-
$map: ();
|
10
|
-
@for $i from 1 through length($value) {
|
11
|
-
$map: map-merge($map, ($i: nth($value, $i)));
|
12
|
-
}
|
13
|
-
@return $map;
|
14
|
-
}
|
15
|
-
|
16
|
-
@return if(type-of($value) != map, (1: $value), $value);
|
17
|
-
}
|