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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99e9948fdc73821d691dff56564bd95ba226cb22
4
- data.tar.gz: 1376e1747eb940625c622414ee3f461cdfb533df
3
+ metadata.gz: d21166a089e1eda7dc21a24dfa8412c07d0f4511
4
+ data.tar.gz: a7c0f0250b172fff934501bd4c5640f38c1d5941
5
5
  SHA512:
6
- metadata.gz: fdffdae4b8dfda259d5b0cff90f0ac8463325ba17af51a3ead9570824c0a36475ac1344c1ec97c46735299bb85da0dc10a1c4a2c5f119e7817e9cca5863b1902
7
- data.tar.gz: 8eb869e289967a69541a1944b641539e86624a83da12f01182f5ed17c90d0d84f2956ba5dcb2b8040dfee88c3c1aaefa47e2678313b8f9370e27adb528bba8c7
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
- extract_tags("Hello #world! #welcome")
56
- # => ["world", "welcome"]
47
+ puts result[:hashtags]
48
+ # => ["world"]
57
49
  ```
58
50
 
59
51
  ## Contributing
@@ -19,5 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'html-pipeline', '~> 1.11.0'
22
+
22
23
  spec.add_development_dependency "rspec", '~> 3.2.0'
24
+ spec.add_development_dependency "github-markdown", "~> 0.5"
23
25
  end
@@ -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
@@ -1,7 +1,7 @@
1
1
  module Html
2
2
  module Pipeline
3
3
  module Hashtag
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  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.1
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-05 00:00:00.000000000 Z
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