html-pipeline-gitlab 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: e2152131cb71f56ec9919f5fd035e3f3419f2e09
4
- data.tar.gz: 882d2777949b385ded5924d1d78a9c5d1b99ede7
3
+ metadata.gz: 761eebe497d43f7d750b204380a1a96aa97ea18a
4
+ data.tar.gz: 3359741032f9c25e5ad31dda0aada680ea5d9081
5
5
  SHA512:
6
- metadata.gz: a2f2b7a5e95970e8a4b1c342a9bd9c39c706a00a49a5852b7200103fda226ce7fea99098a5361d197b96a1a1dde461130a09aeabae07a99e437970d2d60a9d3e
7
- data.tar.gz: 299f4f94a6a33cb0d424a80662c6cbf17d3c01e6cea370209727ae06c2f65e20975122cbdba29a5134f5034745c27765111b736e83139297ff1f10ab2558a933
6
+ metadata.gz: bae915c13ad3623c4e788f4c8b021cee84569392095f884ad85ea6ecb1aa651f1dde1ec39c7b4e2cf0c69357a5470e5ea28162304aaca0db8457a484f2899b64
7
+ data.tar.gz: aead33707d35f534dee9495af9a4d581e5de332b611f3da8a5794c78c84d27090ba3ca5458aa75ee4d7ddf3365848ce81bea01ac9e846a7230dfbb93c8ea6cad
data/.travis.yml CHANGED
@@ -9,3 +9,5 @@ install:
9
9
  - travis_retry bundle config build.nokogiri --use-system-libraries
10
10
  - travis_retry bundle install
11
11
  script: rake test
12
+ notifications:
13
+ email: false
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Html::Pipeline::Gitlab
2
2
 
3
- TODO: Write a gem description
3
+ This gem implements various filters for [html-pipeline](https://github.com/jch/html-pipeline)
4
+ used by [GitLab](https://about.gitlab.com).
5
+
6
+ ## Code Status
7
+
8
+ [![Build Status](https://semaphoreapp.com/api/v1/projects/b9b808be-6c72-4e76-ae62-79b3a25a022a/243365/badge.png)](https://semaphoreapp.com/razer6/html-pipeline-gitlab)
4
9
 
5
10
  ## Installation
6
11
 
@@ -18,13 +23,9 @@ Or install it yourself as:
18
23
 
19
24
  $ gem install html-pipeline-gitlab
20
25
 
21
- ## Usage
22
-
23
- TODO: Write usage instructions here
24
-
25
26
  ## Contributing
26
27
 
27
- 1. Fork it ( https://github.com/[my-github-username]/html-pipeline-gitlab/fork )
28
+ 1. Fork it ( https://github.com/razer6/html-pipeline-gitlab/fork )
28
29
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
30
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
31
  4. Push to the branch (`git push origin my-new-feature`)
@@ -5,85 +5,77 @@ require 'html/pipeline/filter'
5
5
 
6
6
  module HTML
7
7
  class Pipeline
8
- # HTML filter that replaces :emoji: with images.
9
- #
10
- # Context:
11
- # :asset_root (required) - base url to link to emoji sprite
12
- # :asset_path (optional) - url path to link to emoji sprite. :file_name can be used as a placeholder for the sprite file name. If no asset_path is set "emoji/:file_name" is used.
13
- class GitLabEmojiFilter < Filter
14
- def call
15
- doc.search('text()').each do |node|
16
- content = node.to_html
17
- next if !content.include?(':')
18
- next if has_ancestor?(node, %w(pre code))
19
- html = emoji_image_filter(content)
20
- next if html == content
21
- node.replace(html)
8
+ class GitLab
9
+ # HTML filter that replaces :emoji: with images.
10
+ #
11
+ # Context:
12
+ # :asset_root (required) - base url to link to emoji sprite
13
+ # :asset_path (optional) - url path to link to emoji sprite.
14
+ # :file_name can be used as a placeholder for the sprite file name.
15
+ # If no asset_path is set "emoji/:file_name" is used.
16
+ class GitLabEmojiFilter < Filter
17
+ def call
18
+ doc.search('text()').each do |node|
19
+ content = node.to_html
20
+ next if !content.include?(':')
21
+ next if has_ancestor?(node, %w(pre code))
22
+ html = emoji_image_filter(content)
23
+ next if html == content
24
+ node.replace(html)
25
+ end
26
+ doc
27
+ end
28
+
29
+ # Implementation of validate hook.
30
+ # Errors should raise exceptions or use an existing validator.
31
+ def validate
32
+ needs :asset_root
22
33
  end
23
- doc
24
- end
25
-
26
- # Implementation of validate hook.
27
- # Errors should raise exceptions or use an existing validator.
28
- def validate
29
- needs :asset_root
30
- end
31
34
 
32
- # Replace :emoji: with corresponding images.
33
- #
34
- # text - String text to replace :emoji: in.
35
- #
36
- # Returns a String with :emoji: replaced with images.
37
- def emoji_image_filter(text)
38
- return text unless text.include?(':')
35
+ # Replace :emoji: with corresponding images.
36
+ #
37
+ # text - String text to replace :emoji: in.
38
+ #
39
+ # Returns a String with :emoji: replaced with images.
40
+ def emoji_image_filter(text)
41
+ return text unless text.include?(':')
39
42
 
40
- text.gsub(emoji_pattern) do |match|
41
- name = $1
42
- "<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{emoji_url(name)}' height='20' width='20' align='absmiddle' />"
43
+ text.gsub(emoji_pattern) do |match|
44
+ name = $1
45
+ "<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{emoji_url(name)}' height='20' width='20' align='absmiddle' />"
46
+ end
43
47
  end
44
- end
45
48
 
46
- # The base url to link emoji sprites
47
- #
48
- # Raises ArgumentError if context option has not been provided.
49
- # Returns the context's asset_root.
50
- def asset_root
51
- context[:asset_root]
52
- end
53
-
54
- # The url path to link emoji sprites
55
- #
56
- # :file_name can be used in the asset_path as a placeholder for the sprite file name. If no asset_path is set in the context "emoji/:file_name" is used.
57
- # Returns the context's asset_path or the default path if no context asset_path is given.
58
- def asset_path(name)
59
- if context[:asset_path]
60
- context[:asset_path].gsub(":file_name", emoji_filename(name))
61
- else
62
- File.join("emoji", emoji_filename(name))
49
+ # The base url to link emoji sprites
50
+ #
51
+ # Raises ArgumentError if context option has not been provided.
52
+ # Returns the context's asset_root.
53
+ def asset_root
54
+ context[:asset_root]
63
55
  end
64
- end
65
56
 
66
- private
57
+ private
67
58
 
68
- def emoji_url(name)
69
- File.join(asset_root, asset_path(name))
70
- end
59
+ def emoji_url(name)
60
+ File.join(asset_root, 'emoji', emoji_filename(name))
61
+ end
71
62
 
72
- # Build a regexp that matches all valid :emoji: names.
73
- def self.emoji_pattern
74
- @emoji_pattern ||= /:(#{emoji_names.map { |name| Regexp.escape(name) }.join('|')}):/
75
- end
63
+ # Build a regexp that matches all valid :emoji: names.
64
+ def self.emoji_pattern
65
+ @emoji_pattern ||= /:(#{emoji_names.map { |name| Regexp.escape(name) }.join('|')}):/
66
+ end
76
67
 
77
- def emoji_pattern
78
- self.class.emoji_pattern
79
- end
68
+ def emoji_pattern
69
+ self.class.emoji_pattern
70
+ end
80
71
 
81
- def self.emoji_names
82
- Emoji.names
83
- end
72
+ def self.emoji_names
73
+ Emoji.names
74
+ end
84
75
 
85
- def emoji_filename(name)
86
- "#{::CGI.escape(name)}.png"
76
+ def emoji_filename(name)
77
+ "#{::CGI.escape(name)}.png"
78
+ end
87
79
  end
88
80
  end
89
81
  end
@@ -1,7 +1,7 @@
1
1
  module Html
2
2
  module Pipeline
3
3
  module Gitlab
4
- VERSION = "0.0.1"
4
+ VERSION = '0.0.2'
5
5
  end
6
6
  end
7
7
  end
@@ -1,9 +1,2 @@
1
- require "html/pipeline/gitlab/version"
2
-
3
- module Html
4
- module Pipeline
5
- module Gitlab
6
- # Your code goes here...
7
- end
8
- end
9
- end
1
+ require 'html/pipeline/gitlab/version'
2
+ require 'html/pipeline/gitlab/gitlab_emoji_filter'
@@ -1,26 +1,26 @@
1
1
  require 'test_helper'
2
- require 'html/pipeline/gitlab/gitlab_emoji_filter'
2
+ require 'html/pipeline/gitlab'
3
3
 
4
4
  class HTML::Pipeline::GitLabEmojiFilterTest < Minitest::Test
5
- GitLabEmojiFilter = HTML::Pipeline::GitLabEmojiFilter
5
+ GitLabEmojiFilter = HTML::Pipeline::GitLab::GitLabEmojiFilter
6
6
 
7
7
  def test_emojify
8
- filter = GitLabEmojiFilter.new("<p>:heart:</p>", {:asset_root => 'https://foo.com'})
8
+ filter = GitLabEmojiFilter.new('<p>:heart:</p>', {asset_root: 'https://foo.com'})
9
9
  doc = filter.call
10
- assert_match "https://foo.com/emoji/heart.png", doc.search('img').attr('src').value
10
+ assert_match 'https://foo.com/emoji/heart.png', doc.search('img').attr('src').value
11
11
  end
12
12
 
13
13
  def test_unsupported_emoji
14
- block = "<p>:sheep:</p>"
15
- filter = GitLabEmojiFilter.new(block, {:asset_root => 'https://foo.com'})
14
+ block = '<p>:sheep:</p>'
15
+ filter = GitLabEmojiFilter.new(block, {asset_root: 'https://foo.com'})
16
16
  doc = filter.call
17
17
  assert_match block, doc.to_html
18
18
  end
19
19
 
20
20
  def test_uri_encoding
21
- filter = GitLabEmojiFilter.new("<p>:+1:</p>", {:asset_root => 'https://foo.com'})
21
+ filter = GitLabEmojiFilter.new('<p>:+1:</p>', {asset_root: 'https://foo.com'})
22
22
  doc = filter.call
23
- assert_match "https://foo.com/emoji/%2B1.png", doc.search('img').attr('src').value
23
+ assert_match 'https://foo.com/emoji/%2B1.png', doc.search('img').attr('src').value
24
24
  end
25
25
 
26
26
  def test_required_context_validation
@@ -29,10 +29,4 @@ class HTML::Pipeline::GitLabEmojiFilterTest < Minitest::Test
29
29
  }
30
30
  assert_match /:asset_root/, exception.message
31
31
  end
32
-
33
- def test_custom_asset_path
34
- filter = GitLabEmojiFilter.new("<p>:+1:</p>", {:asset_path => ':file_name', :asset_root => 'https://foo.com'})
35
- doc = filter.call
36
- assert_match "https://foo.com/%2B1.png", doc.search('img').attr('src').value
37
- end
38
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline-gitlab
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
  - Robert Schilling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler