SassyStrings 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG.md +1 -0
  2. data/README.md +4 -4
  3. data/lib/SassyStrings.rb +2 -2
  4. data/stylesheets/private/_all.scss +2 -2
  5. data/stylesheets/private/_char-at.scss +7 -15
  6. data/stylesheets/private/_levenshtein.scss +63 -84
  7. data/stylesheets/private/_str-count.scss +15 -23
  8. data/stylesheets/private/_str-ends-with.scss +6 -14
  9. data/stylesheets/private/_str-explode.scss +28 -35
  10. data/stylesheets/private/_str-implode.scss +10 -18
  11. data/stylesheets/private/_str-last-index.scss +6 -14
  12. data/stylesheets/private/_str-lcfirst.scss +5 -13
  13. data/stylesheets/private/_str-pad.scss +10 -19
  14. data/stylesheets/private/_str-printf.scss +9 -18
  15. data/stylesheets/private/_str-repeat.scss +6 -14
  16. data/stylesheets/private/_str-replace.scss +11 -29
  17. data/stylesheets/private/_str-reverse.scss +7 -15
  18. data/stylesheets/private/_str-rot.scss +9 -18
  19. data/stylesheets/private/_str-shuffle.scss +17 -31
  20. data/stylesheets/private/_str-starts-with.scss +5 -13
  21. data/stylesheets/private/_str-trim.scss +5 -13
  22. data/stylesheets/private/_str-ucfirst.scss +5 -13
  23. data/stylesheets/private/_str-word-count.scss +6 -14
  24. data/stylesheets/private/_stringify.scss +13 -22
  25. data/stylesheets/public/_all.scss +3 -2
  26. data/stylesheets/public/_char-at.scss +12 -28
  27. data/stylesheets/public/_levenshtein.scss +3 -18
  28. data/stylesheets/public/_str-count.scss +8 -23
  29. data/stylesheets/public/_str-ends-with.scss +2 -17
  30. data/stylesheets/public/_str-explode.scss +3 -18
  31. data/stylesheets/public/_str-implode.scss +5 -17
  32. data/stylesheets/public/_str-last-index.scss +3 -18
  33. data/stylesheets/public/_str-lcfirst.scss +2 -15
  34. data/stylesheets/public/_str-pad.scss +8 -22
  35. data/stylesheets/public/_str-printf.scss +2 -16
  36. data/stylesheets/public/_str-repeat.scss +3 -18
  37. data/stylesheets/public/_str-replace.scss +7 -30
  38. data/stylesheets/public/_str-reverse.scss +2 -15
  39. data/stylesheets/public/_str-rot.scss +3 -18
  40. data/stylesheets/public/_str-shuffle.scss +6 -17
  41. data/stylesheets/public/_str-starts-with.scss +2 -17
  42. data/stylesheets/public/_str-trim.scss +2 -15
  43. data/stylesheets/public/_str-ucfirst.scss +2 -15
  44. data/stylesheets/public/_str-word-count.scss +6 -19
  45. data/stylesheets/public/_stringify.scss +2 -14
  46. metadata +45 -39
  47. checksums.yaml +0 -7
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ * `1.1.4`: improved `str-replace` and added SassDoc compliant comments
3
4
  * `1.1.3`: bumped Sass dependency to 3.4.x
4
5
  * `1.1.2`: fixed an error when using private functions
5
6
  * `1.1.1`: fixed an error when using private functions
