html-pipeline-hashtag 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 +4 -4
- data/README.md +5 -13
- data/html-pipeline-hashtag.gemspec +2 -0
- data/lib/html/pipeline/hashtag/hashtag_filter.rb +5 -1
- data/lib/html/pipeline/hashtag/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d21166a089e1eda7dc21a24dfa8412c07d0f4511
|
4
|
+
data.tar.gz: a7c0f0250b172fff934501bd4c5640f38c1d5941
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b16d8d24a24b8c0979eabaee8bc190a0b9dac8109ee3aeda07c574b90d87e3b23d9a6ca7163311667971acabce59898a11643f005b0508fb683a3793b0d0aa6
|
7
|
+
data.tar.gz: bdac44aff9d7a8d1b3f1d9ac0e9d4d39acd5503e408e4e7ba132f15bbf60153213476b1c56281d0b2282d1d819efe5bc6d4816b4d05d03ec9d6fa323adaf8528
|
data/README.md
CHANGED
@@ -39,21 +39,13 @@ context = {
|
|
39
39
|
:tag_url => '/tags/%{tag}'
|
40
40
|
}
|
41
41
|
|
42
|
-
pipeline.call(input, context)
|
43
|
-
# => <p>Hello <a href="/tags/world" target="_blank" class="hashtag">#world</a>!</p>
|
42
|
+
result = pipeline.call(input, context)
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
def extract_tags(*args)
|
49
|
-
tags = []
|
50
|
-
HTML::Pipeline::HashtagFilter.hashtags_in(*args) { |hashtag, tag| tags << tag }
|
51
|
-
|
52
|
-
tags
|
53
|
-
end
|
44
|
+
puts result[:output].to_html
|
45
|
+
# => "<p>Hello <a href=\"/tags/world\" target=\"_blank\" class=\"hashtag\">#world</a>!</p>\n"
|
54
46
|
|
55
|
-
|
56
|
-
# => ["world"
|
47
|
+
puts result[:hashtags]
|
48
|
+
# => ["world"]
|
57
49
|
```
|
58
50
|
|
59
51
|
## Contributing
|
@@ -26,6 +26,8 @@ module HTML
|
|
26
26
|
IGNORE_PARENTS = %w(pre code a style).to_set
|
27
27
|
|
28
28
|
def call
|
29
|
+
result[:hashtags] ||= []
|
30
|
+
|
29
31
|
search_text_nodes(doc).each do |node|
|
30
32
|
content = node.to_html
|
31
33
|
|
@@ -33,7 +35,7 @@ module HTML
|
|
33
35
|
next if has_ancestor?(node, IGNORE_PARENTS)
|
34
36
|
|
35
37
|
html = hashtag_link_filter(content, hashtag_pattern)
|
36
|
-
node.replace(html)
|
38
|
+
node.replace(html) unless html == content
|
37
39
|
end
|
38
40
|
|
39
41
|
doc
|
@@ -53,6 +55,8 @@ module HTML
|
|
53
55
|
|
54
56
|
def hashtag_link_filter(text, hashtag_pattern)
|
55
57
|
self.class.hashtags_in(text, hashtag_pattern) do |match, tag|
|
58
|
+
result[:hashtags] |= [tag]
|
59
|
+
|
56
60
|
link_to_hashtag(tag)
|
57
61
|
end
|
58
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline-hashtag
|
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
|
- German Antsiferov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html-pipeline
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: github-markdown
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.5'
|
41
55
|
description: HTML Pipeline filter that replaces hashtags with links.
|
42
56
|
email:
|
43
57
|
- dxdy@bk.ru
|