SassyStrings 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/README.md +5 -0
  4. data/lib/SassyStrings.rb +2 -2
  5. data/stylesheets/_SassyStrings.scss +2 -20
  6. data/stylesheets/private/_all.scss +24 -0
  7. data/stylesheets/private/_char-at.scss +16 -0
  8. data/stylesheets/private/_levenshtein.scss +105 -0
  9. data/stylesheets/private/_str-count.scss +27 -0
  10. data/stylesheets/private/_str-ends-with.scss +16 -0
  11. data/stylesheets/private/_str-explode.scss +41 -0
  12. data/stylesheets/private/_str-implode.scss +21 -0
  13. data/stylesheets/private/_str-last-index.scss +27 -0
  14. data/stylesheets/private/_str-lcfirst.scss +15 -0
  15. data/stylesheets/private/_str-pad.scss +36 -0
  16. data/stylesheets/private/_str-printf.scss +29 -0
  17. data/stylesheets/private/_str-repeat.scss +22 -0
  18. data/stylesheets/private/_str-replace.scss +33 -0
  19. data/stylesheets/private/_str-reverse.scss +21 -0
  20. data/stylesheets/private/_str-rot.scss +39 -0
  21. data/stylesheets/private/_str-shuffle.scss +36 -0
  22. data/stylesheets/private/_str-starts-with.scss +16 -0
  23. data/stylesheets/private/_str-trim.scss +31 -0
  24. data/stylesheets/private/_str-ucfirst.scss +15 -0
  25. data/stylesheets/{functions → private}/_str-word-count.scss +5 -6
  26. data/stylesheets/private/_stringify.scss +26 -0
  27. data/stylesheets/public/_all.scss +23 -0
  28. data/stylesheets/public/_char-at.scss +31 -0
  29. data/stylesheets/public/_levenshtein.scss +26 -0
  30. data/stylesheets/public/_str-count.scss +26 -0
  31. data/stylesheets/public/_str-ends-with.scss +26 -0
  32. data/stylesheets/public/_str-explode.scss +26 -0
  33. data/stylesheets/public/_str-implode.scss +19 -0
  34. data/stylesheets/{functions → public}/_str-last-index.scss +5 -12
  35. data/stylesheets/public/_str-lcfirst.scss +20 -0
  36. data/stylesheets/public/_str-pad.scss +33 -0
  37. data/stylesheets/public/_str-printf.scss +21 -0
  38. data/stylesheets/public/_str-repeat.scss +26 -0
  39. data/stylesheets/public/_str-replace.scss +39 -0
  40. data/stylesheets/public/_str-reverse.scss +20 -0
  41. data/stylesheets/public/_str-rot.scss +26 -0
  42. data/stylesheets/public/_str-shuffle.scss +18 -0
  43. data/stylesheets/public/_str-starts-with.scss +26 -0
  44. data/stylesheets/public/_str-trim.scss +20 -0
  45. data/stylesheets/{functions → public}/_str-ucfirst.scss +6 -2
  46. data/stylesheets/public/_str-word-count.scss +20 -0
  47. data/stylesheets/public/_stringify.scss +15 -0
  48. metadata +44 -22
  49. data/stylesheets/functions/_char-at.scss +0 -25
  50. data/stylesheets/functions/_levenshtein.scss +0 -99
  51. data/stylesheets/functions/_str-count.scss +0 -31
  52. data/stylesheets/functions/_str-ends-with.scss +0 -20
  53. data/stylesheets/functions/_str-explode.scss +0 -45
  54. data/stylesheets/functions/_str-implode.scss +0 -15
  55. data/stylesheets/functions/_str-lcfirst.scss +0 -14
  56. data/stylesheets/functions/_str-pad.scss +0 -45
  57. data/stylesheets/functions/_str-printf.scss +0 -28
  58. data/stylesheets/functions/_str-repeat.scss +0 -26
  59. data/stylesheets/functions/_str-replace.scss +0 -47
  60. data/stylesheets/functions/_str-reverse.scss +0 -20
  61. data/stylesheets/functions/_str-rot.scss +0 -43
  62. data/stylesheets/functions/_str-shuffle.scss +0 -26
  63. data/stylesheets/functions/_str-starts-with.scss +0 -20
  64. data/stylesheets/functions/_str-trim.scss +0 -30
  65. data/stylesheets/functions/_stringify.scss +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3899887f5222edd4ba1eecc70d5f9050abce8de9
4
- data.tar.gz: e02a8b4448c9c00d2272a1b1a1d399d9bf4e1f6e
3
+ metadata.gz: d70bcfa2579e805f82da0912eef6f090541410bf
4
+ data.tar.gz: 1dc25991030d97b6a074736f6c8586be02c6e6e2
5
5
  SHA512:
