sassy-strings 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/sassy-strings.rb +186 -9
- metadata +7 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
data.tar.gz: 02b3446a1c8f82a7ec32e1a909ede9cbbe0de5ea
|
4
|
+
metadata.gz: 7b50362fa0e422988160e83067310698cb54bf64
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: 68b5c52349aa162c63c7a12526d5aab7db675daa3c62aa6213049b28133ef5416a95b1c0ac7c8fd89952c5c4faa14e845e35bf77e21b8033ee98c155c631b95c
|
7
|
+
metadata.gz: fe9217daa156966b5956e1d6febbd7283212b338a7f9249585da9971b02864edb1e2d060b961f4fd912d82b64aa229f170287e17e91b7bf485903e6479cc2de5
|
data/lib/sassy-strings.rb
CHANGED
@@ -3,14 +3,24 @@ Compass::Frameworks.register("sassy-strings", :path => "#{File.dirname(__FILE__)
|
|
3
3
|
|
4
4
|
# Sassy String Functions
|
5
5
|
module Sass::Script::Functions
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
# Split a string into a list using a given key
|
7
|
+
#
|
8
|
+
# @return [Sass::Script::List]
|
9
|
+
# @raise [ArgumentError] if `string` isn't a string
|
10
|
+
# @raise [ArgumentError] if `key` isn't a key
|
11
|
+
# @example
|
12
|
+
# split-string('Hello World', ' ') => ('Hello', 'World')
|
13
|
+
# str-split('Hello World', ' ') => ('Hello', 'World')
|
14
|
+
def split_string(string, key)
|
15
|
+
items = string.value.split(key.value)
|
16
|
+
if items.count == 1
|
17
|
+
Sass::Script::Bool.new(false)
|
18
|
+
else
|
19
|
+
Sass::Script::List.new(items.map{|i| Sass::Script::String.new(i)}, :comma)
|
20
|
+
end
|
10
21
|
end
|
11
22
|
|
12
|
-
|
13
|
-
def split_string(string, key)
|
23
|
+
def str_split(string, key)
|
14
24
|
items = string.value.split(key.value)
|
15
25
|
if items.count == 1
|
16
26
|
Sass::Script::Bool.new(false)
|
@@ -19,7 +29,17 @@ module Sass::Script::Functions
|
|
19
29
|
end
|
20
30
|
end
|
21
31
|
|
22
|
-
|
32
|
+
declare :split_string, [:string, :key]
|
33
|
+
declare :str_split, [:string, :key]
|
34
|
+
|
35
|
+
# Find the position of a substring within a string
|
36
|
+
#
|
37
|
+
# @return [Sass::Script::Number]
|
38
|
+
# @raise [ArgumentError] if `needle` isn't a string
|
39
|
+
# @raise [ArgumentError] if `haystack` isn't a key
|
40
|
+
# @example
|
41
|
+
# str-pos('ello', 'hello') => 1
|
42
|
+
# str-pos('a', 'hello') => -1
|
23
43
|
def str_pos(needle, haystack)
|
24
44
|
if haystack.value.to_s.index(needle.value.to_s)
|
25
45
|
Sass::Script::Number.new(haystack.value.to_s.index(needle.value.to_s))
|
@@ -28,6 +48,8 @@ module Sass::Script::Functions
|
|
28
48
|
end
|
29
49
|
end
|
30
50
|
|
51
|
+
declare :str_pos, [:needle, :haystack]
|
52
|
+
|
31
53
|
# Converts a String to a Number
|
32
54
|
def str_to_number(string)
|
33
55
|
result = Sass::Script::Parser.parse(string.value, string.line || 0, 0)
|
@@ -39,11 +61,166 @@ module Sass::Script::Functions
|
|
39
61
|
end
|
40
62
|
end
|
41
63
|
|
64
|
+
declare :str_split, [:string, :key]
|
65
|
+
|
66
|
+
# Returns the number of characters in a string.
|
67
|
+
#
|
68
|
+
# @return [Sass::Script::Number]
|
69
|
+
# @raise [ArgumentError] if `string` isn't a string
|
70
|
+
# @example
|
71
|
+
# str-length("foo") => 3
|
72
|
+
def str_length(string)
|
73
|
+
assert_type string, :String
|
74
|
+
Sass::Script::Number.new(string.value.size)
|
75
|
+
end
|
76
|
+
declare :str_length, [:string]
|
77
|
+
|
78
|
+
# inserts a string into another string
|
79
|
+
#
|
80
|
+
# Inserts the `insert` string before the character at the given index.
|
81
|
+
# Negative indices count from the end of the string.
|
82
|
+
# The inserted string will starts at the given index.
|
83
|
+
#
|
84
|
+
# @return [Sass::Script::String]
|
85
|
+
# @raise [ArgumentError] if `original` isn't a string, `insert` isn't a string, or `index` isn't a number.
|
86
|
+
# @example
|
87
|
+
# str-insert("abcd", "X", 1) => "Xabcd"
|
88
|
+
# str-insert("abcd", "X", 4) => "abcXd"
|
89
|
+
# str-insert("abcd", "X", 100) => "abcdX"
|
90
|
+
# str-insert("abcd", "X", -100) => "Xabcd"
|
91
|
+
# str-insert("abcd", "X", -4) => "aXbcd"
|
92
|
+
# str-insert("abcd", "X", -1) => "abcdX"
|
93
|
+
def str_insert(original, insert, index)
|
94
|
+
assert_type original, :String
|
95
|
+
assert_type insert, :String
|
96
|
+
assert_type index, :Number
|
97
|
+
unless index.unitless?
|
98
|
+
raise ArgumentError.new("#{index.inspect} is not a unitless number")
|
99
|
+
end
|
100
|
+
insertion_point = index.value > 0 ? [index.value - 1, original.value.size].min : [index.value, -original.value.size - 1].max
|
101
|
+
Sass::Script::String.new(original.value.dup.insert(insertion_point, insert.value), original.type)
|
102
|
+
end
|
103
|
+
declare :str_insert, [:original, :insert, :index]
|
104
|
+
|
105
|
+
# A SASS Wrapper Function for Ruby's gsub method
|
106
|
+
#
|
107
|
+
# @return [Sass::Script::String]
|
108
|
+
|
109
|
+
# @example
|
110
|
+
# str_replace(abcd, a, zzz) => zzzbcd
|
111
|
+
|
112
|
+
def str_replace(string, find, replace)
|
113
|
+
assert_type string, :String
|
114
|
+
assert_type replace, :String
|
115
|
+
Sass::Script::String.new(string.value.gsub(find.value,replace.value), string.type)
|
116
|
+
end
|
117
|
+
declare :str_replace, [:string, :find, :replace]
|
118
|
+
|
119
|
+
# Starting at the left, finds the index of the first location
|
120
|
+
# where `substring` is found in `string`.
|
121
|
+
#
|
122
|
+
# @return [Sass::Script::String]
|
123
|
+
# @raise [ArgumentError] if `original` isn't a string, `insert` isn't a string, or `index` isn't a number.
|
124
|
+
# @example
|
125
|
+
# str-index(abcd, a) => 1
|
126
|
+
# str-index(abcd, ab) => 1
|
127
|
+
# str-index(abcd, X) => 0
|
128
|
+
# str-index(abcd, c) => 3
|
129
|
+
|
130
|
+
def str_index(string, substring)
|
131
|
+
assert_type string, :String
|
132
|
+
assert_type substring, :String
|
133
|
+
index = string.value.index(substring.value) || -1
|
134
|
+
Sass::Script::Number.new(index + 1)
|
135
|
+
end
|
136
|
+
declare :str_index, [:string, :substring]
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
# Extract a substring from `string` from `start` index to `end` index.
|
141
|
+
#
|
142
|
+
# @return [Sass::Script::String]
|
143
|
+
# @raise [ArgumentError] if `string` isn't a string or `start` and `end` aren't unitless numbers
|
144
|
+
# @example
|
145
|
+
# str-extract(abcd,2,3) => bc
|
146
|
+
# str-extract(abcd,2) => cd
|
147
|
+
# str-extract(abcd,-2) => abc
|
148
|
+
# str-extract(abcd,2,-2) => bc
|
149
|
+
# str-extract(abcd,3,-3) => unquote("")
|
150
|
+
# str-extract("abcd",3,-3) => ""
|
151
|
+
# str-extract(abcd,1,1) => a
|
152
|
+
# str-extract(abcd,1,2) => ab
|
153
|
+
# str-extract(abcd,1,4) => abcd
|
154
|
+
# str-extract(abcd,-100,4) => abcd
|
155
|
+
# str-extract(abcd,1,100) => abcd
|
156
|
+
# str-extract(abcd,2,1) => unquote("")
|
157
|
+
# str-extract("abcd",2,3) => "bc"
|
158
|
+
def str_extract(string, start_at, end_at = nil)
|
159
|
+
assert_type string, :String
|
160
|
+
assert_type start_at, :Number
|
161
|
+
unless start_at.unitless?
|
162
|
+
raise ArgumentError.new("#{start_at.inspect} is not a unitless number")
|
163
|
+
end
|
164
|
+
if end_at.nil?
|
165
|
+
if start_at.value < 0
|
166
|
+
end_at = start_at
|
167
|
+
start_at = Sass::Script::Number.new(1)
|
168
|
+
else
|
169
|
+
end_at = Sass::Script::Number.new(-1)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
assert_type end_at, :Number
|
173
|
+
unless end_at.unitless?
|
174
|
+
raise ArgumentError.new("#{end_at.inspect} is not a unitless number")
|
175
|
+
end
|
176
|
+
s = start_at.value > 0 ? start_at.value - 1 : start_at.value
|
177
|
+
e = end_at.value > 0 ? end_at.value - 1 : end_at.value
|
178
|
+
extracted = string.value.slice(s..e)
|
179
|
+
Sass::Script::String.new(extracted || "", string.type)
|
180
|
+
end
|
181
|
+
declare :str_index, [:string, :start, :end]
|
182
|
+
# Convert a string to upper case
|
183
|
+
#
|
184
|
+
# @return [Sass::Script::String]
|
185
|
+
# @raise [ArgumentError] if `string` isn't a string
|
186
|
+
# @example
|
187
|
+
# to-upper-case(abcd) => ABCD
|
188
|
+
# to-upper-case("abcd") => "ABCD"
|
189
|
+
def to_upper_case(string)
|
190
|
+
assert_type string, :String
|
191
|
+
Sass::Script::String.new(string.value.upcase, string.type)
|
192
|
+
end
|
193
|
+
|
194
|
+
def to_uppercase(string)
|
195
|
+
assert_type string, :String
|
196
|
+
Sass::Script::String.new(string.value.upcase, string.type)
|
197
|
+
end
|
198
|
+
declare :to_upper_case, [:string]
|
199
|
+
declare :to_uppercase, [:string]
|
200
|
+
|
201
|
+
# Convert a string to lower case
|
202
|
+
#
|
203
|
+
# @return [Sass::Script::String]
|
204
|
+
# @raise [ArgumentError] if `string` isn't a string
|
205
|
+
# @example
|
206
|
+
# to-lower-case(ABCD) => abcd
|
207
|
+
# to-lower-case("ABCD") => "abcd"
|
208
|
+
def to_lower_case(string)
|
209
|
+
assert_type string, :String
|
210
|
+
Sass::Script::String.new(string.value.downcase, string.type)
|
211
|
+
end
|
212
|
+
def to_lowercase(string)
|
213
|
+
assert_type string, :String
|
214
|
+
Sass::Script::String.new(string.value.downcase, string.type)
|
215
|
+
end
|
216
|
+
declare :to_lower_case, [:string]
|
217
|
+
declare :to_lowercase, [:string]
|
218
|
+
|
42
219
|
end
|
43
220
|
|
44
221
|
module SassyStrings
|
45
222
|
|
46
|
-
VERSION = "0.
|
47
|
-
DATE = "2013-
|
223
|
+
VERSION = "1.0.0"
|
224
|
+
DATE = "2013-08-16"
|
48
225
|
|
49
226
|
end
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sassy-strings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 1
|
9
|
-
version: 0.3.1
|
4
|
+
version: 1.0.0
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Sam Richard
|
@@ -14,8 +9,7 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2013-
|
18
|
-
default_executable:
|
12
|
+
date: 2013-08-16 00:00:00 Z
|
19
13
|
dependencies:
|
20
14
|
- !ruby/object:Gem::Dependency
|
21
15
|
name: compass
|
@@ -24,10 +18,6 @@ dependencies:
|
|
24
18
|
requirements:
|
25
19
|
- - ">="
|
26
20
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 12
|
30
|
-
- 2
|
31
21
|
version: 0.12.2
|
32
22
|
type: :runtime
|
33
23
|
version_requirements: *id001
|
@@ -42,9 +32,10 @@ extra_rdoc_files: []
|
|
42
32
|
|
43
33
|
files:
|
44
34
|
- lib/sassy-strings.rb
|
45
|
-
has_rdoc: true
|
46
35
|
homepage: https://github.com/snugug/sassy-strings
|
47
|
-
licenses:
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
48
39
|
|
49
40
|
post_install_message:
|
50
41
|
rdoc_options: []
|
@@ -55,23 +46,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
46
|
requirements:
|
56
47
|
- - ">="
|
57
48
|
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 0
|
60
49
|
version: "0"
|
61
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
51
|
requirements:
|
63
52
|
- - ">="
|
64
53
|
- !ruby/object:Gem::Version
|
65
|
-
segments:
|
66
|
-
- 1
|
67
|
-
- 2
|
68
54
|
version: "1.2"
|
69
55
|
requirements: []
|
70
56
|
|
71
57
|
rubyforge_project: sassy-strings
|
72
|
-
rubygems_version:
|
58
|
+
rubygems_version: 2.0.3
|
73
59
|
signing_key:
|
74
|
-
specification_version:
|
60
|
+
specification_version: 4
|
75
61
|
summary: Advanced String handling for Sass
|
76
62
|
test_files: []
|
77
63
|
|