SassyCast 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -4
  3. data/README.md +123 -119
  4. data/lib/SassyCast.rb +14 -14
  5. data/stylesheets/SassyCast.scss +2 -7
  6. data/stylesheets/private/_all.scss +16 -0
  7. data/stylesheets/private/bool/_bool.scss +16 -0
  8. data/stylesheets/{types → private}/color/_color.scss +59 -63
  9. data/stylesheets/{types → private}/color/helpers/_from-hex.scss +41 -39
  10. data/stylesheets/{types → private}/color/helpers/_from-hsl.scss +48 -46
  11. data/stylesheets/{types → private}/color/helpers/_from-rgb.scss +49 -47
  12. data/stylesheets/private/color/helpers/_get-color-value.scss +20 -0
  13. data/stylesheets/private/color/helpers/_hex-to-dec.scss +22 -0
  14. data/stylesheets/{types → private}/list/_list.scss +33 -29
  15. data/stylesheets/private/map/_map.scss +23 -0
  16. data/stylesheets/private/null/_null.scss +13 -0
  17. data/stylesheets/{types → private}/number/_number.scss +63 -66
  18. data/stylesheets/{types → private}/number/helpers/_find-digits.scss +35 -33
  19. data/stylesheets/{types → private}/number/helpers/_find-integer.scss +35 -33
  20. data/stylesheets/private/number/helpers/_length.scss +21 -0
  21. data/stylesheets/private/number/helpers/_pow.scss +24 -0
  22. data/stylesheets/private/string/_string.scss +15 -0
  23. data/stylesheets/public/_all.scss +7 -0
  24. data/stylesheets/public/bool/_bool.scss +13 -0
  25. data/stylesheets/public/color/_color.scss +13 -0
  26. data/stylesheets/public/list/_list.scss +13 -0
  27. data/stylesheets/public/map/_map.scss +13 -0
  28. data/stylesheets/public/null/_null.scss +13 -0
  29. data/stylesheets/public/number/_number.scss +13 -0
  30. data/stylesheets/public/string/_string.scss +12 -0
  31. metadata +28 -19
  32. data/stylesheets/types/bool/_bool.scss +0 -12
  33. data/stylesheets/types/color/helpers/_get-color-value.scss +0 -18
  34. data/stylesheets/types/color/helpers/_hex-to-dec.scss +0 -20
  35. data/stylesheets/types/map/_map.scss +0 -17
  36. data/stylesheets/types/null/_null.scss +0 -9
  37. data/stylesheets/types/number/helpers/_length.scss +0 -19
  38. data/stylesheets/types/number/helpers/_pow.scss +0 -22
  39. data/stylesheets/types/string/_string.scss +0 -12
@@ -1,34 +1,36 @@
1
- // Finding the digits part of a stringified number
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $source: string source
4
- // @param [number] $pointer: current pointer
5
- // --------------------------------------------------------------------------------
6
- // @return [list] (new pointer, parsed number)
7
-
8
- @function _find-digits($source, $pointer) {
9
- $source: to-lower-case($source);
10
- $length: str-length($source);
11
- $numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
12
- $result: 0;
13
- $runs: 1;
14
-
15
- @while $pointer <= $length {
16
- $token: str-slice($source, $pointer, $pointer);
17
- $index: index($numbers, $token);
18
-
19
- @if $token == '.' {
20
- // @continue;
21
- }
22
- @else if $index and $index > 0 {
23
- $runs: $runs * 10;
24
- $result: $result * 10 + ($index - 1);
25
- }
26
- @else {
27
- @return $pointer, $result / $runs;
28
- }
29
-
30
- $pointer: $pointer + 1;
31
- }
32
-
33
- @return $pointer, $result / $runs;
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
- // Finding the integer part of a stringified number
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $source: string source
4
- // @param [number] $pointer: current pointer
5
- // --------------------------------------------------------------------------------
6
- // @return [list] (new pointer, parsed number)
7
-
8
- @function _find-integer($source, $pointer) {
9
- $source: to-lower-case($source);
10
- $length: str-length($source);
11
- $numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
12
- $result: 0;
13
-
14
- @while $pointer <= $length {
15
- $token: str-slice($source, $pointer, $pointer);
16
- $index: index($numbers, $token);
17
-
18
- @if $token == '-' {
19
- // @continue;
20
- }
21
- @else if $index {
22
- $result: $result * 10 + ($index - 1);
23
- }
24
- @else {
25
- @return $pointer, $result;
26
- }
27
-
28
- $pointer: $pointer + 1;
29
- }
30
-
31
- @return $pointer, $result;
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
+ }
@@ -0,0 +1,7 @@
1
+ @import "bool/bool";
2
+ @import "number/number";
3
+ @import "string/string";
4
+ @import "list/list";
5
+ @import "map/map";
6
+ @import "null/null";
7
+ @import "color/color";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Convert to bool
3
+ * ---
4
+ * @access public
5
+ * ---
6
+ * @param {*} $value - value to cast
7
+ * ---
8
+ * @return {bool}
9
+ */
10
+
11
+ @function to-bool($value) {
12
+ @return _sc-to-bool($value);
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Convert to color
3
+ * ---
4
+ * @access public
5
+ * ---
6
+ * @param {*} $value - value to cast
7
+ * ---
8
+ * @return {color | null}
9
+ */
10
+
11
+ @function to-color($value) {
12
+ @return _sc-to-color($value);
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Convert to list
3
+ * ---
4
+ * @access public
5
+ * ---
6
+ * @param {*} $value - value to cast
7
+ * ---
8
+ * @return {list}
9
+ */
10
+
11
+ @function to-list($value, $keep: 'both') {
12
+ @return _sc-to-list($value,$keep);
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Convert to map
3
+ * ---
4
+ * @access public
5
+ * ---
6
+ * @param {*} $value - value to cast
7
+ * ---
8
+ * @return {map}
9
+ */
10
+
11
+ @function to-map($value) {
12
+ @return _sc-to-map($value);
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Convert to null
3
+ * ---
4
+ * @access public
5
+ * ---
6
+ * @param {*} $value - value to cast
7
+ * ---
8
+ * @return null
9
+ */
10
+
11
+ @function to-null($value) {
12
+ @return _sc-to-null($value);
13
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Cast a value to a number if possible or return 0
3
+ * ---
4
+ * @access public
5
+ * ---
6
+ * @param {string} $value - complete source
7
+ * ---
8
+ * @return {number}
9
+ */
10
+
11
+ @function to-number($value) {
12
+ @return _sc-to-number($value);
13
+ }
@@ -0,0 +1,12 @@
1
+ /* Convert to string
2
+ * ---
3
+ * @access public
4
+ * ---
5
+ * @param {*} $value - value to cast
6
+ * ---
7
+ * @return {string}
8
+ */
9
+
10
+ @function to-string($value) {
11
+ @return _sc-to-string($value);
12
+ }
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.0.0
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-01-31 00:00:00.000000000 Z
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.3
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
- }