data/README.md CHANGED
@@ -5,9 +5,9 @@ Here is a [Compass Extension](http://compass-style.org/) providing you all funct
5
5
  ## What's in there?
6
6
 
7
7
  * `char-at($string, $index)`: returns the character from `$string` at index `$index`
8
- * `levenshtein($a, $b)`: returns the Levenshtein distance betwee `$a` and `$b`
8
+ * `levenshtein($a, $b)`: returns the Levenshtein distance between `$a` and `$b`
9
9
  * `str-count($string, $needle)`: counts number of occurrences of `$needle` in `$string`
10
- * `str-ends-with($string, $needle)`: returns wether `$string` ends with `$needle`
10
+ * `str-ends-with($string, $needle)`: returns whether `$string` ends with `$needle`
11
11
  * `str-explode($string, $separator)`: explodes `$string` on `$separator` occurrences
12
12
  * `str-implode($list)`: implodes `$list` into a string
13
13
  * `str-last-index($string, $needle)`: returns last index of `$needle` in `$string`
@@ -15,12 +15,12 @@ Here is a [Compass Extension](http://compass-style.org/) providing you all funct
15
15
  * `str-pad($string, $length, $pad: " ", $direction: left)`: pads `$string` with `$pad` to match `$length` starting from `$direction`
16
16
  * `str-printf($string, $elements...)`: replaces occurrences of `%s` in `$string` by elements from `$elements`
17
17
  * `str-repeat($string, $times)`: repeats `$string` `$times` times
18
- * `str-replace($string, $old, $new: "", $case-sensitive: true)`: replaces `$old` by `$new` in `$string` respecting `$case-sensitive`
18
+ * `str-replace($string, $old, $new: "")`: replaces `$old` by `$new` in `$string` respecting `$case-sensitive`
19
19
  * `str-reverse($string)`: reverses string
20
20
  * `str-rot($string, $rot: 13)`: rotates letters in `$string` of `$rot` position in alphabet
21
21
  * `str-shuffle($string)`: shuffles letters in string
22
22
  * `str-split($string)`: splits `$string` into a list of characters
23
- * `str-starts-width($string, $needle)`: returns wether `$string` starts with `$needle`
23
+ * `str-starts-with($string, $needle)`: returns whether `$string` starts with `$needle`
24
24
  * `str-trim($string)`: removes white spaces before and after `$string`
25
25
  * `str-ucfirst($string)`: turns first letter of `$string` into upper case
26
26
  * `str-word-count($string)`: counts number of words in `$string`
@@ -4,8 +4,8 @@ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
4
  Compass::Frameworks.register("SassyStrings", :path => "#{File.dirname(__FILE__)}/..")
5
5
 
6
6
  module SassyStrings
7
- VERSION = "1.1.3"
8
- DATE = "2014-11-27"
7
+ VERSION = "1.1.4"
8
+ DATE = "2014-12-31"
9
9
  end
10
10
 
11
11
  # Sassy String Functions
@@ -1,7 +1,7 @@
1
1
  //* ----------------------------------------------------- */
2
2
  // Private files
3
- // Use at your own risk
4
3
  //* ----------------------------------------------------- */
4
+
5
5
  @import "char-at";
6
6
  @import "levenshtein";
7
7
  @import "str-count";
@@ -21,4 +21,4 @@
21
21
  @import "str-trim";
22
22
  @import "str-ucfirst";
23
23
  @import "str-word-count";
24
- @import "stringify";
24
+ @import "stringify";
@@ -1,16 +1,8 @@
1
- /*
2
- * Return character from $string at $index
3
- * ---
4
- * @access private
5
- * ---
6
- * @since 1.2.0
7
- * ---
8
- * @param {string} $string - string to check
9
- * @param {string} $index - index to inspect
10
- * ---
11
- * @return {string}
12
- */
13
-
1
+ /// Return character from `$string` at `$index`.
2
+ /// @since 1.2.0
3
+ /// @param {String} $string - string to check
4
+ /// @param {String} $index - index to inspect
5
+ /// @return {String}
14
6
  @function _ss-char-at($string, $index) {
15
- @return str-slice($string, $index, $index);
16
- }
7
+ @return str-slice($string, $index, $index);
8
+ }
@@ -1,105 +1,84 @@
1
- /*
2
- * Calculating Levenshtein distance between two strings
3
- * ---
4
- * @access private
5
- * ---
6
- * @since 1.2.0
7
- * ---
8
- * @param {string} $a - first string
9
- * @param {string} $b - second string
10
- * ---
11
- * @return {number}
12
- */
1
+ /// Calculating Levenshtein distance between strings `$a` and `$b`.
2
+ /// @since 1.2.0
3
+ /// @param {String} $a - first string
4
+ /// @param {String} $b - second string
5
+ /// @return {Number}
13
6
  @function _ss-levenshtein($a, $b) {
14
- $a: to-lower-case($a);
15
- $b: to-lower-case($b);
7
+ $a: to-lower-case($a);
8
+ $b: to-lower-case($b);
16
9
 
17
- $n: str-length($a);
18
- $m: str-length($b);
10
+ $n: str-length($a);
11
+ $m: str-length($b);
19
12
 
20
- $matrix: _ss-matrix($n + 1, $m + 1);
21
- $cost: _ss-matrix($n, $m);
13
+ $matrix: _ss-matrix($n + 1, $m + 1);
14
+ $cost: _ss-matrix($n, $m);
22
15
 
23
- @if $a == $b { @return 0; }
24
- @if $n == 0 { @return $m; }
25
- @if $m == 0 { @return $n; }
16
+ @if $a == $b { @return 0; }
17
+ @if $n == 0 { @return $m; }
18
+ @if $m == 0 { @return $n; }
26
19
 
27
- @for $i from 0 through $n {
28
- @for $j from 0 through $m {
29
- $v: if($i == 0, $j, if($j == 0, $i, 0));
30
- @if $v != 0 {
31
- $matrix: _ss-set-matrix($matrix, $i + 1, $j + 1, $v);
32
- }
33
- @if $i != 0 and $j != 0 {
34
- $v: if(str-slice($a, $i, $i) == str-slice($b, $j, $j), 0, 1);
35
- @if $v != 0 {
36
- $cost: _ss-set-matrix($cost, $i, $j, $v);
37
- }
38
- }
20
+ @for $i from 0 through $n {
21
+ @for $j from 0 through $m {
22
+ $v: if($i == 0, $j, if($j == 0, $i, 0));
23
+ @if $v != 0 {
24
+ $matrix: _ss-set-matrix($matrix, $i + 1, $j + 1, $v);
25
+ }
26
+ @if $i != 0 and $j != 0 {
27
+ $v: if(str-slice($a, $i, $i) == str-slice($b, $j, $j), 0, 1);
28
+ @if $v != 0 {
29
+ $cost: _ss-set-matrix($cost, $i, $j, $v);
39
30
  }
31
+ }
40
32
  }
33
+ }
41
34
 
42
- @for $i from 2 through length($matrix) {
43
- @for $j from 2 through length(nth($matrix, $i)) {
44
- $matrix: _ss-set-matrix($matrix, $i, $j, min(_ss-e($matrix, $i - 1, $j) + 1, _ss-e($matrix, $i, $j - 1) + 1, _ss-e($matrix, $i - 1, $j - 1) + _ss-e($cost, $i - 1, $j - 1)));
45
- }
35
+ @for $i from 2 through length($matrix) {
36
+ @for $j from 2 through length(nth($matrix, $i)) {
37
+ $matrix: _ss-set-matrix($matrix, $i, $j, min(_ss-e($matrix, $i - 1, $j) + 1, _ss-e($matrix, $i, $j - 1) + 1, _ss-e($matrix, $i - 1, $j - 1) + _ss-e($cost, $i - 1, $j - 1)));
46
38
  }
39
+ }
47
40
 
48
- @return _ss-e($matrix, length($matrix), length(nth($matrix, 1)));
41
+ @return _ss-e($matrix, length($matrix), length(nth($matrix, 1)));
49
42
  }
50
43
 
51
- /*
52
- * Helper to target an element in a matrix
53
- * ---
54
- * @access private
55
- * ---
56
- * @param {number} $m - matrix
57
- * @param {number} $x - x coord
58
- * @param {number} $y - y coord
59
- * ---
60
- * @return {number}
61
- */
62
-
44
+ /// Helper to target an element in a matrix
45
+ /// @access private
46
+ /// @param {Number} $m - matrix
47
+ /// @param {Number} $x - x coord
48
+ /// @param {Number} $y - y coord
49
+ /// @return {Number}
63
50
  @function _ss-e($m, $x, $y) {
64
- @return nth(nth($m, $x), $y);
51
+ @return nth(nth($m, $x), $y);
65
52
  }
66
53
 
67
- /*
68
- * Helper instanciation a matrix of $x by $y
69
- * ---
70
- * @access private
71
- * ---
72
- * @param {number} $x - number of cols
73
- * @param {number} $y - number of lines
74
- * ---
75
- * @return {list}
76
- */
77
-
54
+ /// Helper instanciation a matrix of $x by $y
55
+ /// @access private
56
+ /// @param {Number} $x - number of cols
57
+ /// @param {Number} $y - number of lines
58
+ /// @return {List}
78
59
  @function _ss-matrix($x, $y) {
79
- $matrix: ();
80
- @for $i from 1 through $x {
81
- $tmp: ();
82
- @for $y from 1 through $y {
83
- $tmp: append($tmp, 0)
84
- }
85
- $matrix: append($matrix, $tmp);
60
+ $matrix: ();
61
+
62
+ @for $i from 1 through $x {
63
+ $tmp: ();
64
+
65
+ @for $y from 1 through $y {
66
+ $tmp: append($tmp, 0)
86
67
  }
87
- @return $matrix;
88
- }
89
68
 
90
- /*
91
- * Helper assigning $value at $matrix[$x, $y]
92
- * ---
93
- * @access private
94
- * ---
95
- * @param {number} $matrix - matrix to update
96
- * @param {number} $x - x coord
97
- * @param {number} $y - y coord
98
- * @param {number} $value - value to assign at $matrix[$x, $y]
99
- * ---
100
- * @return [list]
101
- */
69
+ $matrix: append($matrix, $tmp);
70
+ }
102
71
 
72
+ @return $matrix;
73
+ }
74
+
75
+ /// Helper assigning $value at $matrix[$x, $y]
76
+ /// @access private
77
+ /// @param {Number} $matrix - matrix to update
78
+ /// @param {Number} $x - x coord
79
+ /// @param {Number} $y - y coord
80
+ /// @param {Number} $value - value to assign at $matrix[$x, $y]
81
+ /// @return {List}
103
82
  @function _ss-set-matrix($matrix, $x, $y, $value) {
104
83
  @return set-nth($matrix, $x, set-nth(nth($matrix, $x), $y, $value));
105
- }
84
+ }
@@ -1,27 +1,19 @@
1
- /*
2
- * Count the number of occurrences of $needle in $string
3
- * ---
4
- * @access private
5
- * ---
6
- * @since 1.2.0
7
- * ---
8
- * @param {string} $string - string
9
- * @param {string} $needle - substring to count in $string
10
- * ---
11
- * @return {number}
12
- */
13
-
1
+ /// Count the number of occurrences of `$needle` in `$string`.
2
+ /// @since 1.2.0
3
+ /// @param {String} $string - string
4
+ /// @param {String} $needle - substring to count in `$string`
5
+ /// @return {Number}
14
6
  @function _ss-str-count($string, $needle) {
15
- $index: str-index($string, $needle);
16
- $result: if($index, 1, 0);
7
+ $index: str-index($string, $needle);
8
+ $result: if($index, 1, 0);
17
9
 
18
- @if $index {
19
- @for $i from $index + str-length($needle) through str-length($string) {
20
- @if str-slice($string, $i, $i + str-length($needle) - 1) == $needle {
21
- $result: $result + 1;
22
- }
23
- }
10
+ @if $index {
11
+ @for $i from $index + str-length($needle) through str-length($string) {
12
+ @if str-slice($string, $i, $i + str-length($needle) - 1) == $needle {
13
+ $result: $result + 1;
14
+ }
24
15
  }
16
+ }
25
17
 
26
- @return $result;
27
- }
18
+ @return $result;
19
+ }
@@ -1,16 +1,8 @@
1
- /*
2
- * Check whether $string ends with $needle
3
- * ---
4
- * @access private
5
- * ---
6
- * @since 1.2.0
7
- * ---
8
- * @param {string} $string - string to check
9
- * @param {string} $needle - substring to check
10
- * ---
11
- * @return {bool}
12
- */
13
-
1
+ /// Check whether `$string` ends with `$needle`.
2
+ /// @since 1.2.0
3
+ /// @param {String} $string - string to check
4
+ /// @param {String} $needle - substring to check
5
+ /// @return {Bool}
14
6
  @function _ss-str-ends-with($string, $needle) {
15
- @return str-slice($string, -1 * str-length($needle)) == $needle;
7
+ @return str-slice($string, -1 * str-length($needle)) == $needle;
16
8
  }
@@ -1,41 +1,34 @@
1
- /*
2
- * Split $string into several parts using $delimiter
3
- * ---
4
- * @access private
5
- * ---
6
- * @since 1.2.0
7
- * ---
8
- * @param {string} $string - string to split
9
- * @param {string} $delimiter - string to use as a delimiter to split $string
10
- * ---
11
- * @return {list}
12
- */
1
+ /// Split `$string` into several parts using `$delimiter`.
2
+ /// @since 1.2.0
3
+ /// @param {String} $string - string to split
4
+ /// @param {String} $delimiter ('') - string to use as a delimiter to split `$string`
5
+ /// @return {List}
6
+ @function _ss-str-explode($string, $delimiter: "") {
7
+ $result: ();
8
+ $length: str-length($string);
13
9
 
14
- @function _ss-str-explode($string, $delimiter: '') {
15
- $result: ();
16
- $length: str-length($string);
17
-
18
- @if str-length($delimiter) == 0 {
19
- @for $i from 1 through $length {
20
- $result: append($result, str-slice($string, $i, $i));
21
- }
22
- @return $result;
10
+ @if str-length($delimiter) == 0 {
11
+ @for $i from 1 through $length {
12
+ $result: append($result, str-slice($string, $i, $i));
23
13
  }
24
14
 
25
- $running: true;
26
- $remaining: $string;
15
+ @return $result;
16
+ }
17
+
18
+ $running: true;
19
+ $remaining: $string;
20
+
21
+ @while $running {
22
+ $index: str-index($remaining, $delimiter);
27
23
 
28
- @while $running {
29
- $index: str-index($remaining, $delimiter);
30
- @if $index {
31
- $slice: str-slice($remaining, 1, $index - 1);
32
- $result: append($result, $slice);
33
- $remaining: str-slice($remaining, $index + str-length($delimiter));
34
- }
35
- @else {
36
- $running: false;
37
- }
24
+ @if $index {
25
+ $slice: str-slice($remaining, 1, $index - 1);
26
+ $result: append($result, $slice);
27
+ $remaining: str-slice($remaining, $index + str-length($delimiter));
28
+ } @else {
29
+ $running: false;
38
30
  }
31
+ }
39
32
 
40
- @return append($result, $remaining);
41
- }
33
+ @return append($result, $remaining);
34
+ }
@@ -1,21 +1,13 @@
1
- /*
2
- * Implode $list into a string
3
- * ---
4
- * @access private
5
- * ---
6
- * @since 1.2.0
7
- * ---
8
- * @param {list} $list - list to convert to string
9
- * ---
10
- * @return {string}
11
- */
12
-
1
+ /// Implode `$list` into a string.
2
+ /// @since 1.2.0
3
+ /// @param {List} $list - list to convert to string
4
+ /// @return {String}
13
5
  @function _ss-str-implode($list) {
14
- $result: "";
6
+ $result: "";
15
7
 
16
- @each $item in $list {
17
- $result: $result + if(length($item) > 1, str-implode($item), $item);
18
- }
8
+ @each $item in $list {
9
+ $result: $result + if(length($item) > 1, str-implode($item), $item);
10
+ }
19
11
 
20
- @return $result;
21
- }
12
+ @return $result;
13
+ }
@@ -1,16 +1,8 @@
1
- /*
2
- * Return last index of $needle in $string
3
- * ---
4
- * @access private
5
- * ---
6
- * @since 1.2.0
7
- * ---
8
- * @param {string} $string - string to search in
9
- * @param {string} $needle - substring to search for
10
- * ---
11
- * @return {number}
12
- */
13
-
1
+ /// Return last index of `$needle` in `$string`.
2
+ /// @since 1.2.0
3
+ /// @param {String} $string - string to search in
4
+ /// @param {String} $needle - substring to search for
5
+ /// @return {Number}
14
6
  @function _ss-str-last-index($string, $needle) {
15
7
  $index: str-index($string, $needle);
16
8
  $result: $index;
@@ -24,4 +16,4 @@
24
16
  }
25
17
 
26
18
  @return $result;
27
- }
19
+ }