jekyll-commit-mentions 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/commit_mention_filter.rb +105 -0
- data/lib/jekyll-commit-mentions.rb +46 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3a0dc4eb6f161ded768904fcc66efa9de0c1fbe
|
4
|
+
data.tar.gz: 16cc8173db3ab806c79ed080ce293d17718189bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3b924783e47e064af1409ca22932e7987ea2c018e24b3757b48d4d21e6acf731d3094836cc1c9d98c585f8ced0b7c0abebb741cc8a2df02a711f0a50837f6b3
|
7
|
+
data.tar.gz: 7db3165bae90bdb3b82b7c6194836db498fb3f0a9eebe7cf85138a822abcc81bd31515de9ea28d21b0d82e5cb7c234fafb9cafa6cb7e9cf6edeeb516c32266f0
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module HTML
|
4
|
+
class Pipeline
|
5
|
+
# HTML filter that replaces #mention mentions with links to Github issue. Mentions within <pre>,
|
6
|
+
# <code>, <style> and <a> elements are ignored.
|
7
|
+
#
|
8
|
+
# Context options:
|
9
|
+
# :base_url - Used to construct links to issue page for each mention.
|
10
|
+
# :commitid_pattern - Used to provide a custom regular expression to
|
11
|
+
# identify issue ids
|
12
|
+
#
|
13
|
+
class CommitMentionFilter < Filter
|
14
|
+
# Public: Find issue #mention in text. See
|
15
|
+
# CommitMentionFilter#mention_link_filter.
|
16
|
+
#
|
17
|
+
# CommitMentionFilter.mentioned_commits_in(text) do |match, commitid|
|
18
|
+
# "<a href=...>#{commitid}</a>"
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# text - String text to search.
|
22
|
+
#
|
23
|
+
# Yields the String match, the String commitid. The yield's return replaces the match in
|
24
|
+
# the original text.
|
25
|
+
#
|
26
|
+
# Returns a String replaced with the return of the block.
|
27
|
+
def self.mentioned_commits_in(text, commitid_pattern=CommitidPattern)
|
28
|
+
text.gsub MentionPatterns[commitid_pattern] do |match|
|
29
|
+
commitid = $1
|
30
|
+
yield match, commitid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Hash that contains all of the mention patterns used by the pipeline
|
36
|
+
MentionPatterns = Hash.new do |hash, key|
|
37
|
+
hash[key] = /
|
38
|
+
(?:^|\W) # beginning of string or non-word char
|
39
|
+
((?>#{key})) # commitid
|
40
|
+
(?!\/) # without a trailing slash
|
41
|
+
(?=
|
42
|
+
\.+[ \t\W]| # dots followed by space or non-word character
|
43
|
+
\.+$| # dots at end of line
|
44
|
+
[^0-9a-zA-Z_.]| # non-word character except dot
|
45
|
+
$ # end of line
|
46
|
+
)
|
47
|
+
/ix
|
48
|
+
end
|
49
|
+
|
50
|
+
# Default pattern used to extract commitid from text. The value can be
|
51
|
+
# overriden by providing the commitid_pattern variable in the context.
|
52
|
+
CommitidPattern = /[0-9a-f]{7,40}/
|
53
|
+
|
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
|
56
|
+
|
57
|
+
def call
|
58
|
+
result[:mentioned_commitids] ||= []
|
59
|
+
|
60
|
+
doc.search('text()').each do |node|
|
61
|
+
content = node.to_html
|
62
|
+
next if !content.match(CommitidPattern)
|
63
|
+
next if has_ancestor?(node, IGNORE_PARENTS)
|
64
|
+
html = mention_link_filter(content, base_url, commitid_pattern)
|
65
|
+
next if html == content
|
66
|
+
node.replace(html)
|
67
|
+
end
|
68
|
+
doc
|
69
|
+
end
|
70
|
+
|
71
|
+
def commitid_pattern
|
72
|
+
context[:commitid_pattern] || CommitidPattern
|
73
|
+
end
|
74
|
+
|
75
|
+
# Replace issue #mentions in text with links to the mentioned
|
76
|
+
# issue's page.
|
77
|
+
#
|
78
|
+
# text - String text to replace #mention commitids in.
|
79
|
+
# base_url - The base URL used to construct issue page URLs.
|
80
|
+
# commitid_pattern - Regular expression used to identify commitid in
|
81
|
+
# text
|
82
|
+
#
|
83
|
+
# Returns a string with #commitid replaced with links. All links have a
|
84
|
+
# 'issue-mention' class name attached for styling.
|
85
|
+
def mention_link_filter(text, base_url='/', commitid_pattern)
|
86
|
+
self.class.mentioned_commits_in(text, commitid_pattern) do |match, commitid|
|
87
|
+
link = link_to_mentioned_issue(commitid)
|
88
|
+
link ? match.sub("#{commitid}", link) : match
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def link_to_mentioned_issue(commitid)
|
93
|
+
result[:mentioned_commitids] |= [commitid]
|
94
|
+
|
95
|
+
url = base_url.dup
|
96
|
+
url << "/" unless url =~ /[\/~]\z/
|
97
|
+
shortid = commitid[-7..-1] || commitid
|
98
|
+
|
99
|
+
"<a href='#{url << commitid}' class='commit-mention'>" +
|
100
|
+
"#{shortid}" +
|
101
|
+
"</a>"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require 'html/pipeline'
|
3
|
+
require 'commit_mention_filter'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class IssueMentions < Jekyll::Generator
|
7
|
+
safe true
|
8
|
+
|
9
|
+
def initialize(config = Hash.new)
|
10
|
+
@filter = HTML::Pipeline::CommitMentionFilter.new(nil, {:base_url => base_url(config['jekyll-issue-mentions']) })
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate(site)
|
14
|
+
site.pages.each { |page| mentionify page if html_page?(page) }
|
15
|
+
site.posts.each { |post| mentionify post }
|
16
|
+
site.docs_to_write.each { |doc| mentionify doc }
|
17
|
+
end
|
18
|
+
|
19
|
+
def mentionify(page)
|
20
|
+
return if !page.content.match(@filter.commitid_pattern)
|
21
|
+
page.content = @filter.mention_link_filter(page.content, @filter.base_url, @filter.commitid_pattern)
|
22
|
+
end
|
23
|
+
|
24
|
+
def html_page?(page)
|
25
|
+
page.html? || page.url.end_with?('/')
|
26
|
+
end
|
27
|
+
|
28
|
+
def base_url(configs)
|
29
|
+
case configs
|
30
|
+
when nil, NilClass
|
31
|
+
raise ArgumentError.new("Your jekyll-issue-mentions config has to configured.")
|
32
|
+
when String
|
33
|
+
configs.to_s
|
34
|
+
when Hash
|
35
|
+
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
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-commit-mentions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- harish shetty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: html-pipeline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.9.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email: support@workato.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- lib/commit_mention_filter.rb
|
104
|
+
- lib/jekyll-commit-mentions.rb
|
105
|
+
homepage: https://github.com/workato/jekyll-commit-mentions
|
106
|
+
licenses:
|
107
|
+
- mit
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.6
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Github commit sha mention support for your jekyll site
|
129
|
+
test_files: []
|