SassyJSON 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +18 -18
  3. data/README.md +112 -112
  4. data/lib/JsonImporter.rb +228 -228
  5. data/lib/SassyJSON.rb +12 -14
  6. data/stylesheets/SassyJSON.scss +5 -5
  7. data/stylesheets/decode/api/_json.scss +26 -26
  8. data/stylesheets/decode/decode.scss +28 -28
  9. data/stylesheets/decode/helpers/all/_throw.scss +11 -11
  10. data/stylesheets/decode/helpers/all/_value.scss +49 -49
  11. data/stylesheets/decode/helpers/color/_color.scss +50 -50
  12. data/stylesheets/decode/helpers/color/_get-color-value.scss +22 -22
  13. data/stylesheets/decode/helpers/color/_hex-to-dec.scss +19 -19
  14. data/stylesheets/decode/helpers/color/_hex.scss +39 -39
  15. data/stylesheets/decode/helpers/color/_hsl.scss +46 -46
  16. data/stylesheets/decode/helpers/color/_rgb.scss +46 -46
  17. data/stylesheets/decode/helpers/map/_consume.scss +33 -33
  18. data/stylesheets/decode/helpers/number/_find-digits.scss +39 -39
  19. data/stylesheets/decode/helpers/number/_find-exponent.scss +51 -51
  20. data/stylesheets/decode/helpers/number/_find-integer.scss +37 -37
  21. data/stylesheets/decode/helpers/number/_pow.scss +22 -22
  22. data/stylesheets/decode/helpers/string/_find-ending-quote.scss +57 -57
  23. data/stylesheets/decode/helpers/string/_length.scss +42 -42
  24. data/stylesheets/decode/helpers/string/_strip-token.scss +16 -16
  25. data/stylesheets/decode/types/_bool.scss +40 -40
  26. data/stylesheets/decode/types/_list.scss +54 -54
  27. data/stylesheets/decode/types/_map.scss +78 -78
  28. data/stylesheets/decode/types/_null.scss +19 -19
  29. data/stylesheets/decode/types/_number.scss +63 -63
  30. data/stylesheets/decode/types/_string.scss +41 -41
  31. data/stylesheets/encode/api/_json.scss +17 -17
  32. data/stylesheets/encode/encode.scss +17 -17
  33. data/stylesheets/encode/helpers/_quote.scss +9 -9
  34. data/stylesheets/encode/mixins/_json.scss +36 -36
  35. data/stylesheets/encode/types/_bool.scss +9 -9
  36. data/stylesheets/encode/types/_color.scss +9 -9
  37. data/stylesheets/encode/types/_list.scss +13 -13
  38. data/stylesheets/encode/types/_map.scss +13 -13
  39. data/stylesheets/encode/types/_null.scss +9 -9
  40. data/stylesheets/encode/types/_number.scss +9 -9
  41. data/stylesheets/encode/types/_string.scss +9 -9
  42. metadata +8 -10
