string_awesome 0.2.4 → 0.2.5
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.
- checksums.yaml +4 -4
- data/lib/string_awesome/awesome_methods.rb +9 -9
- data/lib/string_awesome/version.rb +1 -1
- data/spec/awesome_methods_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cd58efc570f7ce893ccca18c174c728c4ab1680
|
4
|
+
data.tar.gz: 0fae2cf2ffecce0691336304b302993e0d813643
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4392918a8bc45ecc107c47bd94f69a233e32f36c1faf22c9f28aa8d387225f224f51c02ee1751a7f1f54507e3da9de4364394df1c5c0f92ae1a01ddf4b5bb469
|
7
|
+
data.tar.gz: 599dad656adfc1cb3fa1e358158ecccaa93a791f3e4607d30326d231979d48acd16c9395091d9d9a41b56b76230667e6a1245d0d113e6e44236b34808f99b93b
|
@@ -165,7 +165,7 @@ module StringAwesome
|
|
165
165
|
max_length = (length / 2).round if max_length == 0
|
166
166
|
|
167
167
|
# Truncates the string
|
168
|
-
str = self.
|
168
|
+
str = self.sa_truncate(max_length, options[:after_a_word]).strip
|
169
169
|
|
170
170
|
# Appends ellipsis
|
171
171
|
str << (options[:html_encoded] == true ? '…' : '...')
|
@@ -184,7 +184,7 @@ module StringAwesome
|
|
184
184
|
# - Indicates the max length expected, before ellipsis, for the result.
|
185
185
|
# after_a_word: (Boolean)
|
186
186
|
# - If true, the ellipsis will be displayed necessarily after a word.
|
187
|
-
def
|
187
|
+
def sa_truncate(length, after_a_word = false)
|
188
188
|
str = self[0...length]
|
189
189
|
|
190
190
|
if after_a_word == true
|
@@ -216,7 +216,7 @@ module StringAwesome
|
|
216
216
|
def linkify(options = {})
|
217
217
|
self.gsub!(SA_REGEXES[:url]) do |match|
|
218
218
|
# http://verylongurl...
|
219
|
-
displayed =
|
219
|
+
displayed = truncate_url match, options[:truncate]
|
220
220
|
|
221
221
|
# Now that we're done with the 'truncate' option, let's remove it...
|
222
222
|
options.delete(:truncate) unless !options
|
@@ -224,7 +224,7 @@ module StringAwesome
|
|
224
224
|
# Forces the presence of the 'http://'
|
225
225
|
match = "http://#{match}" unless match =~ SA_REGEXES[:protocol]
|
226
226
|
|
227
|
-
"<a href=\"#{match}\"#{
|
227
|
+
"<a href=\"#{match}\"#{apply_tag_attrs(options)}>#{displayed}</a>"
|
228
228
|
end
|
229
229
|
self
|
230
230
|
end
|
@@ -237,7 +237,7 @@ module StringAwesome
|
|
237
237
|
# - :class - Value for "class" attribute: <a href="url" class="link">url</a>
|
238
238
|
# - :target - Value for "target" attribute: <a href="url" target="_blank">url</a>
|
239
239
|
|
240
|
-
def
|
240
|
+
def apply_tag_attrs(options)
|
241
241
|
options ? options.reduce(' ') { |s, v| s << "#{v[0]}=\"#{v[1]}\" " }.gsub(/\s+$/, '') : ''
|
242
242
|
end
|
243
243
|
|
@@ -249,7 +249,7 @@ module StringAwesome
|
|
249
249
|
# t: (Hash|Integer)
|
250
250
|
# - Where the URL will be truncated.
|
251
251
|
|
252
|
-
def
|
252
|
+
def truncate_url(m, t)
|
253
253
|
t ? (t.instance_of?(Hash) ? m.ellipsis(t[:length], html_encoded: t[:html_encoded]) : m.ellipsis(t)) : m
|
254
254
|
end
|
255
255
|
|
@@ -276,10 +276,10 @@ module StringAwesome
|
|
276
276
|
str.gsub!(SA_REGEXES[:tweet]) do |match|
|
277
277
|
is_hashtag = match =~ /#/
|
278
278
|
|
279
|
-
unless
|
279
|
+
unless restricted?(is_hashtag, options[:only])
|
280
280
|
match = match.strip
|
281
281
|
attrs = is_hashtag ? ["search?q=%23#{match.gsub(/#/, '')}", :hashtag] : ["#{match.gsub(/@/, '')}", :tt_handle]
|
282
|
-
match = " <a href=\"https://twitter.com/#{attrs[0]}\"#{
|
282
|
+
match = " <a href=\"https://twitter.com/#{attrs[0]}\"#{apply_tag_attrs(options[attrs[1]])}>#{match}</a>"
|
283
283
|
end
|
284
284
|
|
285
285
|
match
|
@@ -295,7 +295,7 @@ module StringAwesome
|
|
295
295
|
# only: (Array)
|
296
296
|
# - Types allowed: :hashtag, :tt_handle.
|
297
297
|
|
298
|
-
def
|
298
|
+
def restricted?(is_hashtag, only)
|
299
299
|
only and ([:hashtag, :tt_handle] != only.sort) and ((is_hashtag and !only.include?(:hashtag)) or (!is_hashtag and !only.include?(:tt_handle)))
|
300
300
|
end
|
301
301
|
end
|
@@ -66,16 +66,16 @@ describe String do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
#
|
69
|
-
# String#
|
69
|
+
# String#sa_truncate
|
70
70
|
#
|
71
71
|
|
72
72
|
describe '#truncate' do
|
73
73
|
it 'shoud truncate the text' do
|
74
|
-
"It's a very loooooong text!".
|
74
|
+
"It's a very loooooong text!".sa_truncate(11).should eq "It's a very"
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'shoud truncate the text after a word' do
|
78
|
-
"It's a very loooooong text!".
|
78
|
+
"It's a very loooooong text!".sa_truncate(8, true).should eq "It's a"
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_awesome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Guedes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|