6
- metadata.gz: be9b497e564554997e0d12d51bc54b6bc36610bdaf2cebc1a151d0563dcfc643a572b15483bafc10c2000f6324572f09c691fa6a5ea805de1c58f4c3bcf81992
7
- data.tar.gz: a92dba77ae9cedacc0234a429723f8ac819c1f225d76666196fa73e008c140f306bb844bc651ed389e6ed6af6fe0c87a42030cc92d2a4d4c53f7511c410d897d
6
+ metadata.gz: 57479ce6911600c434b4ae2d69e8e5d2e19e110885d77156b2980d346990392f2cd0c4605ddef84d1c6949c6653e959c27ce7dcd1545483ca48484e0f1458473
7
+ data.tar.gz: fe84136981c67e4782df41f6d19eaa51f7ab6765aced5c0d10643eef55fb81bd316519011f1c879860d5018da734009f07f59e11deff92b6175f1447c740202c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
2
 
3
+ * `1.1.0`: dissociated error checking from function logic, and added some missing imports
3
4
  * `1.0.1`: fixed a lot of tiny bugs ([#8](https://github.com/HugoGiraudel/SassyStrings/pull/8))
4
5
  * `1.0.0`: initial commit
data/README.md CHANGED
@@ -47,3 +47,8 @@ Some functions depend on other functions. If you include functions individually,
47
47
  ## Credits
48
48
 
49
49
  Huge thanks to [Marc Mintel](http://twitter.com/marcmintel) for his help.
50
+
51
+ ## Advanced usage
52
+
53
+ If you experience naming conflicts or want to add your own error handling and dependency checker feel free to use the functions in `stylesheets/private`.
54
+ These functions do not add any kind of error handling so use them at your own risk!
data/lib/SassyStrings.rb CHANGED
@@ -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.0.1"
8
- DATE = "2014-02-16"
7
+ VERSION = "1.1.0"
8
+ DATE = "2014-09-28"
9
9
  end
10
10
 
11
11
  # Sassy String Functions
@@ -4,23 +4,5 @@
4
4
  // Repository: https://github.com/HugoGiraudel/SassyStrings/
5
5
  // -------------------------------------------------------------------------------
6
6
 
7
- @import "functions/char-at";
8
- @import "functions/levenshtein";
9
- @import "functions/str-count";
10
- @import "functions/str-ends-with";
11
- @import "functions/str-explode";
12
- @import "functions/str-implode";
13
- @import "functions/str-last-index";
14
- @import "functions/str-lcfirst";
15
- @import "functions/str-pad";
16
- @import "functions/str-printf";
17
- @import "functions/str-repeat";
18
- @import "functions/str-replace";
19
- @import "functions/str-reverse";
20
- @import "functions/str-rot";
21
- @import "functions/str-shuffle";
22
- @import "functions/str-starts-with";
23
- @import "functions/str-trim";
24
- @import "functions/str-ucfirst";
25
- @import "functions/str-word-count";
26
- @import "functions/stringify";
7
+ @import 'private/all';
8
+ @import 'public/all';
@@ -0,0 +1,24 @@
1
+ //* ----------------------------------------------------- */
2
+ // Private files
3
+ // Use at your own risk
4
+ //* ----------------------------------------------------- */
5
+ @import "char-at";
6
+ @import "levenshtein";
7
+ @import "str-count";
8
+ @import "str-ends-with";
9
+ @import "str-explode";
10
+ @import "str-implode";
11
+ @import "str-last-index";
12
+ @import "str-lcfirst";
13
+ @import "str-pad";
14
+ @import "str-printf";
15
+ @import "str-repeat";
16
+ @import "str-replace";
17
+ @import "str-reverse";
18
+ @import "str-rot";
19
+ @import "str-shuffle";
20
+ @import "str-starts-with";
21
+ @import "str-trim";
22
+ @import "str-ucfirst";
23
+ @import "str-word-count";
24
+ @import "stringify";
@@ -0,0 +1,16 @@
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
+
14
+ @function _ss-char-at($string, $index) {
15
+ @return str-slice($string, $index, $index);
16
+ }
@@ -0,0 +1,105 @@
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
+ */
13
+ @function _ss-levenshtein($a, $b) {
14
+ $a: to-lower-case($a);
15
+ $b: to-lower-case($b);
16
+
17
+ $n: str-length($a);
18
+ $m: str-length($b);
19
+
20
+ $matrix: _ss-matrix($n + 1, $m + 1);
21
+ $cost: _ss-matrix($n, $m);
22
+
23
+ @if $a == $b { @return 0; }
24
+ @if $n == 0 { @return $m; }
25
+ @if $m == 0 { @return $n; }
26
+
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
+ }
39
+ }
40
+ }
41
+
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
+ }
46
+ }
47
+
48
+ @return _ss-e($matrix, length($matrix), length(nth($matrix, 1)));
49
+ }
50
+
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
+
63
+ @function _ss-e($m, $x, $y) {
64
+ @return nth(nth($m, $x), $y);
65
+ }
66
+
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
+
78
+ @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);
86
+ }
87
+ @return $matrix;
88
+ }
89
+
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
+ */
102
+
103
+ @function _ss-set-matrix($matrix, $x, $y, $value) {
104
+ @return set-nth($matrix, $x, set-nth(nth($matrix, $x), $y, $value));
105
+ }
@@ -0,0 +1,27 @@
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
+
14
+ @function _ss-str-count($string, $needle) {
15
+ $index: str-index($string, $needle);
16
+ $result: if($index, 1, 0);
17
+
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
+ }
24
+ }
25
+
26
+ @return $result;
27
+ }
@@ -0,0 +1,16 @@
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
+
14
+ @function _ss-str-ends-with($string, $needle) {
15
+ @return str-slice($string, -1 * str-length($needle)) == $needle;
16
+ }
@@ -0,0 +1,41 @@
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
+ */
13
+
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;
23
+ }
24
+
25
+ $running: true;
26
+ $remaining: $string;
27
+
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
+ }
38
+ }
39
+
40
+ @return append($result, $remaining);
41
+ }
@@ -0,0 +1,21 @@
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
+
13
+ @function _ss-str-implode($list) {
14
+ $result: "";
15
+
16
+ @each $item in $list {
17
+ $result: $result + if(length($item) > 1, str-implode($item), $item);
18
+ }
19
+
20
+ @return $result;
21
+ }
@@ -0,0 +1,27 @@
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
+
14
+ @function _ss-str-last-index($string, $needle) {
15
+ $index: str-index($string, $needle);
16
+ $result: $index;
17
+
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: $i;
22
+ }
23
+ }
24
+ }
25
+
26
+ @return $result;
27
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Lower case first character of $string
3
+ * ---
4
+ * @access private
5
+ * ---
6
+ * @since 1.2.0
7
+ * ---
8
+ * @param {string} $string - string to lower the first character
9
+ * ---
10
+ * @return {string}
11
+ */
12
+
13
+ @function _ss-str-lcfirst($string) {
14
+ @return to-lower-case(str-slice($string, 1, 1)) + str-slice($string, 2);
15
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Pad $string from $direction with $pad to reach $length characters
3
+ * ---
4
+ * @access public
5
+ * ---
6
+ * @since 1.2.0
7
+ * ---
8
+ * @param {string} $string - string to pad
9
+ * @param {number} $length - number of characters to go for in returned string
10
+ * @param {string} $pad - string to use to pad $string
11
+ * @param {string} $direction - direction left or right for padding
12
+ * ---
13
+ * @return {string}
14
+ */
15
+
16
+ @function _ss-str-pad($string, $length, $pad: " ", $direction: left) {
17
+ $direction: if(index(left right, $direction), $direction, left);
18
+ $new-string: $string;
19
+ $index: 1;
20
+
21
+ @if $length > str-length($string) {
22
+ @while str-length($new-string) < $length {
23
+ $remains: $length - str-length($new-string);
24
+ $pad: if($remains < str-length($pad), str-slice($pad, 1, $remains), $pad);
25
+ @if $direction == left {
26
+ $new-string: str-insert($new-string, $pad, $index);
27
+ $index: $index + str-length($pad);
28
+ }
29
+ @else {
30
+ $new-string: $new-string + $pad;
31
+ }
32
+ }
33
+ }
34
+
35
+ @return $new-string;
36
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Replace occurrences of %s in $string by $elements
3
+ * ---
4
+ * @access private
5
+ * ---
6
+ * @since 1.2.0
7
+ * ---
8
+ * @param {string} $string - string to check
9
+ * @param {arglist} $elements - strings to use for replacements in %s
10
+ * ---
11
+ * @return {string}
12
+ */
13
+
14
+ @function _ss-str-printf($string, $elements...) {
15
+ $breaker: '%s';
16
+ $result: $string;
17
+
18
+ @for $i from 1 through length($elements) {
19
+ $index: str-index($result, $breaker);
20
+ @if $index {
21
+ $result: str-slice($result, 1, $index - 1) + stringify(nth($elements, $i)) + str-slice($result, $index + str-length($breaker));
22
+ }
23
+ @else {
24
+ @return $result;
25
+ }
26
+ }
27
+
28
+ @return $result;
29
+ }