linkhum 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +3 -0
- data/README.md +4 -4
- data/lib/linkhum.rb +24 -17
- data/linkhum.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjZjODJiMGM1N2Q2ZjdlOTkyN2IyMThkNGQ4MDI3NjgyMzJhYzExZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2MwNTM2MGVmZjk5ZmZiMzMyOGU4YWFkN2Q2NDUyY2M0ODJlZWUzOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTY5ZGIzNzdkZjgzYWJkODcyYjJlZjYzMzM4NGRiNGViYjNhMjUxNTdmMTM0
|
10
|
+
NDNhMTY2NzE4NzNlMDY4ZWQ2NTA4OTE4ZmU0YzIyZGY1ZWY4Y2Y0NjZkNWFj
|
11
|
+
YTdkZGY1N2U3NmMzMTA0NjU2ZTlkYWRlYTgyZTcwNWI0NGU2NzA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWMwMDdhMzZjNzcxMDMyMTlhN2E0MmRkMGY1NDBmMzA0N2UwYWRjMjZjNGU5
|
14
|
+
MjljNGNmZTkxOTIxMDJlMjlkN2ZjZmY1MDhkODI0MjhmZTIyZjRmMWE0MzRm
|
15
|
+
N2NkMTM1OWQxYzQ1YTY1ZGFiYTlhODY3OWNhOTIwNzdhNGI5NDQ=
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -123,19 +123,19 @@ MyLinks.urlify("Hey, @jude!")
|
|
123
123
|
# => "Hey, <a href='http://oursite/users/jude'>@jude</a>!"
|
124
124
|
|
125
125
|
# nil or false means no replacements:
|
126
|
-
class
|
126
|
+
class MyLinksConditional < LinkHum
|
127
127
|
special /@(\S+)\b/ do |username|
|
128
128
|
"http://oursite/users/#{username}" if User.where(name: username).exists?
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
|
132
|
+
MyLinksConditional.urlify("So, our @dude and @unknownguy walk into a bar...")
|
133
133
|
# => "So, our <a href='http://oursite/users/dude'>@dude</a> and @unknownguy walk into a bar..."
|
134
134
|
```
|
135
135
|
|
136
136
|
Some `special` gotchas:
|
137
|
-
*
|
138
|
-
|
137
|
+
* in version 0.0.2, you can define any number of `special`s, but it's
|
138
|
+
totally up to you to have non-conflicting, clearly distinguished patterns;
|
139
139
|
* it passes to the block values by the same logic as `String#scan` does:
|
140
140
|
|
141
141
|
```ruby
|
data/lib/linkhum.rb
CHANGED
@@ -10,13 +10,12 @@ class LinkHum
|
|
10
10
|
new(text).urlify(options.merge(link_processor: block))
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
@special and
|
17
|
-
puts("Warning: redefining #{self}.special from #{caller.first}")
|
13
|
+
def specials
|
14
|
+
@specials ||= []
|
15
|
+
end
|
18
16
|
|
19
|
-
|
17
|
+
def special(pattern = nil, &block)
|
18
|
+
specials << [pattern, block]
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
@@ -52,18 +51,26 @@ class LinkHum
|
|
52
51
|
def process_text(str)
|
53
52
|
str = CGI.escapeHTML(str)
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
if pattern
|
58
|
-
str.gsub(pattern){|s|
|
59
|
-
if (u = block.call(*arguments(pattern, s)))
|
60
|
-
"<a href='#{screen_feet(u)}'>#{s}</a>"
|
61
|
-
else
|
62
|
-
s
|
63
|
-
end
|
64
|
-
}
|
65
|
-
else
|
54
|
+
if self.class.specials.empty?
|
66
55
|
str
|
56
|
+
else
|
57
|
+
replace_specials(str)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def replace_specials(str)
|
62
|
+
patterns = self.class.specials.map(&:first)
|
63
|
+
blocks = self.class.specials.map(&:last)
|
64
|
+
|
65
|
+
str.gsub(Regexp.union(patterns)) do |s|
|
66
|
+
pattern = patterns.detect{|p| s[p] == s}
|
67
|
+
idx = patterns.index(pattern)
|
68
|
+
|
69
|
+
if idx && (u = blocks[idx].call(*arguments(pattern, s)))
|
70
|
+
"<a href='#{screen_feet(u)}'>#{s}</a>"
|
71
|
+
else
|
72
|
+
s
|
73
|
+
end
|
67
74
|
end
|
68
75
|
end
|
69
76
|
|
data/linkhum.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linkhum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Makhotkin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -102,6 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- .dokaz
|
105
|
+
- CHANGELOG.md
|
105
106
|
- LICENSE.txt
|
106
107
|
- README.md
|
107
108
|
- lib/linkhum.rb
|