html-pipeline-gitlab 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/html-pipeline-gitlab.gemspec +2 -0
- data/lib/html/pipeline/gitlab.rb +7 -5
- data/lib/html/pipeline/gitlab/gitlab_emoji_filter.rb +6 -16
- data/lib/html/pipeline/gitlab/version.rb +1 -1
- data/test/html/pipeline/gitlab_gemoji_filter_test.rb +9 -12
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd6c8995b16ac5d93311facb210ebc6fa9ed74d4
|
4
|
+
data.tar.gz: 147ef4e54054d3b43c8abb925f67d5b6a4a7daa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67df9b88434db7d8bd48485a75d9c4463d0b47bc7d53d4fc0542bba8fb99b98ad89443cc7d18b67090ae767a0d0daee8f197f25088acfcc159e596a6c5144a61
|
7
|
+
data.tar.gz: a06130d7bacda0f227e47f6cac432798ef7ebb7f2470223e929f848a46e48b5d73c26d9d5f0483a49e0279865a042fca146f13c9cecb1de830e3c171afd0488d
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
This gem implements various filters for [html-pipeline](https://github.com/jch/html-pipeline)
|
4
4
|
used by [GitLab](https://about.gitlab.com).
|
5
5
|
|
6
|
-
[![
|
6
|
+
[![build status](https://gitlab-ce.githost.io/projects/5/status.png?ref=master)](https://gitlab-ce.githost.io/projects/5?ref=master)
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -20,8 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'pry', '~> 0.9'
|
23
24
|
|
24
25
|
spec.add_runtime_dependency 'html-pipeline', '~> 1.11.0'
|
25
26
|
spec.add_runtime_dependency 'gitlab_emoji', '~> 0.0.1'
|
26
27
|
spec.add_runtime_dependency 'sanitize', '~> 2.1'
|
28
|
+
spec.add_runtime_dependency 'actionpack', '~> 4'
|
27
29
|
end
|
data/lib/html/pipeline/gitlab.rb
CHANGED
@@ -10,11 +10,13 @@ module HTML
|
|
10
10
|
# Custom filter implementations
|
11
11
|
autoload :GitlabEmojiFilter, 'html/pipeline/gitlab/gitlab_emoji_filter'
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def initialize(filters)
|
14
|
+
@filters = filters.flatten.freeze
|
15
|
+
end
|
16
|
+
|
17
|
+
def pipeline
|
18
|
+
HTML::Pipeline.new @filters
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
require 'gitlab_emoji'
|
3
3
|
require 'html/pipeline/filter'
|
4
|
+
require 'action_controller'
|
4
5
|
|
5
6
|
module HTML
|
6
7
|
class Pipeline
|
7
8
|
class Gitlab
|
8
9
|
# 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.
|
13
|
-
# :file_name can be used as a placeholder for the sprite file name.
|
14
|
-
# If no asset_path is set "emoji/:file_name" is used.
|
15
10
|
class GitlabEmojiFilter < Filter
|
16
11
|
def call
|
17
12
|
search_text_nodes(doc).each do |node|
|
@@ -28,7 +23,6 @@ module HTML
|
|
28
23
|
# Implementation of validate hook.
|
29
24
|
# Errors should raise exceptions or use an existing validator.
|
30
25
|
def validate
|
31
|
-
needs :asset_root
|
32
26
|
end
|
33
27
|
|
34
28
|
# Replace :emoji: with corresponding images.
|
@@ -45,18 +39,14 @@ module HTML
|
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
48
|
-
# The base url to link emoji sprites
|
49
|
-
#
|
50
|
-
# Raises ArgumentError if context option has not been provided.
|
51
|
-
# Returns the context's asset_root.
|
52
|
-
def asset_root
|
53
|
-
context[:asset_root]
|
54
|
-
end
|
55
|
-
|
56
42
|
private
|
57
43
|
|
58
44
|
def emoji_url(name)
|
59
|
-
|
45
|
+
url_to_image("emoji/#{emoji_filename(name)}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def url_to_image(image)
|
49
|
+
ActionController::Base.helpers.url_to_image(image)
|
60
50
|
end
|
61
51
|
|
62
52
|
# Build a regexp that matches all valid :emoji: names.
|
@@ -4,29 +4,26 @@ require 'html/pipeline/gitlab'
|
|
4
4
|
class HTML::Pipeline::GitlabEmojiFilterTest < Minitest::Test
|
5
5
|
GitlabEmojiFilter = HTML::Pipeline::Gitlab::GitlabEmojiFilter
|
6
6
|
|
7
|
+
def setup
|
8
|
+
ActionController::Base.asset_host = 'https://foo.com'
|
9
|
+
end
|
10
|
+
|
7
11
|
def test_emojify
|
8
|
-
filter = GitlabEmojiFilter.new('<p>:heart:</p>'
|
12
|
+
filter = GitlabEmojiFilter.new('<p>:heart:</p>')
|
9
13
|
doc = filter.call
|
10
|
-
assert_match 'https://foo.com/emoji/heart.png', doc.search('img').attr('src').value
|
14
|
+
assert_match 'https://foo.com/images/emoji/heart.png', doc.search('img').attr('src').value
|
11
15
|
end
|
12
16
|
|
13
17
|
def test_unsupported_emoji
|
14
18
|
block = '<p>:sheep:</p>'
|
15
|
-
filter = GitlabEmojiFilter.new(block
|
19
|
+
filter = GitlabEmojiFilter.new(block)
|
16
20
|
doc = filter.call
|
17
21
|
assert_match block, doc.to_html
|
18
22
|
end
|
19
23
|
|
20
24
|
def test_uri_encoding
|
21
|
-
filter = GitlabEmojiFilter.new('<p>:+1:</p>'
|
25
|
+
filter = GitlabEmojiFilter.new('<p>:+1:</p>')
|
22
26
|
doc = filter.call
|
23
|
-
assert_match 'https://foo.com/emoji
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_required_context_validation
|
27
|
-
exception = assert_raises(ArgumentError) {
|
28
|
-
GitlabEmojiFilter.call("", {})
|
29
|
-
}
|
30
|
-
assert_match /:asset_root/, exception.message
|
27
|
+
assert_match 'https://foo.com/images/emoji/+1.png', doc.search('img').attr('src').value
|
31
28
|
end
|
32
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline-gitlab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Schilling
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.9'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.9'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: html-pipeline
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,6 +95,20 @@ dependencies:
|
|
81
95
|
- - "~>"
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '2.1'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: actionpack
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '4'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '4'
|
84
112
|
description: Extension filters for html-pipeline used by GitLab
|
85
113
|
email:
|
86
114
|
- schilling.ro@gmail.com
|