string_awesome 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/string_awesome/awesome_methods.rb +7 -5
- data/lib/string_awesome/version.rb +1 -1
- data/spec/awesome_methods_spec.rb +31 -7
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NzYxYjA3Mjc0YmM1OTdmMWRkOTE2NTg1MzNkN2UxMzE3YWJlNDg1Mg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e7a2d49fdaa2999e14bbd47104154df9831f39f
|
4
|
+
data.tar.gz: 77f20be63fb8cde1a961ccd6678b0961f6a507f8
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MTE5OTZlZDEzYjZjMGYxMDJiMzg2NzBmMzk4YTY1ZDk3YzhjZTczNDg0YTli
|
11
|
-
ZGY3ZWQ2MTE1OWYyYWFjMGM4MTlhNWY2NmJmMDE5NTAzNzQ3YjY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NmI5MWVhNzk2MjI5NTVjOWU3NjYxM2Y5MmQ2NjRjNmRkMTA0NDlmZGQ4NDMw
|
14
|
-
MWI1NWM3ZWI1ZDY5OWY2ZTRkOGJlY2U5YzY1YTgwMDI3ZmVhYTE4NmUwZTQx
|
15
|
-
NDZhOThlY2U1ODI1NThkYTc0ZjNlYWI3Y2U5MjhlYjhhMmQ4ZmQ=
|
6
|
+
metadata.gz: 1dec6e517d7750c18e9a95b955393a7f03d83743a939c06d1dec88d4f2a43824f1fed7e5f194d37ec804c6d93f69bd516ea0d3f723e272780fc845dde44e8f1a
|
7
|
+
data.tar.gz: c43e8eae6e433c0df800c0a62ddd214a1ba976eebc2e46316978fbbba90081df0a20842c061f78d7dfbf6c390c6db7c55ba11dad84a9f21010004dbdf96c28dd
|
@@ -257,11 +257,14 @@ module StringAwesome
|
|
257
257
|
# Arguments:
|
258
258
|
# options: (Hash)
|
259
259
|
# - Options such as:
|
260
|
-
# - :only
|
260
|
+
# - :only - Array of Symbols restricting what will be matched in the text;
|
261
|
+
# - :url - Attributes for URLs <a> links;
|
262
|
+
# - :tt_handle - Attributes for Twitter handles <a> links;
|
263
|
+
# - :hashtag - Attributes for hashtag <a> links.
|
261
264
|
|
262
265
|
def tweetify(options = {})
|
263
266
|
# Applies linkify unless there's some restriction
|
264
|
-
str = options[:only] ? self : self.linkify(
|
267
|
+
str = options[:only] ? self : self.linkify(options[:url] || {})
|
265
268
|
|
266
269
|
# Iterates with the matched expressions
|
267
270
|
str.gsub!(SA_TWEET_REGEX) do |match|
|
@@ -269,9 +272,8 @@ module StringAwesome
|
|
269
272
|
|
270
273
|
unless _restricted?(is_hashtag, options[:only])
|
271
274
|
match = match.strip
|
272
|
-
attrs = is_hashtag ? [
|
273
|
-
|
274
|
-
match = " <a href=\"https://twitter.com/#{attrs[:href]}\" target=\"_blank\" class=\"#{attrs[:class]}\">#{match}</a>"
|
275
|
+
attrs = is_hashtag ? ["search?q=%23#{match.gsub(/#/, '')}", :hashtag] : ["#{match.gsub(/@/, '')}", :tt_handle]
|
276
|
+
match = " <a href=\"https://twitter.com/#{attrs[0]}\"#{_apply_tag_attrs(options[attrs[1]])}>#{match}</a>"
|
275
277
|
end
|
276
278
|
|
277
279
|
match
|
@@ -276,51 +276,75 @@ end
|
|
276
276
|
describe 'String#tweetify' do
|
277
277
|
it 'should find Twitter handles (@username) and wrap them in anchor tags' do
|
278
278
|
str = 'What about to follow @tiagopog?'
|
279
|
-
this = 'What about to follow <a href="https://twitter.com/tiagopog"
|
279
|
+
this = 'What about to follow <a href="https://twitter.com/tiagopog">@tiagopog</a>?'
|
280
280
|
str.tweetify.should eq this
|
281
281
|
end
|
282
282
|
|
283
|
+
it 'should find Twitter handles (@username) and wrap them in anchor tags (attributes included)' do
|
284
|
+
str = 'What about to follow @tiagopog?'
|
285
|
+
this = 'What about to follow <a href="https://twitter.com/tiagopog" target="_blank" class="tt-handle">@tiagopog</a>?'
|
286
|
+
str.tweetify(tt_handle: { target: '_blank', class: 'tt-handle' }).should eq this
|
287
|
+
end
|
288
|
+
|
283
289
|
it 'should not match foo@bar as being a Twitter handle' do
|
284
290
|
'foo@bar'.tweetify.should eq 'foo@bar'
|
285
291
|
end
|
286
292
|
|
287
293
|
it 'should find hashtags (#hashtag) and wrap them in anchor tags' do
|
288
294
|
str = "Let's code! #rubyrocks"
|
289
|
-
this = "Let's code! <a href=\"https://twitter.com/search?q=%23rubyrocks\"
|
295
|
+
this = "Let's code! <a href=\"https://twitter.com/search?q=%23rubyrocks\">#rubyrocks</a>"
|
290
296
|
str.tweetify.should eq this
|
291
297
|
end
|
292
298
|
|
299
|
+
it 'should find hashtags (#hashtag) and wrap them in anchor tags (attributes included)' do
|
300
|
+
str = "Let's code! #rubyrocks"
|
301
|
+
this = "Let's code! <a href=\"https://twitter.com/search?q=%23rubyrocks\" target=\"_blank\" class=\"hashtag\">#rubyrocks</a>"
|
302
|
+
str.tweetify(hashtag: { target: '_blank', class: 'hashtag' }).should eq this
|
303
|
+
end
|
304
|
+
|
293
305
|
it 'should not match foo#bar as being a hashtag' do
|
294
306
|
'foo#bar'.tweetify.should eq 'foo#bar'
|
295
307
|
end
|
296
308
|
|
297
309
|
it 'should find URLs and wrap them in anchor tags' do
|
298
310
|
str = 'Tweet some cool link: http://foobar.com'
|
299
|
-
this = 'Tweet some cool link: <a href="http://foobar.com"
|
311
|
+
this = 'Tweet some cool link: <a href="http://foobar.com">http://foobar.com</a>'
|
300
312
|
str.tweetify.should eq this
|
301
313
|
end
|
302
314
|
|
315
|
+
it 'should find URLs and wrap them in anchor tags (attributes included)' do
|
316
|
+
str = 'Tweet some cool link: http://foobar.com'
|
317
|
+
this = 'Tweet some cool link: <a href="http://foobar.com" class="link">http://foobar.com</a>'
|
318
|
+
str.tweetify(url: { class: 'link' }).should eq this
|
319
|
+
end
|
320
|
+
|
303
321
|
it 'should find links, Twitter handles, hashtags and wrap them in anchor tags' do
|
304
322
|
str = 'Cool link from @tiagopog! http://foobar.com #rubyrocks'
|
305
|
-
this = 'Cool link from <a href="https://twitter.com/tiagopog"
|
323
|
+
this = 'Cool link from <a href="https://twitter.com/tiagopog">@tiagopog</a>! <a href="http://foobar.com">http://foobar.com</a> <a href="https://twitter.com/search?q=%23rubyrocks">#rubyrocks</a>'
|
306
324
|
str.tweetify.should eq this
|
307
325
|
end
|
308
326
|
|
309
327
|
it 'should find only Twitter handles' do
|
310
328
|
str = 'Cool link from @tiagopog! http://foobar.com #rubyrocks'
|
311
|
-
this = 'Cool link from <a href="https://twitter.com/tiagopog"
|
329
|
+
this = 'Cool link from <a href="https://twitter.com/tiagopog">@tiagopog</a>! http://foobar.com #rubyrocks'
|
312
330
|
str.tweetify(only: [:tt_handle]).should eq this
|
313
331
|
end
|
314
332
|
|
315
333
|
it 'should find only hashtags' do
|
316
334
|
str = 'Cool link from @tiagopog! http://foobar.com #rubyrocks'
|
317
|
-
this = 'Cool link from @tiagopog! http://foobar.com <a href="https://twitter.com/search?q=%23rubyrocks"
|
335
|
+
this = 'Cool link from @tiagopog! http://foobar.com <a href="https://twitter.com/search?q=%23rubyrocks">#rubyrocks</a>'
|
318
336
|
str.tweetify(only: [:hashtag]).should eq this
|
319
337
|
end
|
320
338
|
|
321
339
|
it 'should not find URLs, just hashtags and Twitter handles' do
|
322
340
|
str = 'Cool link from @tiagopog! http://foobar.com #rubyrocks'
|
323
|
-
this = 'Cool link from <a href="https://twitter.com/tiagopog"
|
341
|
+
this = 'Cool link from <a href="https://twitter.com/tiagopog">@tiagopog</a>! http://foobar.com <a href="https://twitter.com/search?q=%23rubyrocks">#rubyrocks</a>'
|
324
342
|
str.tweetify(only: [:hashtag, :tt_handle]).should eq this
|
325
343
|
end
|
344
|
+
|
345
|
+
it 'should not find URLs, just hashtags and Twitter handles' do
|
346
|
+
str = 'Cool link from @tiagopog! http://foobar.com #rubyrocks'
|
347
|
+
this = 'Cool link from <a href="https://twitter.com/tiagopog" target="_blank" class="tt-handle">@tiagopog</a>! http://foobar.com <a href="https://twitter.com/search?q=%23rubyrocks" target="_blank" class="hashtag">#rubyrocks</a>'
|
348
|
+
str.tweetify(only: [:hashtag, :tt_handle], tt_handle: { target: '_blank', class: 'tt-handle' }, hashtag: { target: '_blank', class: 'hashtag' }).should eq this
|
349
|
+
end
|
326
350
|
end
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Guedes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
- - <
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.0'
|
30
30
|
- - <
|
@@ -62,14 +62,14 @@ dependencies:
|
|
62
62
|
name: rspec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - '>='
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - '>='
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
@@ -90,14 +90,14 @@ dependencies:
|
|
90
90
|
name: rake
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- -
|
93
|
+
- - '>='
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
description: Awesome and easy-to-use extensions to Ruby String class.
|
@@ -130,17 +130,17 @@ require_paths:
|
|
130
130
|
- lib
|
131
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
132
132
|
requirements:
|
133
|
-
- -
|
133
|
+
- - '>='
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- -
|
138
|
+
- - '>='
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.1.
|
143
|
+
rubygems_version: 2.1.5
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Extensions for Ruby String class
|