twitter-text 1.4.17 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/README.rdoc +3 -13
- data/Rakefile +1 -0
- data/lib/twitter-text/autolink.rb +436 -0
- data/lib/twitter-text/deprecation.rb +15 -0
- data/lib/{extractor.rb → twitter-text/extractor.rb} +125 -41
- data/lib/{hithighlighter.rb → twitter-text/hit_highlighter.rb} +5 -7
- data/lib/{regex.rb → twitter-text/regex.rb} +33 -23
- data/lib/twitter-text/rewriter.rb +59 -0
- data/lib/{unicode.rb → twitter-text/unicode.rb} +0 -0
- data/lib/{validation.rb → twitter-text/validation.rb} +17 -3
- data/lib/twitter-text.rb +13 -7
- data/spec/autolinking_spec.rb +192 -16
- data/spec/extractor_spec.rb +12 -0
- data/spec/rewriter_spec.rb +2 -11
- data/spec/spec_helper.rb +1 -1
- data/test/conformance_test.rb +128 -129
- data/twitter-text.gemspec +1 -1
- metadata +14 -12
- data/lib/autolink.rb +0 -266
- data/lib/rewriter.rb +0 -65
data/lib/rewriter.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module Twitter
|
2
|
-
# A module provides base methods to rewrite usernames, lists, hashtags and URLs.
|
3
|
-
module Rewriter extend self
|
4
|
-
def rewrite(text, options = {})
|
5
|
-
[:hashtags, :urls, :usernames_or_lists].inject(text) do |key|
|
6
|
-
send("rewrite_#{key}", text, &options[key]) if options[key]
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def rewrite_usernames_or_lists(text)
|
11
|
-
new_text = ""
|
12
|
-
|
13
|
-
# this -1 flag allows strings ending in ">" to work
|
14
|
-
text.to_s.split(/[<>]/, -1).each_with_index do |chunk, index|
|
15
|
-
if index != 0
|
16
|
-
new_text << ((index % 2 == 0) ? ">" : "<")
|
17
|
-
end
|
18
|
-
|
19
|
-
if index % 4 != 0
|
20
|
-
new_text << chunk
|
21
|
-
else
|
22
|
-
new_text << chunk.gsub(Twitter::Regex[:auto_link_usernames_or_lists]) do
|
23
|
-
before, at, user, slash_listname, after = $1, $2, $3, $4, $'
|
24
|
-
if slash_listname
|
25
|
-
# the link is a list
|
26
|
-
"#{before}#{yield(at, user, slash_listname)}"
|
27
|
-
else
|
28
|
-
if after =~ Twitter::Regex[:end_screen_name_match]
|
29
|
-
# Followed by something that means we don't autolink
|
30
|
-
"#{before}#{at}#{user}#{slash_listname}"
|
31
|
-
else
|
32
|
-
# this is a screen name
|
33
|
-
"#{before}#{yield(at, user, nil)}#{slash_listname}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
new_text
|
41
|
-
end
|
42
|
-
|
43
|
-
def rewrite_hashtags(text)
|
44
|
-
text.to_s.gsub(Twitter::Regex[:auto_link_hashtags]) do
|
45
|
-
before, hash, hashtag, after = $1, $2, $3, $'
|
46
|
-
if after =~ Twitter::Regex[:end_hashtag_match]
|
47
|
-
"#{before}#{hash}#{hashtag}"
|
48
|
-
else
|
49
|
-
"#{before}#{yield(hash, hashtag)}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def rewrite_urls(text)
|
55
|
-
text.to_s.gsub(Twitter::Regex[:valid_url]) do
|
56
|
-
all, before, url, protocol, domain, path, query_string = $1, $2, $3, $4, $5, $6, $7
|
57
|
-
if protocol && !protocol.empty?
|
58
|
-
"#{before}#{yield(url)}"
|
59
|
-
else
|
60
|
-
all
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|