html-pipeline-linkify_github 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5638ffbca9252a4443a1f4202d4338fe33249137
4
+ data.tar.gz: 46b88271fba26138bbaa86a17bad8062e3d2e818
5
+ SHA512:
6
+ metadata.gz: 9670294c39de66cbe696aacc67d93d40b714d30a5cb58cca4caf0edaecf5c7c449ad5f9e4e731e914783e3327ad148888f5a1a71a8ec70a5bf0599fbe8b95fec
7
+ data.tar.gz: ff3001f09b0f2390ff676d0453fb08e9eaa5eb14dacd14695e9357391ce27bcdf54303cd455b02443279a2d42d433f301fcfe5af389a75655e643fe573552810
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ bundler_args: --retry=3 --jobs=3
2
+ cache: bundler
3
+ language: ruby
4
+ sudo: false
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.7
8
+ - 2.2.3
9
+ - ruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ fast_finish: true
14
+ notifications:
15
+ slack:
16
+ secure: wZ1UPEcH/Zf/wSPvpR1q76vpUQvAEGuwR5500ML8C+shW7PedvuSZaiZYAOZxhyD17RXzXYroON0ArEk3NUcKD8supPzYjUWzCeWDIFaYxEb7dOm7tpRBf4GuQ/oy8HGsBi947ZTX3WytGWZU0q0aRu2EirPcoY05vzley/hYTI=
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # CHANGELOG
2
+
3
+ ## Unreleased
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in twemoji.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "rake"
8
+ gem "bundler"
9
+ gem "pry"
10
+ end
11
+
12
+ group :test do
13
+ gem "minitest", ">= 5.8"
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Juanito Fatas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # HTML::Pipeline::LinkifyGitHub [![Build Status](https://travis-ci.org/jollygoodcode/html-pipeline-linkify_github.svg)](https://travis-ci.org/jollygoodcode/html-pipeline-linkify_github)
2
+
3
+ `HTML::Pipeline::LinkifyGitHub` provides a [HTML::Pipeline](https://github.com/jch/html-pipeline)
4
+ filter to autolink GitHub urls.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "html-pipeline-linkify_github"
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install html-pipeline-linkify_github
21
+
22
+ ## Usage
23
+
24
+ **Use `HTML::Pipeline::LinkifyGitHubFilter` filter before your markdown filter.**
25
+
26
+ ```ruby
27
+ require "html/pipeline"
28
+ require "html/pipeline/linkify_github"
29
+
30
+ pipeline = HTML::Pipeline.new [
31
+ HTML::Pipeline::LinkifyGitHubFilter,
32
+ HTML::Pipeline::MarkdownFilter
33
+ ]
34
+
35
+ result = pipeline.call <<-CODE
36
+ https://github.com/rails/rails/pull/21862
37
+ https://github.com/rails/rails/issues/21843
38
+ https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864
39
+ CODE
40
+
41
+ puts result[:output]
42
+ ```
43
+
44
+ prints:
45
+
46
+ ```markdown
47
+ [rails/rails#21862](https://github.com/rails/rails/pull/21862)
48
+ [rails/rails#21843](https://github.com/rails/rails/issues/21843)
49
+ [rails/rails@`67597e1`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)
50
+ ```
51
+
52
+ ## Contributing
53
+
54
+ 1. [Fork it](https://github.com/jollygoodcode/html-pipeline-linkify_github/fork)
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am "Add some feature"`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
59
+
60
+ ## Notes
61
+
62
+ This RubyGem requires Ruby 2.0+ because [support for 1.9.3 is officially end](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/).
63
+
64
+ ## Credits
65
+
66
+ A huge THANK YOU to all our [contributors](https://github.com/jollygoodcode/twemoji/graphs/contributors)! :heart:
67
+
68
+ This project is maintained by [Jolly Good Code](http://www.jollygoodcode.com).
69
+
70
+ ## License
71
+
72
+ MIT License. See [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "html/pipeline/linkify_github/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "html-pipeline-linkify_github"
8
+ spec.version = HTML::Pipeline::LinkifyGitHub::VERSION
9
+ spec.authors = ["Juanito Fatas"]
10
+ spec.email = ["katehuang0320@gmail.com"]
11
+ spec.summary = %q{A HTML::Pipeline filter to autolink GitHub urls.}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/juanitofatas/html-pipeline-linkify_github"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "html-pipeline", ">= 1.11"
20
+
21
+ spec.required_ruby_version = "~> 2.0"
22
+ end
@@ -0,0 +1,86 @@
1
+ require "html/pipeline"
2
+
3
+ module HTML
4
+ class Pipeline
5
+ # Filter that converts GitHub's url into friendly markdown.
6
+ #
7
+ # For example:
8
+ #
9
+ # https://github.com/rails/rails/pull/21862
10
+ # https://github.com/rails/rails/issues/21843
11
+ # https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864
12
+ #
13
+ # =>
14
+ #
15
+ # [rails/rails#21862](https://github.com/rails/rails/pull/21862)
16
+ # [rails/rails#21843](https://github.com/rails/rails/issues/21843)
17
+ # [rails/rails@`67597e`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)
18
+ #
19
+ # This filter does not write any additional information to the context hash.
20
+ class LinkifyGitHubFilter < TextFilter
21
+ GITHUB_URL = "github.com".freeze
22
+ PULL = "/pull/".freeze
23
+ ISSUES = "/issues/".freeze
24
+ COMMIT = "/commit/".freeze
25
+
26
+ PULL_REQUEST_REGEXP = %r{https?://(www.)?github.com/(?<owner>.+)/(?<repo>.+)/pull/(?<number>\d+)/?}.freeze
27
+ ISSUES_REGEXP = %r{https?://(www.)?github.com/(?<owner>.+)/(?<repo>.+)/issues/(?<number>\d+)/?}.freeze
28
+ COMMIT_REGEXP = %r{https?://(www.)?github.com/(?<owner>.+)/(?<repo>.+)/commit/(?<number>\w+)/?}.freeze
29
+
30
+ # Convert GitHub urls into friendly markdown.
31
+ def call
32
+ return @text unless @text.include?(GITHUB_URL)
33
+
34
+ replace_pull_request_links if has_pull_request_link?
35
+ replace_issue_links if has_issue_link?
36
+ replace_commit_links if has_commit_link?
37
+
38
+ @text
39
+ end
40
+
41
+ private
42
+
43
+ def has_pull_request_link?
44
+ @text.include?(PULL)
45
+ end
46
+
47
+ def has_issue_link?
48
+ @text.include?(ISSUES)
49
+ end
50
+
51
+ def has_commit_link?
52
+ @text.include?(COMMIT)
53
+ end
54
+
55
+ def replace_pull_request_links
56
+ @text.gsub!(PULL_REQUEST_REGEXP) do
57
+ pull_request_markdown($1, $2, $3) if [$1, $2, $3].all?(&:present?)
58
+ end
59
+ end
60
+
61
+ def replace_issue_links
62
+ @text.gsub!(ISSUES_REGEXP) do
63
+ issue_markdown($1, $2, $3) if [$1, $2, $3].all?(&:present?)
64
+ end
65
+ end
66
+
67
+ def replace_commit_links
68
+ @text.gsub!(COMMIT_REGEXP) do
69
+ commit_markdown($1, $2, $3) if [$1, $2, $3].all?(&:present?)
70
+ end
71
+ end
72
+
73
+ def pull_request_markdown(repo, owner, number)
74
+ "[#{repo}/#{owner}##{number}](https://github.com/#{repo}/#{owner}/pull/#{number})"
75
+ end
76
+
77
+ def issue_markdown(repo, owner, number)
78
+ "[#{repo}/#{owner}##{number}](https://github.com/#{repo}/#{owner}/issues/#{number})"
79
+ end
80
+
81
+ def commit_markdown(repo, owner, number)
82
+ "[#{repo}/#{owner}@`#{number[0..6]}`](https://github.com/#{repo}/#{owner}/commit/#{number})"
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,7 @@
1
+ module HTML
2
+ class Pipeline
3
+ module LinkifyGitHub
4
+ VERSION = "1.0.0".freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,133 @@
1
+ require "test_helper"
2
+
3
+ class HTML::Pipeline::LinkifyGitHubTest < Minitest::Test
4
+ LinkifyGitHubFilter = HTML::Pipeline::LinkifyGitHubFilter
5
+
6
+ def filter(text)
7
+ LinkifyGitHubFilter.to_html(text)
8
+ end
9
+
10
+ def test_that_it_has_a_version_number
11
+ assert HTML::Pipeline::LinkifyGitHub::VERSION
12
+ end
13
+
14
+ def test_that_normal_url_will_not_linkify
15
+ text = "https://www.deppbot.com"
16
+
17
+ assert_equal text, filter(text)
18
+ end
19
+
20
+ # == Pull Request
21
+
22
+ def test_that_linkify_pull_request_url
23
+ text = "https://github.com/rails/rails/pull/21862"
24
+
25
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/pull/21862)", filter(text)
26
+ end
27
+
28
+ def test_that_linkify_pull_request_url_with_end_tilde
29
+ text = "https://github.com/rails/rails/pull/21862/"
30
+
31
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/pull/21862)", filter(text)
32
+ end
33
+
34
+ def test_that_linkify_pull_request_url_with_www
35
+ text = "https://www.github.com/rails/rails/pull/21862"
36
+
37
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/pull/21862)", filter(text)
38
+ end
39
+
40
+ def test_that_linkify_pull_request_url_http
41
+ text = "http://github.com/rails/rails/pull/21862"
42
+
43
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/pull/21862)", filter(text)
44
+ end
45
+
46
+ def test_that_linkify_pull_request_url_http_www
47
+ text = "http://www.github.com/rails/rails/pull/21862"
48
+
49
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/pull/21862)", filter(text)
50
+ end
51
+
52
+ def test_that_linkify_with_invalid_pull_request_url
53
+ text = "https://github.com/rails/rails/pull/"
54
+
55
+ assert_equal text, filter(text)
56
+ end
57
+
58
+ # == Issue
59
+
60
+ def test_that_linkify_issue_url
61
+ text = "https://github.com/rails/rails/issues/21862"
62
+
63
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/issues/21862)", filter(text)
64
+ end
65
+
66
+ def test_that_linkify_issue_url_with_end_tilde
67
+ text = "https://github.com/rails/rails/issues/21862/"
68
+
69
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/issues/21862)", filter(text)
70
+ end
71
+
72
+ def test_that_linkify_issue_url_with_www
73
+ text = "https://www.github.com/rails/rails/issues/21862"
74
+
75
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/issues/21862)", filter(text)
76
+ end
77
+
78
+ def test_that_linkify_issue_url_http
79
+ text = "http://github.com/rails/rails/issues/21862"
80
+
81
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/issues/21862)", filter(text)
82
+ end
83
+
84
+ def test_that_linkify_issue_url_http_www
85
+ text = "http://www.github.com/rails/rails/issues/21862"
86
+
87
+ assert_equal "[rails/rails#21862](https://github.com/rails/rails/issues/21862)", filter(text)
88
+ end
89
+
90
+ def test_that_linkify_with_invalid_issue_url
91
+ text = "https://github.com/rails/rails/issues/"
92
+
93
+ assert_equal text, filter(text)
94
+ end
95
+
96
+ # == Commit
97
+
98
+ def test_that_linkify_commit_url
99
+ text = "https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864"
100
+
101
+ assert_equal "[rails/rails@`67597e1`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)", filter(text)
102
+ end
103
+
104
+ def test_that_linkify_commit_url_with_end_tilde
105
+ text = "https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864/"
106
+
107
+ assert_equal "[rails/rails@`67597e1`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)", filter(text)
108
+ end
109
+
110
+ def test_that_linkify_commit_url_with_www
111
+ text = "https://www.github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864"
112
+
113
+ assert_equal "[rails/rails@`67597e1`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)", filter(text)
114
+ end
115
+
116
+ def test_that_linkify_commit_url_with_http
117
+ text = "http://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864"
118
+
119
+ assert_equal "[rails/rails@`67597e1`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)", filter(text)
120
+ end
121
+
122
+ def test_that_linkify_commit_url_with_http_www
123
+ text = "http://www.github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864"
124
+
125
+ assert_equal "[rails/rails@`67597e1`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)", filter(text)
126
+ end
127
+
128
+ def test_that_linkify_with_invalid_commit_url
129
+ text = "http://www.github.com/rails/rails/commit/"
130
+
131
+ assert_equal text, filter(text)
132
+ end
133
+ end
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+ require "minitest/autorun"
3
+ require "html/pipeline/linkify_github"
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html-pipeline-linkify_github
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Juanito Fatas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: html-pipeline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ description: A HTML::Pipeline filter to autolink GitHub urls.
28
+ email:
29
+ - katehuang0320@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".travis.yml"
36
+ - CHANGELOG.md
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - html-pipeline-linkify_github.gemspec
42
+ - lib/html/pipeline/linkify_github.rb
43
+ - lib/html/pipeline/linkify_github/version.rb
44
+ - test/linkify_github_test.rb
45
+ - test/test_helper.rb
46
+ homepage: https://github.com/juanitofatas/html-pipeline-linkify_github
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '2.0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.4.8
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: A HTML::Pipeline filter to autolink GitHub urls.
70
+ test_files: []
71
+ has_rdoc: