twitter-text 1.3.0 → 1.3.1
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.
- data/Gemfile.lock +21 -21
- data/lib/autolink.rb +22 -4
- data/lib/regex.rb +1 -1
- data/spec/autolinking_spec.rb +32 -0
- data/twitter-text.gemspec +1 -1
- metadata +24 -24
data/Gemfile.lock
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
twitter-text (1.3.
|
4
|
+
twitter-text (1.3.1)
|
5
5
|
actionpack
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
abstract (1.0.0)
|
11
|
-
actionpack (3.0.
|
12
|
-
activemodel (= 3.0.
|
13
|
-
activesupport (= 3.0.
|
11
|
+
actionpack (3.0.3)
|
12
|
+
activemodel (= 3.0.3)
|
13
|
+
activesupport (= 3.0.3)
|
14
14
|
builder (~> 2.1.2)
|
15
15
|
erubis (~> 2.6.6)
|
16
|
-
i18n (~> 0.4
|
16
|
+
i18n (~> 0.4)
|
17
17
|
rack (~> 1.2.1)
|
18
|
-
rack-mount (~> 0.6.
|
19
|
-
rack-test (~> 0.5.
|
18
|
+
rack-mount (~> 0.6.13)
|
19
|
+
rack-test (~> 0.5.6)
|
20
20
|
tzinfo (~> 0.3.23)
|
21
|
-
activemodel (3.0.
|
22
|
-
activesupport (= 3.0.
|
21
|
+
activemodel (3.0.3)
|
22
|
+
activesupport (= 3.0.3)
|
23
23
|
builder (~> 2.1.2)
|
24
|
-
i18n (~> 0.4
|
25
|
-
activesupport (3.0.
|
24
|
+
i18n (~> 0.4)
|
25
|
+
activesupport (3.0.3)
|
26
26
|
builder (2.1.2)
|
27
27
|
diff-lcs (1.1.2)
|
28
28
|
erubis (2.6.6)
|
29
29
|
abstract (>= 1.0.0)
|
30
|
-
i18n (0.
|
31
|
-
nokogiri (1.4.
|
32
|
-
nokogiri (1.4.
|
30
|
+
i18n (0.5.0)
|
31
|
+
nokogiri (1.4.4)
|
32
|
+
nokogiri (1.4.4-java)
|
33
33
|
weakling (>= 0.0.3)
|
34
34
|
rack (1.2.1)
|
35
35
|
rack-mount (0.6.13)
|
@@ -37,14 +37,14 @@ GEM
|
|
37
37
|
rack-test (0.5.6)
|
38
38
|
rack (>= 1.0)
|
39
39
|
rake (0.8.7)
|
40
|
-
rspec (2.
|
41
|
-
rspec-core (~> 2.
|
42
|
-
rspec-expectations (~> 2.
|
43
|
-
rspec-mocks (~> 2.
|
44
|
-
rspec-core (2.1
|
45
|
-
rspec-expectations (2.
|
40
|
+
rspec (2.3.0)
|
41
|
+
rspec-core (~> 2.3.0)
|
42
|
+
rspec-expectations (~> 2.3.0)
|
43
|
+
rspec-mocks (~> 2.3.0)
|
44
|
+
rspec-core (2.3.1)
|
45
|
+
rspec-expectations (2.3.0)
|
46
46
|
diff-lcs (~> 1.1.2)
|
47
|
-
rspec-mocks (2.
|
47
|
+
rspec-mocks (2.3.0)
|
48
48
|
simplecov (0.3.7)
|
49
49
|
simplecov-html (>= 0.3.7)
|
50
50
|
simplecov-html (0.3.9)
|
data/lib/autolink.rb
CHANGED
@@ -12,6 +12,8 @@ module Twitter
|
|
12
12
|
DEFAULT_USERNAME_CLASS = "username"
|
13
13
|
# Default CSS class for auto-linked hashtags (along with the url class)
|
14
14
|
DEFAULT_HASHTAG_CLASS = "hashtag"
|
15
|
+
# Default target for auto-linked urls (nil will not add a target attribute)
|
16
|
+
DEFAULT_TARGET = nil
|
15
17
|
# HTML attribute for robot nofollow behavior (default)
|
16
18
|
HTML_ATTR_NO_FOLLOW = " rel=\"nofollow\""
|
17
19
|
|
@@ -42,6 +44,7 @@ module Twitter
|
|
42
44
|
# <tt>:hashtag_url_base</tt>:: the value for <tt>href</tt> attribute on hashtag links. The <tt>#hashtag</tt> (minus the <tt>#</tt>) will be appended at the end of this.
|
43
45
|
# <tt>:suppress_lists</tt>:: disable auto-linking to lists
|
44
46
|
# <tt>:suppress_no_follow</tt>:: Do not add <tt>rel="nofollow"</tt> to auto-linked items
|
47
|
+
# <tt>:target</tt>:: add <tt>target="window_name"</tt> to auto-linked items
|
45
48
|
def auto_link(text, options = {})
|
46
49
|
auto_link_usernames_or_lists(
|
47
50
|
auto_link_urls_custom(
|
@@ -61,6 +64,7 @@ module Twitter
|
|
61
64
|
# <tt>:list_url_base</tt>:: the value for <tt>href</tt> attribute on list links. The <tt>@username/list</tt> (minus the <tt>@</tt>) will be appended at the end of this.
|
62
65
|
# <tt>:suppress_lists</tt>:: disable auto-linking to lists
|
63
66
|
# <tt>:suppress_no_follow</tt>:: Do not add <tt>rel="nofollow"</tt> to auto-linked items
|
67
|
+
# <tt>:target</tt>:: add <tt>target="window_name"</tt> to auto-linked items
|
64
68
|
def auto_link_usernames_or_lists(text, options = {}) # :yields: list_or_username
|
65
69
|
options = options.dup
|
66
70
|
options[:url_class] ||= DEFAULT_URL_CLASS
|
@@ -68,8 +72,9 @@ module Twitter
|
|
68
72
|
options[:username_class] ||= DEFAULT_USERNAME_CLASS
|
69
73
|
options[:username_url_base] ||= "http://twitter.com/"
|
70
74
|
options[:list_url_base] ||= "http://twitter.com/"
|
71
|
-
|
75
|
+
options[:target] ||= DEFAULT_TARGET
|
72
76
|
|
77
|
+
extra_html = HTML_ATTR_NO_FOLLOW unless options[:suppress_no_follow]
|
73
78
|
new_text = ""
|
74
79
|
|
75
80
|
# this -1 flag allows strings ending in ">" to work
|
@@ -87,7 +92,7 @@ module Twitter
|
|
87
92
|
# the link is a list
|
88
93
|
chunk = list = "#{user}#{slash_listname}"
|
89
94
|
chunk = yield(list) if block_given?
|
90
|
-
"#{before}#{at}<a class=\"#{options[:url_class]} #{options[:list_class]}\" href=\"#{html_escape(options[:list_url_base])}#{html_escape(list.downcase)}\"#{extra_html}>#{html_escape(chunk)}</a>"
|
95
|
+
"#{before}#{at}<a class=\"#{options[:url_class]} #{options[:list_class]}\" #{target_tag(options)}href=\"#{html_escape(options[:list_url_base])}#{html_escape(list.downcase)}\"#{extra_html}>#{html_escape(chunk)}</a>"
|
91
96
|
else
|
92
97
|
if after =~ Twitter::Regex[:end_screen_name_match]
|
93
98
|
# Followed by something that means we don't autolink
|
@@ -96,7 +101,7 @@ module Twitter
|
|
96
101
|
# this is a screen name
|
97
102
|
chunk = user
|
98
103
|
chunk = yield(chunk) if block_given?
|
99
|
-
"#{before}#{at}<a class=\"#{options[:url_class]} #{options[:username_class]}\" href=\"#{html_escape(options[:username_url_base])}#{html_escape(chunk)}\"#{extra_html}>#{html_escape(chunk)}</a>"
|
104
|
+
"#{before}#{at}<a class=\"#{options[:url_class]} #{options[:username_class]}\" #{target_tag(options)}href=\"#{html_escape(options[:username_url_base])}#{html_escape(chunk)}\"#{extra_html}>#{html_escape(chunk)}</a>"
|
100
105
|
end
|
101
106
|
end
|
102
107
|
end
|
@@ -113,11 +118,13 @@ module Twitter
|
|
113
118
|
# <tt>:hashtag_class</tt>:: class to add to hashtag <tt><a></tt> tags
|
114
119
|
# <tt>:hashtag_url_base</tt>:: the value for <tt>href</tt> attribute. The hashtag text (minus the <tt>#</tt>) will be appended at the end of this.
|
115
120
|
# <tt>:suppress_no_follow</tt>:: Do not add <tt>rel="nofollow"</tt> to auto-linked items
|
121
|
+
# <tt>:target</tt>:: add <tt>target="window_name"</tt> to auto-linked items
|
116
122
|
def auto_link_hashtags(text, options = {}) # :yields: hashtag_text
|
117
123
|
options = options.dup
|
118
124
|
options[:url_class] ||= DEFAULT_URL_CLASS
|
119
125
|
options[:hashtag_class] ||= DEFAULT_HASHTAG_CLASS
|
120
126
|
options[:hashtag_url_base] ||= "http://twitter.com/search?q=%23"
|
127
|
+
options[:target] ||= DEFAULT_TARGET
|
121
128
|
extra_html = HTML_ATTR_NO_FOLLOW unless options[:suppress_no_follow]
|
122
129
|
|
123
130
|
text.gsub(Twitter::Regex[:auto_link_hashtags]) do
|
@@ -125,7 +132,7 @@ module Twitter
|
|
125
132
|
hash = $2
|
126
133
|
text = $3
|
127
134
|
text = yield(text) if block_given?
|
128
|
-
"#{before}<a href=\"#{options[:hashtag_url_base]}#{html_escape(text)}\" title=\"##{html_escape(text)}\" class=\"#{options[:url_class]} #{options[:hashtag_class]}\"#{extra_html}>#{html_escape(hash)}#{html_escape(text)}</a>"
|
135
|
+
"#{before}<a href=\"#{options[:hashtag_url_base]}#{html_escape(text)}\" title=\"##{html_escape(text)}\" #{target_tag(options)}class=\"#{options[:url_class]} #{options[:hashtag_class]}\"#{extra_html}>#{html_escape(hash)}#{html_escape(text)}</a>"
|
129
136
|
end
|
130
137
|
end
|
131
138
|
|
@@ -148,5 +155,16 @@ module Twitter
|
|
148
155
|
end
|
149
156
|
end
|
150
157
|
|
158
|
+
private
|
159
|
+
|
160
|
+
def target_tag(options)
|
161
|
+
target_option = options[:target]
|
162
|
+
if target_option.blank?
|
163
|
+
""
|
164
|
+
else
|
165
|
+
"target=\"#{html_escape(target_option)}\""
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
151
169
|
end
|
152
170
|
end
|
data/lib/regex.rb
CHANGED
@@ -70,7 +70,7 @@ module Twitter
|
|
70
70
|
)/ix
|
71
71
|
# Valid end-of-path chracters (so /foo. does not gobble the period).
|
72
72
|
# 1. Allow =&# for empty URL parameters and other URL-join artifacts
|
73
|
-
REGEXEN[:valid_url_path_ending_chars] = /[a-z0-9=_
|
73
|
+
REGEXEN[:valid_url_path_ending_chars] = /[a-z0-9=_#\/\+\-]|#{REGEXEN[:wikipedia_disambiguation]}/io
|
74
74
|
REGEXEN[:valid_url_query_chars] = /[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~]/i
|
75
75
|
REGEXEN[:valid_url_query_ending_chars] = /[a-z0-9_&=#\/]/i
|
76
76
|
REGEXEN[:valid_url] = %r{
|
data/spec/autolinking_spec.rb
CHANGED
@@ -517,6 +517,38 @@ describe Twitter::Autolink do
|
|
517
517
|
|
518
518
|
end
|
519
519
|
|
520
|
+
describe "autolinking options" do
|
521
|
+
it "should apply :url_class as a CSS class" do
|
522
|
+
linked = TestAutolink.new.auto_link("http://example.com/", :url_class => 'myclass')
|
523
|
+
linked.should have_autolinked_url('http://example.com/')
|
524
|
+
linked.should match(/myclass/)
|
525
|
+
end
|
526
|
+
|
527
|
+
it "should add rel=nofollow by default" do
|
528
|
+
linked = TestAutolink.new.auto_link("http://example.com/")
|
529
|
+
linked.should have_autolinked_url('http://example.com/')
|
530
|
+
linked.should match(/nofollow/)
|
531
|
+
end
|
532
|
+
|
533
|
+
it "should not add rel=nofollow when passed :suppress_no_follow" do
|
534
|
+
linked = TestAutolink.new.auto_link("http://example.com/", :suppress_no_follow => true)
|
535
|
+
linked.should have_autolinked_url('http://example.com/')
|
536
|
+
linked.should_not match(/nofollow/)
|
537
|
+
end
|
538
|
+
|
539
|
+
it "should not add a target attribute by default" do
|
540
|
+
linked = TestAutolink.new.auto_link("http://example.com/")
|
541
|
+
linked.should have_autolinked_url('http://example.com/')
|
542
|
+
linked.should_not match(/target=/)
|
543
|
+
end
|
544
|
+
|
545
|
+
it "should respect the :target option" do
|
546
|
+
linked = TestAutolink.new.auto_link("http://example.com/", :target => 'mywindow')
|
547
|
+
linked.should have_autolinked_url('http://example.com/')
|
548
|
+
linked.should match(/target="mywindow"/)
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
520
552
|
describe "html_escape" do
|
521
553
|
before do
|
522
554
|
@linker = TestAutolink.new
|
data/twitter-text.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "twitter-text"
|
3
|
-
s.version = "1.3.
|
3
|
+
s.version = "1.3.1"
|
4
4
|
s.authors = ["Matt Sanford", "Patrick Ewing", "Ben Cherry", "Britt Selvitelle", "Raffi Krikorian"]
|
5
5
|
s.email = ["matt@twitter.com", "patrick.henry.ewing@gmail.com", "bcherry@gmail.com", "bs@brittspace.com", "raffi@twitter.com"]
|
6
6
|
s.homepage = "http://twitter.com"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter-text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 1
|
10
|
+
version: 1.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Sanford
|
@@ -19,13 +19,11 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date:
|
22
|
+
date: 2011-01-06 00:00:00 -08:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
|
27
|
-
prerelease: false
|
28
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
29
27
|
none: false
|
30
28
|
requirements:
|
31
29
|
- - ">="
|
@@ -34,12 +32,12 @@ dependencies:
|
|
34
32
|
segments:
|
35
33
|
- 0
|
36
34
|
version: "0"
|
35
|
+
requirement: *id001
|
36
|
+
name: nokogiri
|
37
|
+
prerelease: false
|
37
38
|
type: :development
|
38
|
-
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
|
-
|
41
|
-
prerelease: false
|
42
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
43
41
|
none: false
|
44
42
|
requirements:
|
45
43
|
- - ">="
|
@@ -48,12 +46,12 @@ dependencies:
|
|
48
46
|
segments:
|
49
47
|
- 0
|
50
48
|
version: "0"
|
49
|
+
requirement: *id002
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
51
52
|
type: :development
|
52
|
-
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
|
55
|
-
prerelease: false
|
56
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
55
|
none: false
|
58
56
|
requirements:
|
59
57
|
- - ">="
|
@@ -62,12 +60,12 @@ dependencies:
|
|
62
60
|
segments:
|
63
61
|
- 0
|
64
62
|
version: "0"
|
63
|
+
requirement: *id003
|
64
|
+
name: rspec
|
65
|
+
prerelease: false
|
65
66
|
type: :development
|
66
|
-
version_requirements: *id003
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
|
69
|
-
prerelease: false
|
70
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
69
|
none: false
|
72
70
|
requirements:
|
73
71
|
- - ">="
|
@@ -76,12 +74,12 @@ dependencies:
|
|
76
74
|
segments:
|
77
75
|
- 0
|
78
76
|
version: "0"
|
77
|
+
requirement: *id004
|
78
|
+
name: simplecov
|
79
|
+
prerelease: false
|
79
80
|
type: :development
|
80
|
-
version_requirements: *id004
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
|
83
|
-
prerelease: false
|
84
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
85
83
|
none: false
|
86
84
|
requirements:
|
87
85
|
- - ">="
|
@@ -90,8 +88,10 @@ dependencies:
|
|
90
88
|
segments:
|
91
89
|
- 0
|
92
90
|
version: "0"
|
91
|
+
requirement: *id005
|
92
|
+
name: actionpack
|
93
|
+
prerelease: false
|
93
94
|
type: :runtime
|
94
|
-
version_requirements: *id005
|
95
95
|
description: A gem that provides text handling for Twitter
|
96
96
|
email:
|
97
97
|
- matt@twitter.com
|