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
data/lib/SassyJSON.rb CHANGED
@@ -1,14 +1,12 @@
1
- require 'compass'
2
- extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
3
- Compass::Frameworks.register('SassyJSON', :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 SassyJSON
8
- VERSION = "1.1.1"
9
- DATE = "2014-01-29"
10
- end
11
-
12
- module Sass::Script::Functions
13
-
14
- end
1
+ require 'compass'
2
+ require 'JsonImporter'
3
+
4
+ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
+ Compass::Frameworks.register('SassyJSON', :path => extension_path)
6
+
7
+ # Version is a number. If a version contains alphas, it will be created as a prerelease version
8
+ # Date is in the form of YYYY-MM-DD
9
+ module SassyJSON
10
+ VERSION = "1.1.2"
11
+ DATE = "2014-01-29"
12
+ end
@@ -1,5 +1,5 @@
1
- // Encoder
2
- @import "encode/encode";
3
-
4
- // Decoder
5
- @import "decode/decode";
1
+ // Encoder
2
+ @import "encode/encode";
3
+
4
+ // Decoder
5
+ @import "decode/decode";
@@ -1,26 +1,26 @@
1
- // Parse a JSON string
2
- // --------------------------------------------------------------------------------
3
- // @param $json: JSON string to parse
4
- // --------------------------------------------------------------------------------
5
- // @throw "Input string may not be null"
6
- // --------------------------------------------------------------------------------
7
- // @return [literal|false]
8
-
9
- @function json-decode($json) {
10
- $length: str-length($json);
11
- $pointer: 1;
12
- $value: null;
13
-
14
- @if $json == null {
15
- @return _throw("Input string may not be null.", $pointer);
16
- }
17
-
18
- @while $value != false // Stop if error
19
- and $pointer <= $length {
20
- $read: _json-decode--value($json, $pointer);
21
- $pointer: nth($read, 1);
22
- $value: nth($read, 2);
23
- }
24
-
25
- @return $value;
26
- }
1
+ // Parse a JSON string
2
+ // --------------------------------------------------------------------------------
3
+ // @param $json: JSON string to parse
4
+ // --------------------------------------------------------------------------------
5
+ // @throw "Input string may not be null"
6
+ // --------------------------------------------------------------------------------
7
+ // @return [literal|false]
8
+
9
+ @function json-decode($json) {
10
+ $length: str-length($json);
11
+ $pointer: 1;
12
+ $value: null;
13
+
14
+ @if $json == null {
15
+ @return _throw("Input string may not be null.", $pointer);
16
+ }
17
+
18
+ @while $value != false // Stop if error
19
+ and $pointer <= $length {
20
+ $read: _json-decode--value($json, $pointer);
21
+ $pointer: nth($read, 1);
22
+ $value: nth($read, 2);
23
+ }
24
+
25
+ @return $value;
26
+ }
@@ -1,28 +1,28 @@
1
- // Helpers
2
- @import "helpers/all/throw";
3
- @import "helpers/all/value";
4
- @import "helpers/map/consume";
5
- @import "helpers/number/pow";
6
- @import "helpers/number/find-digits";
7
- @import "helpers/number/find-integer";
8
- @import "helpers/number/find-exponent";
9
- @import "helpers/color/color";
10
- @import "helpers/color/get-color-value";
11
- @import "helpers/color/rgb";
12
- @import "helpers/color/hsl";
13
- @import "helpers/color/hex";
14
- @import "helpers/color/hex-to-dec";
15
- @import "helpers/string/length";
16
- @import "helpers/string/strip-token";
17
- @import "helpers/string/find-ending-quote";
18
-
19
- // Type specific decoding functions
20
- @import "types/bool";
21
- @import "types/null";
22
- @import "types/list";
23
- @import "types/map";
24
- @import "types/number";
25
- @import "types/string";
26
-
27
- // Public API
28
- @import "api/json";
1
+ // Helpers
2
+ @import "helpers/all/throw";
3
+ @import "helpers/all/value";
4
+ @import "helpers/map/consume";
5
+ @import "helpers/number/pow";
6
+ @import "helpers/number/find-digits";
7
+ @import "helpers/number/find-integer";
8
+ @import "helpers/number/find-exponent";
9
+ @import "helpers/color/color";
10
+ @import "helpers/color/get-color-value";
11
+ @import "helpers/color/rgb";
12
+ @import "helpers/color/hsl";
13
+ @import "helpers/color/hex";
14
+ @import "helpers/color/hex-to-dec";
15
+ @import "helpers/string/length";
16
+ @import "helpers/string/strip-token";
17
+ @import "helpers/string/find-ending-quote";
18
+
19
+ // Type specific decoding functions
20
+ @import "types/bool";
21
+ @import "types/null";
22
+ @import "types/list";
23
+ @import "types/map";
24
+ @import "types/number";
25
+ @import "types/string";
26
+
27
+ // Public API
28
+ @import "api/json";
@@ -1,11 +1,11 @@
1
- // Logs an error at `$pointer` with `$string` message
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $string: error message
4
- // @param [number] $pointer: pointer position
5
- // --------------------------------------------------------------------------------
6
- // @return [list] (pointer, false)
7
-
8
- @function _throw($string, $pointer) {
9
- @warn "ERROR::#{$pointer}::#{$string}";
10
- @return $pointer, false;
11
- }
1
+ // Logs an error at `$pointer` with `$string` message
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $string: error message
4
+ // @param [number] $pointer: pointer position
5
+ // --------------------------------------------------------------------------------
6
+ // @return [list] (pointer, false)
7
+
8
+ @function _throw($string, $pointer) {
9
+ @warn "ERROR::#{$pointer}::#{$string}";
10
+ @return $pointer, false;
11
+ }
@@ -1,49 +1,49 @@
1
- // Delay parsing to type-specific function
2
- // according to found character
3
- // --------------------------------------------------------------------------------
4
- // @param [string] $source: JSON complete source
5
- // @param [number] $pointer: current pointer
6
- // --------------------------------------------------------------------------------
7
- // @throw "Unexpected token $token."
8
- // @throw "Empty JSON string."
9
- // --------------------------------------------------------------------------------
10
- // @return [list|false] (new pointer, parsed value)
11
-
12
- @function _json-decode--value($source, $pointer) {
13
- $length: str-length($source);
14
-
15
- @while $pointer <= $length {
16
- $token: str-slice($source, $pointer, $pointer);
17
- $pointer: $pointer + 1;
18
-
19
- @if $token == '{' {
20
- @return _json-decode--map($source, $pointer);
21
- }
22
- @else if $token == '[' {
23
- @return _json-decode--list($source, $pointer);
24
- }
25
- @else if $token == 't' {
26
- @return _json-decode--true($source, $pointer);
27
- }
28
- @else if $token == 'f' {
29
- @return _json-decode--false($source, $pointer);
30
- }
31
- @else if $token == '"' {
32
- @return _json-decode--string($source, $pointer);
33
- }
34
- @else if $token == 'n' {
35
- @return _json-decode--null($source, $pointer);
36
- }
37
- @else if index('1' '2' '3' '4' '5' '6' '7' '8' '9' '0' '-' '.', $token) {
38
- @return _json-decode--number($source, $pointer);
39
- }
40
- @else if $token == ' ' {
41
- // @continue;
42
- }
43
- @else {
44
- @return _throw("Unexpected token `" + $token + "`.", $pointer);
45
- }
46
- }
47
-
48
- @return _throw("Empty JSON string.", $pointer);
49
- }
1
+ // Delay parsing to type-specific function
2
+ // according to found character
3
+ // --------------------------------------------------------------------------------
4
+ // @param [string] $source: JSON complete source
5
+ // @param [number] $pointer: current pointer
6
+ // --------------------------------------------------------------------------------
7
+ // @throw "Unexpected token $token."
8
+ // @throw "Empty JSON string."
9
+ // --------------------------------------------------------------------------------
10
+ // @return [list|false] (new pointer, parsed value)
11
+
12
+ @function _json-decode--value($source, $pointer) {
13
+ $length: str-length($source);
14
+
15
+ @while $pointer <= $length {
16
+ $token: str-slice($source, $pointer, $pointer);
17
+ $pointer: $pointer + 1;
18
+
19
+ @if $token == '{' {
20
+ @return _json-decode--map($source, $pointer);
21
+ }
22
+ @else if $token == '[' {
23
+ @return _json-decode--list($source, $pointer);
24
+ }
25
+ @else if $token == 't' {
26
+ @return _json-decode--true($source, $pointer);
27
+ }
28
+ @else if $token == 'f' {
29
+ @return _json-decode--false($source, $pointer);
30
+ }
31
+ @else if $token == '"' {
32
+ @return _json-decode--string($source, $pointer);
33
+ }
34
+ @else if $token == 'n' {
35
+ @return _json-decode--null($source, $pointer);
36
+ }
37
+ @else if index('1' '2' '3' '4' '5' '6' '7' '8' '9' '0' '-' '.', $token) {
38
+ @return _json-decode--number($source, $pointer);
39
+ }
40
+ @else if $token == ' ' {
41
+ // @continue;
42
+ }
43
+ @else {
44
+ @return _throw("Unexpected token `" + $token + "`.", $pointer);
45
+ }
46
+ }
47
+
48
+ @return _throw("Empty JSON string.", $pointer);
49
+ }
@@ -1,50 +1,50 @@
1
- // Parses a JSON encoded string to see if it's a CSS color
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $string: JSON string
4
- // --------------------------------------------------------------------------------
5
- // @return [color|string] string or number, depending on the match
6
-
7
- @function _color($string) {
8
- @if type-of($string) == color {
9
- @return $string;
10
- }
11
-
12
- $string-lower: to-lower-case($string);
13
- $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;
14
- $keywords: ();
15
-
16
- // Filling $keywords with stringified color keywords
17
- @each $color in $colors {
18
- $keywords: append($keywords, $color + "");
19
- }
20
-
21
- // Deal with inherit keyword
22
- @if $string-lower == "inherit" {
23
- @return unquote($string);
24
- }
25
-
26
- // Deal with color keywords
27
- @if index($keywords, $string-lower) {
28
- @return nth($colors, index($keywords, $string-lower));
29
- }
30
-
31
- // Deal with hexadecimal triplets
32
- @else if str-slice($string-lower, 1, 1) == '#' {
33
- @return _from-hex($string);
34
- }
35
-
36
- // Deal with rgb(a) colors
37
- @else if str-slice($string-lower, 1, 3) == 'rgb' {
38
- @return _from-rgb($string);
39
- }
40
-
41
- // Deal with hsl(a) colors
42
- @else if str-slice($string-lower, 1, 3) == 'hsl' {
43
- @return _from-hsl($string);
44
- }
45
-
46
- // Return string
47
- @else {
48
- @return $string;
49
- }
50
- }
1
+ // Parses a JSON encoded string to see if it's a CSS color
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $string: JSON string
4
+ // --------------------------------------------------------------------------------
5
+ // @return [color|string] string or number, depending on the match
6
+
7
+ @function _color($string) {
8
+ @if type-of($string) == color {
9
+ @return $string;
10
+ }
11
+
12
+ $string-lower: to-lower-case($string);
13
+ $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;
14
+ $keywords: ();
15
+
16
+ // Filling $keywords with stringified color keywords
17
+ @each $color in $colors {
18
+ $keywords: append($keywords, $color + "");
19
+ }
20
+
21
+ // Deal with inherit keyword
22
+ @if $string-lower == "inherit" {
23
+ @return unquote($string);
24
+ }
25
+
26
+ // Deal with color keywords
27
+ @if index($keywords, $string-lower) {
28
+ @return nth($colors, index($keywords, $string-lower));
29
+ }
30
+
31
+ // Deal with hexadecimal triplets
32
+ @else if str-slice($string-lower, 1, 1) == '#' {
33
+ @return _from-hex($string);
34
+ }
35
+
36
+ // Deal with rgb(a) colors
37
+ @else if str-slice($string-lower, 1, 3) == 'rgb' {
38
+ @return _from-rgb($string);
39
+ }
40
+
41
+ // Deal with hsl(a) colors
42
+ @else if str-slice($string-lower, 1, 3) == 'hsl' {
43
+ @return _from-hsl($string);
44
+ }
45
+
46
+ // Return string
47
+ @else {
48
+ @return $string;
49
+ }
50
+ }
@@ -1,22 +1,22 @@
1
- // Cast a stringified number / stringified percentage into number type
2
- // --------------------------------------------------------------------------------
3
- // @param [string] $string: JSON 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(
18
- $last == '%',
19
- nth(_json-decode--number(str-slice($string, 1, -2), 2), 2) * 1%,
20
- nth(_json-decode--number($string, 2), 2)
21
- );
22
- }
1
+ // Cast a stringified number / stringified percentage into number type
2
+ // --------------------------------------------------------------------------------
3
+ // @param [string] $string: JSON 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(
18
+ $last == '%',
19
+ nth(_json-decode--number(str-slice($string, 1, -2), 2), 2) * 1%,
20
+ nth(_json-decode--number($string, 2), 2)
21
+ );
22
+ }
@@ -1,20 +1,20 @@
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;
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
20
  }