jekyll-commit-mentions 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/commit_mention_filter.rb +16 -17
- data/lib/jekyll-commit-mentions.rb +20 -15
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ffeea732e0618fa4f7e37aa4ce263516300bf0
|
4
|
+
data.tar.gz: aa3e8bc25e70d06ceebbacb78a823a7c89dc1b46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 302339310c9fd3c999af178b3d049ba874ea77b13ba273a38a468eee9654f5e497a8b2fc435768868dcc3927bfbe30394bb9461d84af7c8138807fc0f16fb778
|
7
|
+
data.tar.gz: 62473ed2b2f6fe1f4f8fc7bd49ea8f699c5ebfd242c3e1890a58a68bebd97c708bf2f0e827f27f18240a604f51d0404fc56f683557fdf360c57f6a221ed9367a
|
@@ -2,16 +2,16 @@ require 'set'
|
|
2
2
|
|
3
3
|
module HTML
|
4
4
|
class Pipeline
|
5
|
-
# HTML filter that replaces
|
5
|
+
# HTML filter that replaces mention mentions with links to Github commit. Mentions within <pre>,
|
6
6
|
# <code>, <style> and <a> elements are ignored.
|
7
7
|
#
|
8
8
|
# Context options:
|
9
|
-
# :base_url - Used to construct links to
|
9
|
+
# :base_url - Used to construct links to commit page for each mention.
|
10
10
|
# :commitid_pattern - Used to provide a custom regular expression to
|
11
|
-
# identify
|
11
|
+
# identify commit ids
|
12
12
|
#
|
13
13
|
class CommitMentionFilter < Filter
|
14
|
-
# Public: Find
|
14
|
+
# Public: Find commit mention in text. See
|
15
15
|
# CommitMentionFilter#mention_link_filter.
|
16
16
|
#
|
17
17
|
# CommitMentionFilter.mentioned_commits_in(text) do |match, commitid|
|
@@ -49,17 +49,17 @@ module HTML
|
|
49
49
|
|
50
50
|
# Default pattern used to extract commitid from text. The value can be
|
51
51
|
# overriden by providing the commitid_pattern variable in the context.
|
52
|
-
CommitidPattern = /[0-9a-f]{
|
52
|
+
CommitidPattern = /[0-9a-f]{40}/
|
53
53
|
|
54
54
|
# Don't look for mentions in text nodes that are children of these elements
|
55
|
-
IGNORE_PARENTS = %w(pre code a style).to_set
|
55
|
+
IGNORE_PARENTS = %w(pre code a style script).to_set
|
56
56
|
|
57
57
|
def call
|
58
58
|
result[:mentioned_commitids] ||= []
|
59
59
|
|
60
60
|
doc.search('text()').each do |node|
|
61
61
|
content = node.to_html
|
62
|
-
next if !content.match(
|
62
|
+
next if !content.match(commitid_pattern)
|
63
63
|
next if has_ancestor?(node, IGNORE_PARENTS)
|
64
64
|
html = mention_link_filter(content, base_url, commitid_pattern)
|
65
65
|
next if html == content
|
@@ -72,33 +72,32 @@ module HTML
|
|
72
72
|
context[:commitid_pattern] || CommitidPattern
|
73
73
|
end
|
74
74
|
|
75
|
-
# Replace
|
76
|
-
#
|
75
|
+
# Replace commit mentions in text with links to the mentioned
|
76
|
+
# commit's page.
|
77
77
|
#
|
78
|
-
# text - String text to replace
|
79
|
-
# base_url - The base URL used to construct
|
78
|
+
# text - String text to replace mention commitids in.
|
79
|
+
# base_url - The base URL used to construct commit page URLs.
|
80
80
|
# commitid_pattern - Regular expression used to identify commitid in
|
81
81
|
# text
|
82
82
|
#
|
83
83
|
# Returns a string with #commitid replaced with links. All links have a
|
84
|
-
# '
|
84
|
+
# 'commit-mention' class name attached for styling.
|
85
85
|
def mention_link_filter(text, base_url='/', commitid_pattern)
|
86
86
|
self.class.mentioned_commits_in(text, commitid_pattern) do |match, commitid|
|
87
|
-
link =
|
87
|
+
link = link_to_mentioned_commit(commitid)
|
88
88
|
link ? match.sub("#{commitid}", link) : match
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
92
|
+
def link_to_mentioned_commit(commitid)
|
93
93
|
result[:mentioned_commitids] |= [commitid]
|
94
94
|
|
95
95
|
url = base_url.dup
|
96
96
|
url << "/" unless url =~ /[\/~]\z/
|
97
|
+
url << commitid
|
97
98
|
shortid = commitid[-7..-1] || commitid
|
98
99
|
|
99
|
-
"<a href='#{url
|
100
|
-
"#{shortid}" +
|
101
|
-
"</a>"
|
100
|
+
"<a href='#{url}' class='commit-mention'>#{shortid}</a>"
|
102
101
|
end
|
103
102
|
end
|
104
103
|
end
|
@@ -3,11 +3,12 @@ require 'html/pipeline'
|
|
3
3
|
require 'commit_mention_filter'
|
4
4
|
|
5
5
|
module Jekyll
|
6
|
-
class
|
6
|
+
class CommitMentions < Jekyll::Generator
|
7
7
|
safe true
|
8
|
+
attr_reader :base_url
|
8
9
|
|
9
10
|
def initialize(config = Hash.new)
|
10
|
-
|
11
|
+
validate_config!(config)
|
11
12
|
end
|
12
13
|
|
13
14
|
def generate(site)
|
@@ -17,30 +18,34 @@ module Jekyll
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def mentionify(page)
|
20
|
-
|
21
|
-
page.content = @filter.
|
21
|
+
@filter = HTML::Pipeline::CommitMentionFilter.new(page.content, {:base_url => base_url})
|
22
|
+
page.content = @filter.call.to_s.
|
23
|
+
gsub(">", ">").
|
24
|
+
gsub("<", "<").
|
25
|
+
gsub("%7B", "{").
|
26
|
+
gsub("%20", " ").
|
27
|
+
gsub("%7D", "}")
|
22
28
|
end
|
23
29
|
|
24
30
|
def html_page?(page)
|
25
31
|
page.html? || page.url.end_with?('/')
|
26
32
|
end
|
27
33
|
|
28
|
-
|
34
|
+
private
|
35
|
+
def validate_config!(configs)
|
36
|
+
configs = configs['jekyll-commit-mentions']
|
37
|
+
base_url = nil
|
29
38
|
case configs
|
30
|
-
when nil, NilClass
|
31
|
-
raise ArgumentError.new("Your jekyll-issue-mentions config has to configured.")
|
32
39
|
when String
|
33
|
-
configs
|
40
|
+
base_url = configs
|
34
41
|
when Hash
|
35
42
|
base_url = configs['base_url']
|
36
|
-
if base_url.nil?
|
37
|
-
raise ArgumentError.new("Your jekyll-issue-mentions is missing base_url configuration.")
|
38
|
-
else
|
39
|
-
base_url
|
40
|
-
end
|
41
|
-
else
|
42
|
-
raise ArgumentError.new("Your jekyll-issue-mentions config has to either be a string or a hash! It's a #{configs.class} right now.")
|
43
43
|
end
|
44
|
+
error_prefix = "jekyll-commit-mentions"
|
45
|
+
raise ArgumentError.new("#{error_prefix}.base_url is missing/empty") if (base_url.nil? || base_url.empty?)
|
46
|
+
|
47
|
+
@base_url = base_url
|
44
48
|
end
|
49
|
+
|
45
50
|
end
|
46
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-commit-mentions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- harish shetty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -38,6 +38,40 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
- - "<="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.6.5
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.4'
|
58
|
+
- - "<="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.6.5
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: github-markdown
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
41
75
|
- !ruby/object:Gem::Dependency
|
42
76
|
name: rake
|
43
77
|
requirement: !ruby/object:Gem::Requirement
|