@@ -1,40 +1,40 @@
1
- // Cast a JSON encoded string into a hexadecimal color
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $string: JSON string
4
- // --------------------------------------------------------------------------------
5
- // @return [color|string] string or hex color depending on the match
6
-
7
- @function _from-hex($string) {
8
- $string-lower: to-lower-case($string);
9
- $r: ""; $g: ""; $b: "";
10
- $hex: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f";
11
- $length: str-length($string);
12
- $max: if($length == 4, 1, 2);
13
-
14
- // Check for length accuracy
15
- @if $length != 4 and $length != 7 {
16
- @return $string;
17
- }
18
-
19
- // Loop from the second character (omitting #)
20
- @for $i from 2 through $length {
21
- $c: str-slice($string-lower, $i, $i);
22
-
23
- // If wrong character, return
24
- @if not index($hex, $c) {
25
- @return $string;
26
- }
27
-
28
- @if str-length($r) < $max { $r: $r + $c }
29
- @else if str-length($g) < $max { $g: $g + $c }
30
- @else if str-length($b) < $max { $b: $b + $c }
31
- }
32
-
33
- @if $length == 4 {
34
- $r: $r + $r;
35
- $g: $g + $g;
36
- $b: $b + $b;
37
- }
38
-
39
- @return rgb(_hex-to-dec($r), _hex-to-dec($g), _hex-to-dec($b));
1
+ // Cast a JSON encoded string into a hexadecimal color
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $string: JSON string
4
+ // --------------------------------------------------------------------------------
5
+ // @return [color|string] string or hex color depending on the match
6
+
7
+ @function _from-hex($string) {
8
+ $string-lower: to-lower-case($string);
9
+ $r: ""; $g: ""; $b: "";
10
+ $hex: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f";
11
+ $length: str-length($string);
12
+ $max: if($length == 4, 1, 2);
13
+
14
+ // Check for length accuracy
15
+ @if $length != 4 and $length != 7 {
16
+ @return $string;
17
+ }
18
+
19
+ // Loop from the second character (omitting #)
20
+ @for $i from 2 through $length {
21
+ $c: str-slice($string-lower, $i, $i);
22
+
23
+ // If wrong character, return
24
+ @if not index($hex, $c) {
25
+ @return $string;
26
+ }
27
+
28
+ @if str-length($r) < $max { $r: $r + $c }
29
+ @else if str-length($g) < $max { $g: $g + $c }
30
+ @else if str-length($b) < $max { $b: $b + $c }
31
+ }
32
+
33
+ @if $length == 4 {
34
+ $r: $r + $r;
35
+ $g: $g + $g;
36
+ $b: $b + $b;
37
+ }
38
+
39
+ @return rgb(_hex-to-dec($r), _hex-to-dec($g), _hex-to-dec($b));
40
40
  }
@@ -1,47 +1,47 @@
1
- // Cast a JSON encoded string into a hsl(a) color
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $string: JSON string
4
- // --------------------------------------------------------------------------------
5
- // @return [color|string] string or hsl(a) color, depending on the match
6
-
7
- @function _from-hsl($string) {
8
- $frags: ();
9
- $string-lower: to-lower-case($string);
10
- $is-alpha: str-slice($string-lower, 4, 4) == 'a';
11
- $length: str-length($string);
12
- $start: str-index($string, "(");
13
-
14
- @for $i from $start through $length {
15
- $token: str-slice($string-lower, $i, $i);
16
- @if $token == ' ' {
17
- // @continue;
18
- }
19
- @else if $token == '(' or $token == ',' {
20
- $frags: append($frags, "");
21
- }
22
- @else if $token == ')' {
23
- @if length($frags) != if($is-alpha, 4, 3) { @return $string; } // Parsing error
24
- $hue: _get-color-value(nth($frags, 1));
25
- $saturation: _get-color-value(nth($frags, 2));
26
- $lightness: _get-color-value(nth($frags, 3));
27
-
28
- @if not $hue or not $saturation or not $lightness {
29
- @return $string;
30
- }
31
-
32
- @if $is-alpha {
33
- @if length($frags) != 4 { @return $string; } // No alpha channel found
34
- $alpha: _get-color-value(nth($frags, 4));
35
- @if not $alpha { @return $string; } // Error parsing alpha channel
36
- @return hsla($hue, $saturation, $lightness, $alpha);
37
- }
38
-
39
- @return hsl($hue, $saturation, $lightness);
40
- }
41
- @else {
42
- $frags: set-nth($frags, length($frags), nth($frags, length($frags)) + $token);
43
- }
44
- }
45
-
46
- @return $string;
1
+ // Cast a JSON encoded string into a hsl(a) color
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $string: JSON string
4
+ // --------------------------------------------------------------------------------
5
+ // @return [color|string] string or hsl(a) color, depending on the match
6
+
7
+ @function _from-hsl($string) {
8
+ $frags: ();
9
+ $string-lower: to-lower-case($string);
10
+ $is-alpha: str-slice($string-lower, 4, 4) == 'a';
11
+ $length: str-length($string);
12
+ $start: str-index($string, "(");
13
+
14
+ @for $i from $start through $length {
15
+ $token: str-slice($string-lower, $i, $i);
16
+ @if $token == ' ' {
17
+ // @continue;
18
+ }
19
+ @else if $token == '(' or $token == ',' {
20
+ $frags: append($frags, "");
21
+ }
22
+ @else if $token == ')' {
23
+ @if length($frags) != if($is-alpha, 4, 3) { @return $string; } // Parsing error
24
+ $hue: _get-color-value(nth($frags, 1));
25
+ $saturation: _get-color-value(nth($frags, 2));
26
+ $lightness: _get-color-value(nth($frags, 3));
27
+
28
+ @if not $hue or not $saturation or not $lightness {
29
+ @return $string;
30
+ }
31
+
32
+ @if $is-alpha {
33
+ @if length($frags) != 4 { @return $string; } // No alpha channel found
34
+ $alpha: _get-color-value(nth($frags, 4));
35
+ @if not $alpha { @return $string; } // Error parsing alpha channel
36
+ @return hsla($hue, $saturation, $lightness, $alpha);
37
+ }
38
+
39
+ @return hsl($hue, $saturation, $lightness);
40
+ }
41
+ @else {
42
+ $frags: set-nth($frags, length($frags), nth($frags, length($frags)) + $token);
43
+ }
44
+ }
45
+
46
+ @return $string;
47
47
  }
@@ -1,47 +1,47 @@
1
- // Cast a JSON encoded string into a rgb(a) color
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $string: JSON string
4
- // --------------------------------------------------------------------------------
5
- // @return [color|string] string or rgb(a) color depending on the match
6
-
7
- @function _from-rgb($string) {
8
- $string-lower: to-lower-case($string);
9
- $frags: ();
10
- $is-alpha: str-slice($string-lower, 4, 4) == 'a';
11
- $start: str-index($string, "(");
12
- $length: str-length($string);
13
-
14
- @for $i from $start through $length {
15
- $token: str-slice($string-lower, $i, $i);
16
- @if $token == ' ' {
17
- // @continue;
18
- }
19
- @else if $token == '(' or $token == ',' {
20
- $frags: append($frags, "");
21
- }
22
- @else if $token == ')' {
23
- @if length($frags) != if($is-alpha, 4, 3) { @return $string; } // Parsing error
24
- $red: _get-color-value(nth($frags, 1));
25
- $green: _get-color-value(nth($frags, 2));
26
- $blue: _get-color-value(nth($frags, 3));
27
-
28
- @if not $red or not $green or not $blue {
29
- @return $string;
30
- }
31
-
32
- @if $is-alpha {
33
- @if length($frags) != 4 { @return $string; } // No alpha channel found
34
- $alpha: _get-color-value(nth($frags, 4));
35
- @if not $alpha { @return $string; } // Error parsing alpha channel
36
- @return rgba($red, $green, $blue, $alpha);
37
- }
38
-
39
- @return rgb($red, $green, $blue);
40
- }
41
- @else {
42
- $frags: set-nth($frags, length($frags), nth($frags, length($frags)) + $token);
43
- }
44
- }
45
-
46
- @return $string;
1
+ // Cast a JSON encoded string into a rgb(a) color
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $string: JSON string
4
+ // --------------------------------------------------------------------------------
5
+ // @return [color|string] string or rgb(a) color depending on the match
6
+
7
+ @function _from-rgb($string) {
8
+ $string-lower: to-lower-case($string);
9
+ $frags: ();
10
+ $is-alpha: str-slice($string-lower, 4, 4) == 'a';
11
+ $start: str-index($string, "(");
12
+ $length: str-length($string);
13
+
14
+ @for $i from $start through $length {
15
+ $token: str-slice($string-lower, $i, $i);
16
+ @if $token == ' ' {
17
+ // @continue;
18
+ }
19
+ @else if $token == '(' or $token == ',' {
20
+ $frags: append($frags, "");
21
+ }
22
+ @else if $token == ')' {
23
+ @if length($frags) != if($is-alpha, 4, 3) { @return $string; } // Parsing error
24
+ $red: _get-color-value(nth($frags, 1));
25
+ $green: _get-color-value(nth($frags, 2));
26
+ $blue: _get-color-value(nth($frags, 3));
27
+
28
+ @if not $red or not $green or not $blue {
29
+ @return $string;
30
+ }
31
+
32
+ @if $is-alpha {
33
+ @if length($frags) != 4 { @return $string; } // No alpha channel found
34
+ $alpha: _get-color-value(nth($frags, 4));
35
+ @if not $alpha { @return $string; } // Error parsing alpha channel
36
+ @return rgba($red, $green, $blue, $alpha);
37
+ }
38
+
39
+ @return rgb($red, $green, $blue);
40
+ }
41
+ @else {
42
+ $frags: set-nth($frags, length($frags), nth($frags, length($frags)) + $token);
43
+ }
44
+ }
45
+
46
+ @return $string;
47
47
  }
@@ -1,33 +1,33 @@
1
- // Move pointer to position of token
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $source: JSON complete source
4
- // @param [number] $pointer: current pointer
5
- // @param [string] $token: token to reach
6
- // --------------------------------------------------------------------------------
7
- // @throw "Expected $token; found {x}."
8
- // @throw "Expected $token but reached end of stream."
9
- // --------------------------------------------------------------------------------
10
- // @return [number|false] new pointer
11
-
12
- @function _consume($source, $pointer, $token) {
13
- $length: str-length($source);
14
-
15
- @while $pointer <= $length {
16
- $char: str-slice($source, $pointer, $pointer);
17
- $pointer: $pointer + 1;
18
-
19
- @if $char == $token {
20
- @return $pointer;
21
- }
22
-
23
- @else if $char == " " {
24
- // @continue;
25
- }
26
-
27
- @else {
28
- @return _throw("Expected `" + $token + "; ` found `" + $char + "`.", $pointer);
29
- }
30
- }
31
-
32
- @return _throw("Expected `" + $token + "` but reached end of stream.", $pointer);
33
- }
1
+ // Move pointer to position of token
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $source: JSON complete source
4
+ // @param [number] $pointer: current pointer
5
+ // @param [string] $token: token to reach
6
+ // --------------------------------------------------------------------------------
7
+ // @throw "Expected $token; found {x}."
8
+ // @throw "Expected $token but reached end of stream."
9
+ // --------------------------------------------------------------------------------
10
+ // @return [number|false] new pointer
11
+
12
+ @function _consume($source, $pointer, $token) {
13
+ $length: str-length($source);
14
+
15
+ @while $pointer <= $length {
16
+ $char: str-slice($source, $pointer, $pointer);
17
+ $pointer: $pointer + 1;
18
+
19
+ @if $char == $token {
20
+ @return $pointer;
21
+ }
22
+
23
+ @else if $char == " " {
24
+ // @continue;
25
+ }
26
+
27
+ @else {
28
+ @return _throw("Expected `" + $token + "; ` found `" + $char + "`.", $pointer);
29
+ }
30
+ }
31
+
32
+ @return _throw("Expected `" + $token + "` but reached end of stream.", $pointer);
33
+ }
@@ -1,39 +1,39 @@
1
- // Parses a JSON encoded number to find the digits
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $source: JSON complete source
4
- // @param [number] $pointer: current pointer
5
- // --------------------------------------------------------------------------------
6
- // @throw "Unexpected token $token."
7
- // --------------------------------------------------------------------------------
8
- // @return [list|false] (new pointer, parsed number)
9
-
10
- @function _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: null;
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: if($result == null, ($index - 1), $result * 10 + ($index - 1));
27
- }
28
- @else {
29
- @if index('e' '.' ' ' ',' ']' '}', $token) {
30
- @return $pointer, if($result != null, $result / $runs, $result);
31
- }
32
- @return _throw("Unexpected token `" + $token + "`.", $pointer);
33
- }
34
-
35
- $pointer: $pointer + 1;
36
- }
37
-
38
- @return $pointer, if($result != null, $result / $runs, $result);
39
- }
1
+ // Parses a JSON encoded number to find the digits
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $source: JSON complete source
4
+ // @param [number] $pointer: current pointer
5
+ // --------------------------------------------------------------------------------
6
+ // @throw "Unexpected token $token."
7
+ // --------------------------------------------------------------------------------
8
+ // @return [list|false] (new pointer, parsed number)
9
+
10
+ @function _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: null;
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: if($result == null, ($index - 1), $result * 10 + ($index - 1));
27
+ }
28
+ @else {
29
+ @if index('e' '.' ' ' ',' ']' '}', $token) {
30
+ @return $pointer, if($result != null, $result / $runs, $result);
31
+ }
32
+ @return _throw("Unexpected token `" + $token + "`.", $pointer);
33
+ }
34
+
35
+ $pointer: $pointer + 1;
36
+ }
37
+
38
+ @return $pointer, if($result != null, $result / $runs, $result);
39
+ }
@@ -1,51 +1,51 @@
1
- // Parses a JSON encoded number to find the exponent part
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $source: JSON complete source
4
- // @param [number] $pointer: current pointer
5
- // --------------------------------------------------------------------------------
6
- // @throw "Unexpected token $token."
7
- // --------------------------------------------------------------------------------
8
- // @return [list|false] (new pointer, parsed number)
9
-
10
- @function _find-exponent($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: null;
15
- $minus: null;
16
-
17
- @while $pointer <= $length {
18
- $token: str-slice($source, $pointer, $pointer);
19
- $index: index($numbers, $token);
20
-
21
- @if $token == 'e' {
22
- // @continue;
23
- }
24
- @else if $token == '-' {
25
- @if $minus != null {
26
- @return _throw("Unexpected token `-`.", $pointer);
27
- }
28
- $minus: true;
29
- }
30
- @else if $token == '+' {
31
- @if $minus != null {
32
- @return _throw("Unexpected token `+`.", $pointer);
33
- }
34
- $minus: false;
35
- }
36
- @else if $index and $index > 0 {
37
- $result: if($result == null, ($index - 1), $result * 10 + ($index - 1));
38
- }
39
- @else {
40
- @if not index(' ' ',' ']' '}', $token) {
41
- @return _throw("Unexpected token `" + $token + "`.", $pointer);
42
- }
43
-
44
- @return $pointer, if($minus and $result != null, $result * -1, $result);
45
- }
46
-
47
- $pointer: $pointer + 1;
48
- }
49
-
50
- @return $pointer, if($minus and $result != null, $result * -1, $result);
51
- }
1
+ // Parses a JSON encoded number to find the exponent part
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $source: JSON complete source
4
+ // @param [number] $pointer: current pointer
5
+ // --------------------------------------------------------------------------------
6
+ // @throw "Unexpected token $token."
7
+ // --------------------------------------------------------------------------------
8
+ // @return [list|false] (new pointer, parsed number)
9
+
10
+ @function _find-exponent($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: null;
15
+ $minus: null;
16
+
17
+ @while $pointer <= $length {
18
+ $token: str-slice($source, $pointer, $pointer);
19
+ $index: index($numbers, $token);
20
+
21
+ @if $token == 'e' {
22
+ // @continue;
23
+ }
24
+ @else if $token == '-' {
25
+ @if $minus != null {
26
+ @return _throw("Unexpected token `-`.", $pointer);
27
+ }
28
+ $minus: true;
29
+ }
30
+ @else if $token == '+' {
31
+ @if $minus != null {
32
+ @return _throw("Unexpected token `+`.", $pointer);
33
+ }
34
+ $minus: false;
35
+ }
36
+ @else if $index and $index > 0 {
37
+ $result: if($result == null, ($index - 1), $result * 10 + ($index - 1));
38
+ }
39
+ @else {
40
+ @if not index(' ' ',' ']' '}', $token) {
41
+ @return _throw("Unexpected token `" + $token + "`.", $pointer);
42
+ }
43
+
44
+ @return $pointer, if($minus and $result != null, $result * -1, $result);
45
+ }
46
+
47
+ $pointer: $pointer + 1;
48
+ }
49
+
50
+ @return $pointer, if($minus and $result != null, $result * -1, $result);
51
+ }