jekyll_badge 0.1.2 → 0.1.3
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 +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/README.md +37 -4
- data/jekyll_badge.gemspec +2 -0
- data/lib/jekyll_badge/version.rb +1 -1
- data/lib/jekyll_badge.rb +27 -62
- data/lib/jekyll_badge_generate.rb +61 -0
- data/lib/jekyll_badge_private.rb +65 -0
- data/spec/badge/badge_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e81fc7035f9f6b553a5de7e442d6bc0993bffb2dfdd0680876f0fb02b460c7b9
|
|
4
|
+
data.tar.gz: 963f4b10da5e844ae15e91f3b1efa68efe06b426cdcdc5790e72dc62cfd67cbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 077b1d2c6671caff9b34b26ac18692d16b95284cfaeae146a632faa446f544da19a887c647e4eeed77d1efc9d4a5240931f0fd003aebec8feb4c6883ca79334b
|
|
7
|
+
data.tar.gz: db30ef57483278bb6319ec0b8a6e037bb7efefb458da0ddf05bb4959ccdfe88fd366b0c75615b976298f927e4905549f977661a8dced2be436cd5ce11c5f81bc
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 0.1.3 / 2025-10-29
|
|
4
|
+
|
|
5
|
+
* Added documentation for new options:
|
|
6
|
+
`alt`, `badge_svg`, `class`, `dist_url`, `git_url`, `image`, `name`, `label`,
|
|
7
|
+
`style`, `title` and `user_id`
|
|
8
|
+
* Added `spec.platform` to `jekyll_badge.gemspec` because `RubyGems.org` now requires it
|
|
9
|
+
* Long labels are now wrapped after underscores
|
|
10
|
+
|
|
11
|
+
|
|
3
12
|
## 0.1.2
|
|
4
13
|
|
|
5
14
|
* Updated to `jekyll_plugin_support` v1.0.0
|
data/README.md
CHANGED
|
@@ -31,10 +31,43 @@ See [demo/index.html](demo/index.html) for examples.
|
|
|
31
31
|
|
|
32
32
|
### Options
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- `clear`
|
|
37
|
-
- `
|
|
34
|
+
#### Keyword Options
|
|
35
|
+
|
|
36
|
+
- `clear` – Ensures the badge is rendered below preceding floating elements.
|
|
37
|
+
- `debug` – Display debugging information on the rendered page
|
|
38
|
+
|
|
39
|
+
#### Primary Options
|
|
40
|
+
|
|
41
|
+
Override these name/value options as required.
|
|
42
|
+
|
|
43
|
+
- `align` – Align badge `left`, `center` or `right`, defaults to `right`.
|
|
44
|
+
- `alt` – Alt text for badge image, also used as title for badge.
|
|
45
|
+
Defaults to `name`.
|
|
46
|
+
- `class` – Override classes for generated badge,
|
|
47
|
+
defaults to `rounded shadow`.
|
|
48
|
+
- `dist_url` – Badge banner link target (download page),
|
|
49
|
+
defaults to `https://rubygems.org/gems/name`.
|
|
50
|
+
- `image` – Git repository image, without the filetype,
|
|
51
|
+
defaults to `/blog/images/git/github-mark`.
|
|
52
|
+
- `name` – name of component, defaults to the name of the enclosing page.
|
|
53
|
+
- `label` – displayed name of the badge, defaults to `name`.
|
|
54
|
+
- `style` – Additional CSS style for the badge container.
|
|
55
|
+
- `title` – Displayed text when the user hovers their mouse over the
|
|
56
|
+
badge. Defaults to the `alt` value.
|
|
57
|
+
- `type` – Type of badge to display.
|
|
58
|
+
Choices are `ruby_gem` (default) and `golang`.
|
|
59
|
+
- `user_id` – GitHub user id
|
|
60
|
+
(only required for type `golang`, defaults to `mslinn`.)
|
|
61
|
+
|
|
62
|
+
#### Derived Options
|
|
63
|
+
|
|
64
|
+
Derived options can be overridden, just like primary options.
|
|
65
|
+
|
|
66
|
+
- `badge_svg` – URL for badge image,
|
|
67
|
+
defaults to `https://badge.fury.io/rb/name.svg`.
|
|
68
|
+
- `git_url_base` – GitHub User URL,
|
|
69
|
+
defaults to `https://github.com/mslinn`.
|
|
70
|
+
- `git_url` – Repository URL, defaults to `git_url_base/name`.
|
|
38
71
|
|
|
39
72
|
|
|
40
73
|
## Development
|
data/jekyll_badge.gemspec
CHANGED
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
'source_code_uri' => host,
|
|
20
20
|
}
|
|
21
21
|
spec.name = 'jekyll_badge'
|
|
22
|
+
spec.platform = Gem::Platform::RUBY
|
|
22
23
|
spec.post_install_message = <<~END_MESSAGE
|
|
23
24
|
|
|
24
25
|
Thanks for installing #{spec.name}!
|
|
@@ -28,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
|
28
29
|
spec.required_ruby_version = '>= 3.1.0'
|
|
29
30
|
spec.summary = 'Displays a badge on a Jekyll page for the package showing its version'
|
|
30
31
|
spec.version = JekyllBadge::VERSION
|
|
32
|
+
|
|
31
33
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
|
32
34
|
spec.add_dependency 'jekyll_plugin_support', '>= 1.0.0'
|
|
33
35
|
spec.add_dependency 'ruby-link-checker'
|
data/lib/jekyll_badge/version.rb
CHANGED
data/lib/jekyll_badge.rb
CHANGED
|
@@ -19,17 +19,36 @@ module JekyllBadge
|
|
|
19
19
|
VERSION = ::JekyllBadge::VERSION
|
|
20
20
|
|
|
21
21
|
def render_impl
|
|
22
|
-
|
|
22
|
+
# Keyword options
|
|
23
23
|
@clear = @helper.parameter_specified?('clear') ? 'clear' : nil
|
|
24
|
+
@debug = @helper.parameter_specified?('debug')
|
|
25
|
+
|
|
26
|
+
# Primary options
|
|
27
|
+
@align = @helper.parameter_specified?('align') || 'right'
|
|
24
28
|
@class = @helper.parameter_specified?('class') || 'rounded shadow'
|
|
25
29
|
# TODO: put this into _config.yml
|
|
26
30
|
@git_url_base = @helper.parameter_specified?('git_url_base') || 'https://github.com/mslinn'
|
|
27
|
-
@image = @helper.parameter_specified?('image')
|
|
31
|
+
@image = @helper.parameter_specified?('image') || '/blog/images/git/github-mark'
|
|
32
|
+
@style = @helper.parameter_specified?('style') || ''
|
|
33
|
+
@type = @helper.parameter_specified?('type') || 'ruby_gem'
|
|
34
|
+
@user_id = @helper.parameter_specified?('user_id') || 'mslinn'
|
|
35
|
+
|
|
36
|
+
# Derived options
|
|
28
37
|
@name = @helper.parameter_specified?('name') || @page['name']
|
|
29
38
|
@label = @helper.parameter_specified?('label') || @name
|
|
30
|
-
@style = @
|
|
31
|
-
@git_url = @helper.parameter_specified?('git_url') || "#{@git_url_base}/#{@name}"
|
|
39
|
+
@style = "#{@style} width: 28em;".squish if @debug
|
|
32
40
|
|
|
41
|
+
# Further derived options
|
|
42
|
+
@alt = @helper.parameter_specified?('alt') || default_alt
|
|
43
|
+
@badge_svg = @helper.parameter_specified?('badge_src') || default_badge_svg
|
|
44
|
+
@dist_url = @helper.parameter_specified?('dist_url') || default_dist_url
|
|
45
|
+
@git_url = @helper.parameter_specified?('git_url') || "#{@git_url_base}/#{@name}"
|
|
46
|
+
|
|
47
|
+
# Yet further derived options
|
|
48
|
+
@title = " title='#{@alt}'" if @alt
|
|
49
|
+
|
|
50
|
+
# Tweaking
|
|
51
|
+
@label = @label.gsub('_', '_<wbr>')
|
|
33
52
|
unless %w[left center right].include? @align
|
|
34
53
|
@helper.logger.warn { "Ignoring invalid align value ('#{@align}') on line #{@line_number} (plus front matter) of #{@page['name']}." }
|
|
35
54
|
@align = 'right'
|
|
@@ -38,67 +57,13 @@ module JekyllBadge
|
|
|
38
57
|
if @check_links
|
|
39
58
|
check_url
|
|
40
59
|
else
|
|
41
|
-
|
|
60
|
+
output
|
|
42
61
|
end
|
|
43
62
|
end
|
|
44
63
|
|
|
45
|
-
private
|
|
46
|
-
|
|
47
|
-
# Calling this method can slow down startup time dramatically because of HTTP timeouts
|
|
48
|
-
# Better to use this functionality in parallel, the way it was designed, instead of this
|
|
49
|
-
def check_url
|
|
50
|
-
@helper.logger.info 'Checking links, please wait ...'
|
|
51
|
-
@link_checker.check @git_url
|
|
52
|
-
@link_checker.results.each_pair do |_bucket, result|
|
|
53
|
-
if result
|
|
54
|
-
generate_output
|
|
55
|
-
else
|
|
56
|
-
msg = "Error: #{@git_url} is broken"
|
|
57
|
-
@helper.logger.error { msg }
|
|
58
|
-
"<span style='color: red;'>#{msg}</span>"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def generate_output
|
|
64
|
-
classes = "gem_banner #{@align} #{@class} #{@clear}".squish
|
|
65
|
-
<<~END_CONTENT
|
|
66
|
-
<div class="#{classes}" style='#{@style}'>
|
|
67
|
-
<div class="center one_column">
|
|
68
|
-
<a href='https://rubygems.org/gems/#{@name}' target='_blank' class='imgImgUrl'>
|
|
69
|
-
#{"<code class='banner_label'>#{@label}</code>" unless @label.empty?}
|
|
70
|
-
<div class='imgWrapper imgFlex center' style='margin-bottom: 0;'>
|
|
71
|
-
<picture class='imgPicture'>
|
|
72
|
-
<source srcset="https://badge.fury.io/rb/#{@name}.svg" type="image/webp">
|
|
73
|
-
<source srcset="https://badge.fury.io/rb/#{@name}.svg" type="image/png">
|
|
74
|
-
<img alt='#{@name} version'
|
|
75
|
-
class="imgImg"
|
|
76
|
-
src="https://badge.fury.io/rb/#{@name}.svg"
|
|
77
|
-
style='width: 100%;'
|
|
78
|
-
title='#{@name} version'
|
|
79
|
-
/>
|
|
80
|
-
</picture>
|
|
81
|
-
</a>
|
|
82
|
-
</div>
|
|
83
|
-
<div class='imgWrapper imgFlex center' style='width: 120px;'>
|
|
84
|
-
<a href="#{@git_url}" target='_blank' class='imgImgUrl'>
|
|
85
|
-
<picture class='imgPicture'>
|
|
86
|
-
<source srcset="#{@image}.webp" type="image/webp">
|
|
87
|
-
<source srcset="#{@image}.png" type="image/png">
|
|
88
|
-
<img alt='GitHub project for #{@name}'
|
|
89
|
-
class="imgImg"
|
|
90
|
-
src="/blog/images/git/github-mark.png"
|
|
91
|
-
style='width: 100%;'
|
|
92
|
-
title='Git project for #{@name}'
|
|
93
|
-
/>
|
|
94
|
-
</picture>
|
|
95
|
-
</div>
|
|
96
|
-
</a>
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
END_CONTENT
|
|
100
|
-
end
|
|
101
|
-
|
|
102
64
|
::JekyllSupport::JekyllPluginHelper.register(self, PLUGIN_NAME)
|
|
103
65
|
end
|
|
104
66
|
end
|
|
67
|
+
|
|
68
|
+
require_relative 'jekyll_badge_private'
|
|
69
|
+
require_relative 'jekyll_badge_generate'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module JekyllBadge
|
|
2
|
+
class JekyllBadge
|
|
3
|
+
private
|
|
4
|
+
|
|
5
|
+
def generate_banner
|
|
6
|
+
<<~END_CONTENT
|
|
7
|
+
<!-- Colorful badge banner with version info, links to release -->
|
|
8
|
+
#{"<code class='banner_label'>#{@label}</code>" unless @label.empty?}
|
|
9
|
+
<div class='imgWrapper imgFlex center' style='margin-bottom: 0;'>
|
|
10
|
+
<picture class='imgPicture'>
|
|
11
|
+
<source srcset="#{@badge_svg}" type="image/webp">
|
|
12
|
+
<source srcset="#{@badge_svg}" type="image/png">
|
|
13
|
+
<img alt='#{@alt}'
|
|
14
|
+
class="imgImg"
|
|
15
|
+
src="#{@badge_svg}"
|
|
16
|
+
style='width: 100%;'
|
|
17
|
+
title='#{@name}'
|
|
18
|
+
/>
|
|
19
|
+
</picture>
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
END_CONTENT
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def generate_remainder
|
|
26
|
+
<<~END_CONTENT
|
|
27
|
+
<!-- Remainder of badge content -->
|
|
28
|
+
<div class='imgWrapper imgFlex center' style='width: 120px;'>
|
|
29
|
+
<a class='imgImgUrl' href="#{@git_url}" target='_blank'>
|
|
30
|
+
<picture class='imgPicture'>
|
|
31
|
+
<source srcset="#{@image}.webp" type="image/webp">
|
|
32
|
+
<source srcset="#{@image}.png" type="image/png">
|
|
33
|
+
<img alt='GitHub project for #{@name}'
|
|
34
|
+
class="imgImg"
|
|
35
|
+
src="/blog/images/git/github-mark.png"
|
|
36
|
+
style='width: 100%;'
|
|
37
|
+
title='Git project for #{@name}'
|
|
38
|
+
/>
|
|
39
|
+
</picture>
|
|
40
|
+
</div>
|
|
41
|
+
END_CONTENT
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def output
|
|
45
|
+
classes = "gem_banner #{@align} #{@class} #{@clear}".squish
|
|
46
|
+
|
|
47
|
+
<<~END_CONTENT
|
|
48
|
+
<div class="#{classes}" style='#{@style}'#{@title}>
|
|
49
|
+
<div class="center one_column">
|
|
50
|
+
<a class='imgImgUrl' href='#{@dist_url}' target='_blank'>
|
|
51
|
+
#{generate_banner}
|
|
52
|
+
</a>
|
|
53
|
+
<a class='imgImgUrl' href='#{@git_url}' target='_blank'>
|
|
54
|
+
#{generate_remainder}
|
|
55
|
+
</a>
|
|
56
|
+
</div>#{debug}
|
|
57
|
+
</div>#{@warning}
|
|
58
|
+
END_CONTENT
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module JekyllBadge
|
|
2
|
+
class JekyllBadge
|
|
3
|
+
private
|
|
4
|
+
|
|
5
|
+
# Calling this method can slow down startup time dramatically because of HTTP timeouts
|
|
6
|
+
# Better to use this functionality in parallel, the way it was designed, instead of this way
|
|
7
|
+
def check_url
|
|
8
|
+
@helper.logger.info 'Checking links, please wait ...'
|
|
9
|
+
@link_checker.check @git_url
|
|
10
|
+
@link_checker.results.each_pair do |_bucket, result|
|
|
11
|
+
if result
|
|
12
|
+
output
|
|
13
|
+
else
|
|
14
|
+
msg = "Error: #{@git_url} is broken"
|
|
15
|
+
@helper.logger.error { msg }
|
|
16
|
+
"<span style='color: red;'>#{msg}</span>"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def debug
|
|
22
|
+
return unless @debug
|
|
23
|
+
|
|
24
|
+
debug = "\n<pre>"
|
|
25
|
+
debug += "badge_svg=#{@badge_svg}\n"
|
|
26
|
+
debug += "dist_url=#{@dist_url}\n"
|
|
27
|
+
debug += "git_url_base=#{@git_url_base}\n"
|
|
28
|
+
debug += "git_url=#{@git_url}\n"
|
|
29
|
+
debug += "image=#{@image}"
|
|
30
|
+
debug += "</pre>\n"
|
|
31
|
+
debug
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def default_alt
|
|
35
|
+
case @type
|
|
36
|
+
when 'ruby_gem'
|
|
37
|
+
'Latest Ruby gem'
|
|
38
|
+
when 'golang'
|
|
39
|
+
'GitHub newest release'
|
|
40
|
+
else
|
|
41
|
+
@name
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def default_badge_svg
|
|
46
|
+
case @type
|
|
47
|
+
when 'ruby_gem'
|
|
48
|
+
"https://badge.fury.io/rb/#{@name}.svg"
|
|
49
|
+
when 'golang'
|
|
50
|
+
"https://img.shields.io/github/v/release/#{@user_id}/#{@name}"
|
|
51
|
+
else # This is the only place this check is made
|
|
52
|
+
@warning = "<span style='color: darkred'>Error: Type #{@type} is invalid; choices are golang and ruby_gem</span>"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def default_dist_url
|
|
57
|
+
case @type
|
|
58
|
+
when 'ruby_gem'
|
|
59
|
+
"https://rubygems.org/gems/#{@name}"
|
|
60
|
+
when 'golang'
|
|
61
|
+
"https://github.com/#{@user_id}/#{@name}/releases"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/spec/badge/badge_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require_relative '
|
|
1
|
+
require_relative '../../lib/jekyll_badge'
|
|
2
2
|
|
|
3
|
-
RSpec.describe
|
|
3
|
+
RSpec.describe JekyllBadge do
|
|
4
4
|
let(:logger) do
|
|
5
5
|
PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
|
6
6
|
end
|
|
@@ -8,6 +8,6 @@ RSpec.describe Badge::Badge do
|
|
|
8
8
|
let(:parse_context) { TestParseContext.new }
|
|
9
9
|
|
|
10
10
|
it 'has a test' do
|
|
11
|
-
expect(true).to
|
|
11
|
+
expect(true).to be_truthy
|
|
12
12
|
end
|
|
13
13
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll_badge
|
|
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
|
- Mike Slinn
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: jekyll
|
|
@@ -68,6 +67,8 @@ files:
|
|
|
68
67
|
- jekyll_badge.gemspec
|
|
69
68
|
- lib/jekyll_badge.rb
|
|
70
69
|
- lib/jekyll_badge/version.rb
|
|
70
|
+
- lib/jekyll_badge_generate.rb
|
|
71
|
+
- lib/jekyll_badge_private.rb
|
|
71
72
|
- spec/badge/badge_spec.rb
|
|
72
73
|
- spec/spec_helper.rb
|
|
73
74
|
homepage: https://www.mslinn.com/jekyll_plugins/jekyll_badge.html
|
|
@@ -97,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
97
98
|
- !ruby/object:Gem::Version
|
|
98
99
|
version: '0'
|
|
99
100
|
requirements: []
|
|
100
|
-
rubygems_version: 3.
|
|
101
|
-
signing_key:
|
|
101
|
+
rubygems_version: 3.7.2
|
|
102
102
|
specification_version: 4
|
|
103
103
|
summary: Displays a badge on a Jekyll page for the package showing its version
|
|
104
104
|
test_files: []
|