SassyJSON 1.0.6
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.
- data/CHANGELOG.md +11 -0
- data/README.md +96 -0
- data/lib/SassyJSON.rb +14 -0
- data/src/SassyJSON.scss +2 -0
- data/src/decode/api/_json.scss +26 -0
- data/src/decode/decode.scss +28 -0
- data/src/decode/helpers/all/_throw.scss +11 -0
- data/src/decode/helpers/all/_value.scss +49 -0
- data/src/decode/helpers/color/_color.scss +45 -0
- data/src/decode/helpers/color/_get-color-value.scss +18 -0
- data/src/decode/helpers/color/_hex-to-dec.scss +20 -0
- data/src/decode/helpers/color/_hex.scss +39 -0
- data/src/decode/helpers/color/_hsl.scss +46 -0
- data/src/decode/helpers/color/_rgb.scss +46 -0
- data/src/decode/helpers/map/_consume.scss +33 -0
- data/src/decode/helpers/number/_find-digits.scss +40 -0
- data/src/decode/helpers/number/_find-exponent.scss +46 -0
- data/src/decode/helpers/number/_find-integer.scss +38 -0
- data/src/decode/helpers/number/_pow.scss +22 -0
- data/src/decode/helpers/string/_find-ending-quote.scss +36 -0
- data/src/decode/helpers/string/_length.scss +39 -0
- data/src/decode/helpers/string/_strip-token.scss +16 -0
- data/src/decode/types/_bool.scss +40 -0
- data/src/decode/types/_list.scss +54 -0
- data/src/decode/types/_map.scss +78 -0
- data/src/decode/types/_null.scss +19 -0
- data/src/decode/types/_number.scss +63 -0
- data/src/decode/types/_string.scss +41 -0
- data/src/encode/api/_json.scss +17 -0
- data/src/encode/encode.scss +17 -0
- data/src/encode/helpers/_quote.scss +9 -0
- data/src/encode/mixins/_json.scss +34 -0
- data/src/encode/types/_bool.scss +9 -0
- data/src/encode/types/_color.scss +9 -0
- data/src/encode/types/_list.scss +13 -0
- data/src/encode/types/_map.scss +13 -0
- data/src/encode/types/_null.scss +9 -0
- data/src/encode/types/_number.scss +9 -0
- data/src/encode/types/_string.scss +9 -0
- metadata +119 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
// Will find the first non escaped quote in a JSON String
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $string: to search in
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [number] position of the last non escaped quote
|
6
|
+
|
7
|
+
@function _find-ending-quote($string){
|
8
|
+
$backslash: str-slice("\\", 1, 1); // Dirty hack to have a single backslash
|
9
|
+
$search: $string;
|
10
|
+
|
11
|
+
$end-quote-found: false;
|
12
|
+
$position: 0;
|
13
|
+
|
14
|
+
|
15
|
+
@while not $end-quote-found {
|
16
|
+
$index: str-index($search, '"');
|
17
|
+
|
18
|
+
@if not $index or $index == 0 { // No end of string found
|
19
|
+
@return $index;
|
20
|
+
}
|
21
|
+
|
22
|
+
@else {
|
23
|
+
$position: $position + $index;
|
24
|
+
}
|
25
|
+
|
26
|
+
$char-before-quote: str-slice($search, $index - 1, $index - 1);
|
27
|
+
|
28
|
+
@if $char-before-quote != $backslash {
|
29
|
+
$end-quote-found: true;
|
30
|
+
}
|
31
|
+
|
32
|
+
$search: str-slice($search, $index + 1);
|
33
|
+
}
|
34
|
+
|
35
|
+
@return $position;
|
36
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// Parses a JSON encoded string to see if it's a CSS length
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $string: JSON string
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [number|string] string or number, depending on the match
|
6
|
+
|
7
|
+
@function _length($string) {
|
8
|
+
$strings: 'px' 'cm' 'mm' '%' 'ch' 'pica' 'in' 'em' 'rem' 'pt' 'pc' 'ex' 'vw' 'vh' 'vmin' 'vmax';
|
9
|
+
$units: 1px 1cm 1mm 1% 1ch 1pica 1in 1em 1rem 1pt 1pc 1ex 1vw 1vh 1vmin 1vmax;
|
10
|
+
$number: "";
|
11
|
+
$unit: "";
|
12
|
+
|
13
|
+
@for $i from 1 through str-length($string) {
|
14
|
+
$c: str-slice($string, $i, $i);
|
15
|
+
@if $c == ' ' {
|
16
|
+
@if $number != "" {
|
17
|
+
@return $string;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
@else if index('0' '1' '2' '3' '4' '5' '6' '7' '8' '9' '-' '.', $c) {
|
21
|
+
$number: $number + $c;
|
22
|
+
}
|
23
|
+
@else {
|
24
|
+
@if $number == "" {
|
25
|
+
@return $string;
|
26
|
+
}
|
27
|
+
$unit: $unit + $c;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
$number: nth(_json-decode--number($number, 2), 2);
|
32
|
+
$index: index($strings, to-lower-case($unit));
|
33
|
+
|
34
|
+
@if $index and $index > 0 {
|
35
|
+
@return $number * nth($units, $index);
|
36
|
+
}
|
37
|
+
|
38
|
+
@return $string;
|
39
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// Strip special carriage return characters
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $string: string to parse
|
4
|
+
// @param [string] $char: char to strip
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @return [string] new string
|
7
|
+
|
8
|
+
@function _strip-token($string, $token, $replace) {
|
9
|
+
|
10
|
+
@while str-index($string, $token) and str-index($string, $token) > 0 {
|
11
|
+
$index: str-index($string, $token);
|
12
|
+
$string: str-slice($string, 1, $index - 1) + $replace + str-slice($string, $index + str-length($token));
|
13
|
+
}
|
14
|
+
|
15
|
+
@return $string;
|
16
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// Parses a JSON encoded `true`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $source: JSON complete source
|
4
|
+
// @param [number] $pointer: current pointer
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @throw "Unexpected token `t`."
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return [list|false] (new pointer, true)
|
9
|
+
|
10
|
+
@function _json-decode--true($source, $pointer) {
|
11
|
+
$length: str-length($source);
|
12
|
+
@if $length - $pointer < 2
|
13
|
+
or str-slice($source, $pointer, $pointer) != 'r'
|
14
|
+
or str-slice($source, $pointer + 1, $pointer + 1) != 'u'
|
15
|
+
or str-slice($source, $pointer + 2, $pointer + 2) != 'e' {
|
16
|
+
@return _throw("Unexpected token: `t`.", $pointer);
|
17
|
+
}
|
18
|
+
@return ($pointer + 3, true);
|
19
|
+
}
|
20
|
+
|
21
|
+
// Parses a JSON encoded `false`
|
22
|
+
// --------------------------------------------------------------------------------
|
23
|
+
// @param $source: JSON complete source
|
24
|
+
// @param $pointer: current pointer
|
25
|
+
// --------------------------------------------------------------------------------
|
26
|
+
// @throw "Unexpected token `f`."
|
27
|
+
// --------------------------------------------------------------------------------
|
28
|
+
// @return [list|false] (new pointer, false)
|
29
|
+
|
30
|
+
@function _json-decode--false($source, $pointer) {
|
31
|
+
$length: str-length($source);
|
32
|
+
@if $length - $pointer < 3
|
33
|
+
or str-slice($source, $pointer, $pointer) != 'a'
|
34
|
+
or str-slice($source, $pointer + 1, $pointer + 1) != 'l'
|
35
|
+
or str-slice($source, $pointer + 2, $pointer + 2) != 's'
|
36
|
+
or str-slice($source, $pointer + 3, $pointer + 3) != 'e' {
|
37
|
+
@return _throw("Unexpected token: `f`.", $pointer);
|
38
|
+
}
|
39
|
+
@return ($pointer + 4, false);
|
40
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
// Parses a JSON encoded array
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $source: JSON complete source
|
4
|
+
// @param [number] $pointer: current pointer
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @throw "Unexpected comma in array literal."
|
7
|
+
// @throw "Missing comma in array literal."
|
8
|
+
// @throw "Unterminated array literal."
|
9
|
+
// --------------------------------------------------------------------------------
|
10
|
+
// @return [list|false] (new pointer, parsed list)
|
11
|
+
|
12
|
+
@function _json-decode--list($source, $pointer) {
|
13
|
+
$length: str-length($source);
|
14
|
+
$list: ();
|
15
|
+
$needs-comma: false;
|
16
|
+
|
17
|
+
@if $pointer <= $length and str-slice($source, $pointer, $pointer) == "]" {
|
18
|
+
@return ($pointer + 1, $list);
|
19
|
+
}
|
20
|
+
|
21
|
+
@while $pointer <= $length {
|
22
|
+
$token: str-slice($source, $pointer, $pointer);
|
23
|
+
|
24
|
+
@if $token == "]" {
|
25
|
+
@if not $needs-comma and length($list) != 0 {
|
26
|
+
@return _throw("Unexpected comma in array literal.", $pointer);
|
27
|
+
}
|
28
|
+
|
29
|
+
// Do it the Sass way and destruct a single item array to an element.
|
30
|
+
@return ($pointer + 1, if(length($list) == 1, nth($list, 1), $list));
|
31
|
+
}
|
32
|
+
@else if $token == " " {
|
33
|
+
$pointer: $pointer + 1;
|
34
|
+
}
|
35
|
+
@else if $token == "," {
|
36
|
+
@if not $needs-comma {
|
37
|
+
@return _throw("Unexpected comma in array literal.", $pointer);
|
38
|
+
}
|
39
|
+
$needs-comma: false;
|
40
|
+
$pointer: $pointer + 1;
|
41
|
+
}
|
42
|
+
@else {
|
43
|
+
@if $needs-comma {
|
44
|
+
@return _throw("Missing comma in array literal.", $pointer);
|
45
|
+
}
|
46
|
+
$read: _json-decode--value($source, $pointer);
|
47
|
+
$pointer: nth($read, 1);
|
48
|
+
$list: append($list, nth($read, 2));
|
49
|
+
$needs-comma: true;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
@return _throw("Unterminated array literal.", $pointer);
|
54
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
// Parses a JSON encoded object
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $source: JSON complete source
|
4
|
+
// @param [number] $pointer: current pointer
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @throw "Unexpected comma in object literal."
|
7
|
+
// @throw "Unexpected token $token in object literal."
|
8
|
+
// @throw "Missing comma in object literal."
|
9
|
+
// @throw "Unterminated object literal."
|
10
|
+
// @throw "Consuming token `:` failed."
|
11
|
+
// --------------------------------------------------------------------------------
|
12
|
+
// @return [list|false] (new pointer, map)
|
13
|
+
|
14
|
+
@function _json-decode--map($source, $pointer) {
|
15
|
+
$length: str-length($source);
|
16
|
+
$map: ();
|
17
|
+
$needs-comma: false;
|
18
|
+
|
19
|
+
// Deal with empty map
|
20
|
+
@if $pointer <= $length and str-slice($source, $pointer, $pointer) == "}" {
|
21
|
+
@return ($pointer + 1, $map);
|
22
|
+
}
|
23
|
+
|
24
|
+
@while $pointer <= $length {
|
25
|
+
$token: str-slice($source, $pointer, $pointer);
|
26
|
+
$pointer: $pointer + 1;
|
27
|
+
|
28
|
+
@if $token == "}" {
|
29
|
+
@if not $needs-comma and length($map) != 0 {
|
30
|
+
@return _throw("Unexpected comma in object literal.", $pointer);
|
31
|
+
}
|
32
|
+
@return ($pointer, $map);
|
33
|
+
}
|
34
|
+
|
35
|
+
@else if $token == " " {
|
36
|
+
// @continue;
|
37
|
+
}
|
38
|
+
|
39
|
+
@else if $token == "," {
|
40
|
+
@if not $needs-comma {
|
41
|
+
@return _throw("Unexpected comma in object literal.", $pointer);
|
42
|
+
}
|
43
|
+
$needs-comma: false;
|
44
|
+
}
|
45
|
+
|
46
|
+
@else if $token == '"' {
|
47
|
+
@if $needs-comma {
|
48
|
+
@return _throw("Missing comma in object literal.", $pointer);
|
49
|
+
}
|
50
|
+
|
51
|
+
// Read key
|
52
|
+
$read-key: _json-decode--string($source, $pointer);
|
53
|
+
$pointer: nth($read-key, 1);
|
54
|
+
$key: nth($read-key, 2);
|
55
|
+
|
56
|
+
// Remove colon
|
57
|
+
$pointer: _consume($source, $pointer, ":");
|
58
|
+
@if length($pointer) > 1 { // If consume has failed
|
59
|
+
@return _throw("Consuming token `:` failed.", 0);
|
60
|
+
}
|
61
|
+
|
62
|
+
// Read value
|
63
|
+
$read-value: _json-decode--value($source, $pointer);
|
64
|
+
$pointer: nth($read-value, 1);
|
65
|
+
$value: nth($read-value, 2);
|
66
|
+
|
67
|
+
// Add pair to map
|
68
|
+
$map: map-merge($map, ($key: $value));
|
69
|
+
$needs-comma: true;
|
70
|
+
}
|
71
|
+
|
72
|
+
@else {
|
73
|
+
@return _throw("Unexpected token `" + $token + "` in object literal.", $pointer);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
@return _throw("Unterminated object literal.", $pointer);
|
78
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// Parses a JSON encoded `null`
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $source: JSON complete source
|
4
|
+
// @param [number] $pointer: current pointer
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @throw "Unexpected token `n`."
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return [list|false] (new pointer, null)
|
9
|
+
|
10
|
+
@function _json-decode--null($source, $pointer) {
|
11
|
+
$length: str-length($source);
|
12
|
+
@if $length - $pointer < 2
|
13
|
+
or str-slice($source, $pointer, $pointer) != 'u'
|
14
|
+
or str-slice($source, $pointer + 1, $pointer + 1) != 'l'
|
15
|
+
or str-slice($source, $pointer + 2, $pointer + 2) != 'l' {
|
16
|
+
@return _throw("Unexpected token: `n`.", $pointer);
|
17
|
+
}
|
18
|
+
@return ($pointer + 3, null);
|
19
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
// Parses a JSON encoded number
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $source: JSON complete source
|
4
|
+
// @param [number] $pointer: current pointer
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @throw "Unexpected token $token."
|
7
|
+
// @throw "Unexpected end of stream."
|
8
|
+
// --------------------------------------------------------------------------------
|
9
|
+
// @return [list|false] (new pointer, parsed number)
|
10
|
+
|
11
|
+
@function _json-decode--number($source, $pointer) {
|
12
|
+
$pointer: $pointer - 1; // Move back pointer to begininng of number
|
13
|
+
$allowed: '-' '0' '1' '2' '3' '4' '5' '6' '7' '8' '9'; // Allowed characted to start with
|
14
|
+
$first: str-slice($source, $pointer, $pointer); // First character of the number
|
15
|
+
$minus: $first == '-'; // Is it negative?
|
16
|
+
|
17
|
+
// Early check for errors
|
18
|
+
@if not index($allowed, $first) {
|
19
|
+
@return _throw("Unexpected token `" + $first + "`.", $pointer);
|
20
|
+
}
|
21
|
+
|
22
|
+
// Find the integer part
|
23
|
+
$find-integer: _find-integer($source, $pointer);
|
24
|
+
$pointer: nth($find-integer, 1);
|
25
|
+
$result: nth($find-integer, 2);
|
26
|
+
@if not $result { // Error occured
|
27
|
+
@return $find-integer;
|
28
|
+
}
|
29
|
+
|
30
|
+
// Find digits
|
31
|
+
@if str-slice($source, $pointer, $pointer) == '.' {
|
32
|
+
$find-digits: _find-digits($source, $pointer);
|
33
|
+
$pointer: nth($find-digits, 1);
|
34
|
+
$digits: nth($find-digits, 2);
|
35
|
+
|
36
|
+
@if $digits == null { // Empty digits, throw error
|
37
|
+
@return _throw("Unexpected end of stream.", $pointer);
|
38
|
+
}
|
39
|
+
@else if $digits == false { // Error occured, return it
|
40
|
+
@return $find-digits;
|
41
|
+
}
|
42
|
+
|
43
|
+
$result: $result + $digits;
|
44
|
+
}
|
45
|
+
|
46
|
+
// Find exponent
|
47
|
+
@if to-lower-case(str-slice($source, $pointer, $pointer)) == 'e' {
|
48
|
+
$find-exponent: _find-exponent($source, $pointer);
|
49
|
+
$pointer: nth($find-exponent, 1);
|
50
|
+
$exponent: nth($find-exponent, 2);
|
51
|
+
|
52
|
+
@if $exponent == null { // Empty exponent, throw error
|
53
|
+
@return _throw("Unexpected end of stream.", $pointer);
|
54
|
+
}
|
55
|
+
@else if $exponent == false { // Error occured, return it
|
56
|
+
@return $find-exponent;
|
57
|
+
}
|
58
|
+
|
59
|
+
$result: $result * _pow(10, $exponent);
|
60
|
+
}
|
61
|
+
|
62
|
+
@return ($pointer, if($minus, $result * -1, $result));
|
63
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
// Parses a JSON encoded string
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param [string] $source: JSON complete source
|
4
|
+
// @param [number] $pointer: current pointer
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @throw "Unterminated string."
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return [list|false] (new pointer, parsed string / color / length)
|
9
|
+
|
10
|
+
@function _json-decode--string($source, $pointer) {
|
11
|
+
// Check for the end of the string
|
12
|
+
$temp: str-slice($source, $pointer);
|
13
|
+
$end: _find-ending-quote($temp);
|
14
|
+
$string: "";
|
15
|
+
|
16
|
+
// If no end is found
|
17
|
+
@if not $end or $end == 0 {
|
18
|
+
@return _throw("Unterminated string.", $pointer);
|
19
|
+
}
|
20
|
+
|
21
|
+
// If string is not empty
|
22
|
+
@else if $end > 1 {
|
23
|
+
$string: str-slice($temp, 1, $end - 1);
|
24
|
+
|
25
|
+
$cr: "
|
26
|
+
";
|
27
|
+
$string: _strip-token($string, "\r", $cr);
|
28
|
+
$string: _strip-token($string, "\n", $cr);
|
29
|
+
$string: _strip-token($string, '\\\"', '"');
|
30
|
+
|
31
|
+
// Test whether the string could be a CSS length
|
32
|
+
$string: _length($string);
|
33
|
+
|
34
|
+
// Test whether the string could be a CSS color
|
35
|
+
@if type-of($string) == string {
|
36
|
+
$string: _color($string);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
@return ($pointer + $end, $string);
|
41
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// Delay the encoding of ta literal to JSON
|
2
|
+
// to a type-specific method
|
3
|
+
// --------------------------------------------------------------------------------
|
4
|
+
// @param $value: value to be stringified
|
5
|
+
// --------------------------------------------------------------------------------
|
6
|
+
// @throw "Unknown type for $value ({x})."
|
7
|
+
// --------------------------------------------------------------------------------
|
8
|
+
// @return [string|false] JSON encoded string
|
9
|
+
|
10
|
+
@function json-encode($value) {
|
11
|
+
$type: type-of($value);
|
12
|
+
@if function_exists('_json-encode--#{$type}') {
|
13
|
+
@return call('_json-encode--#{$type}', $value);
|
14
|
+
}
|
15
|
+
@warn "Unknown type for #{$value} (#{$type}).";
|
16
|
+
@return false;
|
17
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// Helpers
|
2
|
+
@import "helpers/quote";
|
3
|
+
|
4
|
+
// Type specific encoding functions
|
5
|
+
@import "types/bool";
|
6
|
+
@import "types/color";
|
7
|
+
@import "types/list";
|
8
|
+
@import "types/map";
|
9
|
+
@import "types/number";
|
10
|
+
@import "types/string";
|
11
|
+
@import "types/null";
|
12
|
+
|
13
|
+
// Public API
|
14
|
+
@import "api/json";
|
15
|
+
|
16
|
+
// Mixin to pass the string to the DOM
|
17
|
+
@import "mixins/json";
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Proof quote a value
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $value: value to be quoted
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [string] quoted value
|
6
|
+
|
7
|
+
@function _proof-quote($value) {
|
8
|
+
@return '"' + $value + '"';
|
9
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// JSON.stringify a value and pass it as a font-family of head element
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $value: value to be stringified
|
4
|
+
// @parem $flag: output driver
|
5
|
+
|
6
|
+
@mixin json-encode($value, $flag: all) {
|
7
|
+
$flag: if(not index(all regular media comment, $flag), all, $flag);
|
8
|
+
$json: json-encode($value);
|
9
|
+
|
10
|
+
@if $flag == comment or $flag == all {
|
11
|
+
/*! json-encode: #{$json} */
|
12
|
+
}
|
13
|
+
|
14
|
+
@if $flag == regular or $flag == all {
|
15
|
+
// All browsers except IE8-
|
16
|
+
body::before {
|
17
|
+
display: none !important;
|
18
|
+
content: json-encode($value);
|
19
|
+
}
|
20
|
+
|
21
|
+
// All browsers except Opera (Presto based)
|
22
|
+
head {
|
23
|
+
font-family: json-encode($value);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
@if $flag == media or $flag == all {
|
28
|
+
@media -json-encode {
|
29
|
+
json {
|
30
|
+
json: $json;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Encode a bool to JSON
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $bool: bool to be encoded
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [bool] boolean
|
6
|
+
|
7
|
+
@function _json-encode--bool($boolean) {
|
8
|
+
@return $boolean;
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Encode a color to JSON
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $color: color to be encoded
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [string] encoded color
|
6
|
+
|
7
|
+
@function _json-encode--color($color) {
|
8
|
+
@return _proof-quote($color);
|
9
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Encode a list to JSON
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $list: list to be encoded
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [string] encoded list
|
6
|
+
|
7
|
+
@function _json-encode--list($list) {
|
8
|
+
$str: "";
|
9
|
+
@each $item in $list {
|
10
|
+
$str: $str + ', ' + json-encode($item);
|
11
|
+
}
|
12
|
+
@return '[' + str-slice($str, 3) + ']';
|
13
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Encode a map to JSON
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $map: map to be encoded
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [string] encoded map
|
6
|
+
|
7
|
+
@function _json-encode--map($map) {
|
8
|
+
$str: "";
|
9
|
+
@each $key, $value in $map {
|
10
|
+
$str: $str + ', ' + _proof-quote($key) + ': ' + json-encode($value);
|
11
|
+
}
|
12
|
+
@return '{' + str-slice($str, 3) + '}';
|
13
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Encode `null` to JSON
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $null: `null`
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [string] `null`
|
6
|
+
|
7
|
+
@function _json-encode--null($null) {
|
8
|
+
@return "null";
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Encode a number to JSON
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $number: number to be encoded
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [string] encoded number
|
6
|
+
|
7
|
+
@function _json-encode--number($number) {
|
8
|
+
@return if(unitless($number), $number, _proof-quote($number));
|
9
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Encode a string to JSON
|
2
|
+
// --------------------------------------------------------------------------------
|
3
|
+
// @param $string: string to be encoded
|
4
|
+
// --------------------------------------------------------------------------------
|
5
|
+
// @return [string] encoded string
|
6
|
+
|
7
|
+
@function _json-encode--string($string) {
|
8
|
+
@return _proof-quote($string);
|
9
|
+
}
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SassyJSON
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hugo Giraudel
|
9
|
+
- Fabrice Weinberg
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sass
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.3.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.3.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: compass
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
description: Sass API for JSON
|
48
|
+
email:
|
49
|
+
- hugo.giraudel@gmail.com
|
50
|
+
- fabrice@weinberg.me
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- README.md
|
56
|
+
- CHANGELOG.md
|
57
|
+
- lib/SassyJSON.rb
|
58
|
+
- src/decode/api/_json.scss
|
59
|
+
- src/decode/decode.scss
|
60
|
+
- src/decode/helpers/all/_throw.scss
|
61
|
+
- src/decode/helpers/all/_value.scss
|
62
|
+
- src/decode/helpers/color/_color.scss
|
63
|
+
- src/decode/helpers/color/_get-color-value.scss
|
64
|
+
- src/decode/helpers/color/_hex-to-dec.scss
|
65
|
+
- src/decode/helpers/color/_hex.scss
|
66
|
+
- src/decode/helpers/color/_hsl.scss
|
67
|
+
- src/decode/helpers/color/_rgb.scss
|
68
|
+
- src/decode/helpers/map/_consume.scss
|
69
|
+
- src/decode/helpers/number/_find-digits.scss
|
70
|
+
- src/decode/helpers/number/_find-exponent.scss
|
71
|
+
- src/decode/helpers/number/_find-integer.scss
|
72
|
+
- src/decode/helpers/number/_pow.scss
|
73
|
+
- src/decode/helpers/string/_find-ending-quote.scss
|
74
|
+
- src/decode/helpers/string/_length.scss
|
75
|
+
- src/decode/helpers/string/_strip-token.scss
|
76
|
+
- src/decode/types/_bool.scss
|
77
|
+
- src/decode/types/_list.scss
|
78
|
+
- src/decode/types/_map.scss
|
79
|
+
- src/decode/types/_null.scss
|
80
|
+
- src/decode/types/_number.scss
|
81
|
+
- src/decode/types/_string.scss
|
82
|
+
- src/encode/api/_json.scss
|
83
|
+
- src/encode/encode.scss
|
84
|
+
- src/encode/helpers/_quote.scss
|
85
|
+
- src/encode/mixins/_json.scss
|
86
|
+
- src/encode/types/_bool.scss
|
87
|
+
- src/encode/types/_color.scss
|
88
|
+
- src/encode/types/_list.scss
|
89
|
+
- src/encode/types/_map.scss
|
90
|
+
- src/encode/types/_null.scss
|
91
|
+
- src/encode/types/_number.scss
|
92
|
+
- src/encode/types/_string.scss
|
93
|
+
- src/SassyJSON.scss
|
94
|
+
homepage: https://github.com/HugoGiraudel/SassyJSON/
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.3.6
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project: SassyJSON
|
114
|
+
rubygems_version: 1.8.24
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: SassyJSON is a Sass-powered API for JSON. It provides you the classic json-encode
|
118
|
+
and json-decode directly from your Sass files.
|
119
|
+
test_files: []
|