SassyJSON 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cf04a52495a225d84b9f238e9fb8f33209ae5a3
4
- data.tar.gz: 5ecabfe827ede30ad3ba986cc1f7d82379c42787
3
+ metadata.gz: b252de6ac6970e21a3b2cdcdfecbc263064be64d
4
+ data.tar.gz: 98888fa1e6ace45183f65b96809eb4945a211376
5
5
  SHA512:
6
- metadata.gz: 828cb801f2757a8b9e9bd9115031e1928263df28fba4f5337fe1d6ce336d93119ed544f94108e96a3f06cc0338773e9d66ccaa2f33b2c7bd233f8d09b0ac6520
7
- data.tar.gz: 59bf68fe6d86dc866c27ad802c93afda71aa82ddd8723e477b6955df8899ac1ec44d50cb8b9aa057d5c4d7f82a252f54d7bb4813e71065f408f4c1ef0e821128
6
+ metadata.gz: ed3b1b5469126f55682340b2f0957ff2bcc13faa9c289a280e35c3a4c97c960627b50941378dd1dfa1c5e611719627be10151946b849e91762d94e54cad492b0
7
+ data.tar.gz: c319e4e58baa7e2cd4316a227ac2809eb6a9ae67fb9e413ad537e65298b81d18b5c97c13358d2afa94216d02ce9274b9e10cedb709a6aedb87ba596c666e94b1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Changelog
2
2
 
3
+ * `1.0.11`: fixing an issue with scientific number parsing
4
+ * `1.0.10`: improving number and string helpers
3
5
  * `1.0.9`: fixing a bug in `_find-exponent`
4
6
  * `1.0.8`: fixing a major issue in Ruby Gem
5
7
  * `1.0.7`: minor fixes and stable Ruby Gem
data/lib/SassyJSON.rb CHANGED
@@ -5,7 +5,7 @@ Compass::Frameworks.register('SassyJSON', :path => extension_path)
5
5
  # Version is a number. If a version contains alphas, it will be created as a prerelease version
6
6
  # Date is in the form of YYYY-MM-DD
7
7
  module SassyJSON
8
- VERSION = "1.0.10"
8
+ VERSION = "1.0.11"
9
9
  DATE = "2014-01-23"
10
10
  end
11
11
 
@@ -9,32 +9,37 @@
9
9
  @return $string;
10
10
  }
11
11
 
12
- $string: to-lower-case($string);
13
- $keywords: "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
- $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;
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
+ }
15
20
 
16
21
  // Deal with inherit keyword
17
- @if $string == "inherit" {
22
+ @if $string-lower == "inherit" {
18
23
  @return unquote($string);
19
24
  }
20
25
 
21
26
  // Deal with color keywords
22
- @if index($keywords, $string) {
23
- @return nth($colors, index($keywords, $string));
27
+ @if index($keywords, $string-lower) {
28
+ @return nth($colors, index($keywords, $string-lower));
24
29
  }
25
30
 
26
31
  // Deal with hexadecimal triplets
27
- @else if str-slice($string, 1, 1) == '#' {
32
+ @else if str-slice($string-lower, 1, 1) == '#' {
28
33
  @return _from-hex($string);
29
34
  }
30
35
 
31
36
  // Deal with rgb(a) colors
32
- @else if str-slice($string, 1, 3) == 'rgb' {
37
+ @else if str-slice($string-lower, 1, 3) == 'rgb' {
33
38
  @return _from-rgb($string);
34
39
  }
35
40
 
36
41
  // Deal with hsl(a) colors
37
- @else if str-slice($string, 1, 3) == 'hsl' {
42
+ @else if str-slice($string-lower, 1, 3) == 'hsl' {
38
43
  @return _from-hsl($string);
39
44
  }
40
45
 
@@ -6,10 +6,14 @@
6
6
 
7
7
  @function _get-color-value($string) {
8
8
  $first: str-slice($string, 1, 1);
9
+
10
+ // Pad <1 values with a leading 0
9
11
  @if $first == '.' {
10
12
  $string: '0' + $string;
11
13
  }
14
+
12
15
  $last: str-slice($string, -1, -1);
16
+
13
17
  @return if(
14
18
  $last == '%',
15
19
  nth(_json-decode--number(str-slice($string, 1, -2), 2), 2) * 1%,
@@ -5,6 +5,7 @@
5
5
  // @return [color|string] string or hex color depending on the match
6
6
 
7
7
  @function _from-hex($string) {
8
+ $string-lower: to-lower-case($string);
8
9
  $r: ""; $g: ""; $b: "";
9
10
  $hex: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f";
10
11
  $length: str-length($string);
@@ -17,7 +18,7 @@
17
18
 
18
19
  // Loop from the second character (omitting #)
19
20
  @for $i from 2 through $length {
20
- $c: to-lower-case(str-slice($string, $i, $i));
21
+ $c: str-slice($string-lower, $i, $i);
21
22
 
22
23
  // If wrong character, return
23
24
  @if not index($hex, $c) {
@@ -6,12 +6,13 @@
6
6
 
7
7
  @function _from-hsl($string) {
8
8
  $frags: ();
9
- $is-alpha: str-slice($string, 4, 4) == 'a';
10
- $start: str-index($string, "(");
9
+ $string-lower: to-lower-case($string);
10
+ $is-alpha: str-slice($string-lower, 4, 4) == 'a';
11
11
  $length: str-length($string);
12
+ $start: str-index($string, "(");
12
13
 
13
14
  @for $i from $start through $length {
14
- $token: str-slice($string, $i, $i);
15
+ $token: str-slice($string-lower, $i, $i);
15
16
  @if $token == ' ' {
16
17
  // @continue;
17
18
  }
@@ -5,13 +5,14 @@
5
5
  // @return [color|string] string or rgb(a) color depending on the match
6
6
 
7
7
  @function _from-rgb($string) {
8
+ $string-lower: to-lower-case($string);
8
9
  $frags: ();
9
- $is-alpha: str-slice($string, 4, 4) == 'a';
10
+ $is-alpha: str-slice($string-lower, 4, 4) == 'a';
10
11
  $start: str-index($string, "(");
11
12
  $length: str-length($string);
12
13
 
13
14
  @for $i from $start through $length {
14
- $token: str-slice($string, $i, $i);
15
+ $token: str-slice($string-lower, $i, $i);
15
16
  @if $token == ' ' {
16
17
  // @continue;
17
18
  }
@@ -8,13 +8,14 @@
8
8
  // @return [list|false] (new pointer, parsed number)
9
9
 
10
10
  @function _find-digits($source, $pointer) {
11
+ $source: to-lower-case($source);
11
12
  $length: str-length($source);
12
13
  $numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
13
14
  $result: null;
14
15
  $runs: 1;
15
16
 
16
17
  @while $pointer <= $length {
17
- $token: to-lower-case(str-slice($source, $pointer, $pointer));
18
+ $token: str-slice($source, $pointer, $pointer);
18
19
  $index: index($numbers, $token);
19
20
 
20
21
  @if $token == '.' {
@@ -8,22 +8,29 @@
8
8
  // @return [list|false] (new pointer, parsed number)
9
9
 
10
10
  @function _find-exponent($source, $pointer) {
11
+ $source: to-lower-case($source);
11
12
  $length: str-length($source);
12
13
  $numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
13
14
  $result: null;
14
- $minus: false;
15
+ $minus: null;
15
16
 
16
17
  @while $pointer <= $length {
17
- $token: to-lower-case(str-slice($source, $pointer, $pointer));
18
+ $token: str-slice($source, $pointer, $pointer);
18
19
  $index: index($numbers, $token);
19
20
 
20
21
  @if $token == 'e' {
21
22
  // @continue;
22
23
  }
23
24
  @else if $token == '-' {
25
+ @if $minus != null {
26
+ @return _throw("Unexpected token `-`.", $pointer);
27
+ }
24
28
  $minus: true;
25
29
  }
26
30
  @else if $token == '+' {
31
+ @if $minus != null {
32
+ @return _throw("Unexpected token `+`.", $pointer);
33
+ }
27
34
  $minus: false;
28
35
  }
29
36
  @else if $index and $index > 0 {
@@ -8,12 +8,13 @@
8
8
  // @return [list|false] (new pointer, parsed number)
9
9
 
10
10
  @function _find-integer($source, $pointer) {
11
+ $source: to-lower-case($source);
11
12
  $length: str-length($source);
12
13
  $numbers: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
13
14
  $result: 0;
14
15
 
15
16
  @while $pointer <= $length {
16
- $token: to-lower-case(str-slice($source, $pointer, $pointer));
17
+ $token: str-slice($source, $pointer, $pointer);
17
18
  $index: index($numbers, $token);
18
19
 
19
20
  @if $token == '-' {
@@ -5,6 +5,10 @@
5
5
  // @return [number|string] string or number, depending on the match
6
6
 
7
7
  @function _length($string) {
8
+ @if type-of($string) == number {
9
+ @return $string;
10
+ }
11
+
8
12
  $strings: 'px' 'cm' 'mm' '%' 'ch' 'pica' 'in' 'em' 'rem' 'pt' 'pc' 'ex' 'vw' 'vh' 'vmin' 'vmax';
9
13
  $units: 1px 1cm 1mm 1% 1ch 1pica 1in 1em 1rem 1pt 1pc 1ex 1vw 1vh 1vmin 1vmax;
10
14
  $number: "";
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SassyJSON
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugo Giraudel