jekyll_download_link 1.0.0
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/.rubocop.yml +17 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +105 -0
- data/Rakefile +7 -0
- data/jekyll_download_link.gemspec +46 -0
- data/lib/jekyll_download_link/version.rb +5 -0
- data/lib/jekyll_download_link.rb +48 -0
- data/spec/jekyll_download_link.rb +21 -0
- data/spec/spec_helper.rb +10 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5c97ab0a7c2a3b68247bcb8bd288accad95d2f4bbf4ac7d6cf680524d176f9f4
|
4
|
+
data.tar.gz: 1e9f9d02f2c249f8d59ac7a787c539c5746ba340b080beb0c6050d1bb760c4ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84be7f74f4a327b86f947d6da1a36ebea948e245635e89ee7f9a5b86d1365c579c18f895171e4bfbccdb4694cebdc823bae31b1d39b29398537cc8b01ad0959e
|
7
|
+
data.tar.gz: 35d5f22d4b6b60bb6917039bab880a509b40ea4c00d15567723f34e19d16def19f1de894a5c86c0ffe05252ae508fd324125d5379efc391c0829d51445eb1170
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require: rubocop-jekyll
|
2
|
+
inherit_gem:
|
3
|
+
rubocop-jekyll: .rubocop.yml
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- vendor/**/*
|
8
|
+
- Gemfile*
|
9
|
+
- '*.gemspec' # This does nothing. Why?
|
10
|
+
NewCops: enable
|
11
|
+
TargetRubyVersion: 2.6
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 150
|
15
|
+
|
16
|
+
# Gemspec/RequireMFA:
|
17
|
+
# enable: false
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Mike Slinn
|
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,105 @@
|
|
1
|
+
`jekyll_download_link`
|
2
|
+
[](https://badge.fury.io/rb/jekyll_download_link)
|
3
|
+
===========
|
4
|
+
|
5
|
+
`jekyll_download_link` is a Jekyll tag plugin that generates a link to the given URI, which must be a file on the server.
|
6
|
+
The file name can be absolute or relative to the top-level directory of the web site.
|
7
|
+
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
```
|
11
|
+
{% download_link cloud9.tar %}
|
12
|
+
```
|
13
|
+
|
14
|
+
Generates:
|
15
|
+
|
16
|
+
```
|
17
|
+
<a href="/cloud9.tar"><code>cloud9.tar</code></a> (4.5 KB)
|
18
|
+
```
|
19
|
+
|
20
|
+
Which renders as:<br>
|
21
|
+
<a href="/cloud9.tar">`cloud9.tar`</a> (4.5 KB)
|
22
|
+
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'jekyll_download_link'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle install
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install jekyll_download_link
|
39
|
+
|
40
|
+
|
41
|
+
## Additional Information
|
42
|
+
More information is available on
|
43
|
+
[Mike Slinn’s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
|
44
|
+
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
49
|
+
|
50
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
51
|
+
|
52
|
+
|
53
|
+
### Build and Install Locally
|
54
|
+
To build and install this gem onto your local machine, run:
|
55
|
+
```shell
|
56
|
+
$ rake install:local
|
57
|
+
```
|
58
|
+
|
59
|
+
The following also does the same thing:
|
60
|
+
```shell
|
61
|
+
$ bundle exec rake install
|
62
|
+
jekyll_download_link 1.0.0 built to pkg/jekyll_download_link-0.1.0.gem.
|
63
|
+
jekyll_download_link (1.0.0) installed.
|
64
|
+
```
|
65
|
+
|
66
|
+
Examine the newly built gem:
|
67
|
+
```shell
|
68
|
+
$ gem info jekyll_download_link
|
69
|
+
|
70
|
+
*** LOCAL GEMS ***
|
71
|
+
|
72
|
+
jekyll_download_link (1.0.0)
|
73
|
+
Author: Mike Slinn
|
74
|
+
Homepage:
|
75
|
+
https://github.com/mslinn/jekyll_download_link
|
76
|
+
License: MIT
|
77
|
+
Installed at: /home/mslinn/.gems
|
78
|
+
|
79
|
+
Generates Jekyll logger with colored output.
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
### Build and Push to RubyGems
|
84
|
+
To release a new version,
|
85
|
+
1. Update the version number in `version.rb`.
|
86
|
+
2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
|
87
|
+
3. Run the following:
|
88
|
+
```shell
|
89
|
+
$ bundle exec rake release
|
90
|
+
```
|
91
|
+
The above creates a git tag for the version, commits the created tag,
|
92
|
+
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
93
|
+
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork the project
|
98
|
+
2. Create a descriptively named feature branch
|
99
|
+
3. Add your feature
|
100
|
+
4. Submit a pull request
|
101
|
+
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/jekyll_download_link/version"
|
4
|
+
|
5
|
+
# rubocop:disable Metrics/BlockLength, Style/StringLiterals
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
github = "https://github.com/mslinn/jekyll_download_link"
|
8
|
+
|
9
|
+
spec.authors = ['Mike Slinn']
|
10
|
+
spec.bindir = 'exe'
|
11
|
+
spec.description = <<~END_OF_DESC
|
12
|
+
Provides a Jekyll tag that generates an href to a file for the user to download, plus human-friendly filesize.
|
13
|
+
END_OF_DESC
|
14
|
+
spec.email = ['mslinn@mslinn.com']
|
15
|
+
spec.files = Dir[".rubocop.yml", "LICENSE.*", "Rakefile", "{lib,spec}/**/*", "*.gemspec", "*.md"]
|
16
|
+
spec.homepage = "https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#download"
|
17
|
+
spec.license = 'MIT'
|
18
|
+
spec.metadata = {
|
19
|
+
"allowed_push_host" => "https://rubygems.org",
|
20
|
+
"bug_tracker_uri" => "#{github}/issues",
|
21
|
+
"changelog_uri" => "#{github}/CHANGELOG.md",
|
22
|
+
"homepage_uri" => spec.homepage,
|
23
|
+
"source_code_uri" => github,
|
24
|
+
}
|
25
|
+
spec.name = 'jekyll_download_link'
|
26
|
+
spec.post_install_message = <<~END_MESSAGE
|
27
|
+
|
28
|
+
Thanks for installing #{spec.name}!
|
29
|
+
|
30
|
+
END_MESSAGE
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
spec.required_ruby_version = '>= 2.6.0'
|
33
|
+
spec.summary = 'Provides a Jekyll tag that generates an href to a file for the user to download, plus human-friendly filesize.'
|
34
|
+
spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
|
35
|
+
spec.version = JekyllDownloadLink::VERSION
|
36
|
+
|
37
|
+
spec.add_dependency "jekyll", ">= 3.5.0"
|
38
|
+
spec.add_dependency "jekyll_plugin_logger"
|
39
|
+
|
40
|
+
spec.add_development_dependency "debase"
|
41
|
+
# spec.add_development_dependency "rubocop-jekyll"
|
42
|
+
# spec.add_development_dependency "rubocop-rake"
|
43
|
+
# spec.add_development_dependency "rubocop-rspec"
|
44
|
+
spec.add_development_dependency "ruby-debug-ide"
|
45
|
+
end
|
46
|
+
# rubocop:enable Metrics/BlockLength, Style/StringLiterals
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require "jekyll_plugin_logger"
|
5
|
+
require_relative "jekyll_download_link/version"
|
6
|
+
|
7
|
+
module JekyllPluginDownloadLinkName
|
8
|
+
PLUGIN_NAME = "download_link"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Generates an href to a file for the user to download from the site.
|
12
|
+
# Also shows the file size in a human-readable format.
|
13
|
+
class DownloadLink < Liquid::Tag
|
14
|
+
# Constructor.
|
15
|
+
# @param tag_name [String] is the name of the tag, which we already know.
|
16
|
+
# Contains the name of the file, relative to the website top level directory
|
17
|
+
# @param text [Hash, String, Liquid::Tag::Parser] the arguments from the web page.
|
18
|
+
# @param tokens [Liquid::ParseContext] tokenized command line
|
19
|
+
# @return [void]
|
20
|
+
def initialize(tag_name, text, tokens)
|
21
|
+
super
|
22
|
+
@logger = PluginMetaLogger.instance.new_logger(self)
|
23
|
+
@filename = text.delete('"').delete("'").strip
|
24
|
+
end
|
25
|
+
|
26
|
+
# Method prescribed by the Jekyll plugin lifecycle.
|
27
|
+
# @return [String]
|
28
|
+
def render(context)
|
29
|
+
source = context.registers[:site].config["source"]
|
30
|
+
file_fq = File.join(source, @filename)
|
31
|
+
abort "Error: '#{file_fq}' not found. See the link tag in" unless File.exist?(file_fq)
|
32
|
+
|
33
|
+
"<a href='/#{@filename}'><code>#{@filename}</code></a> (#{as_size(File.size(file_fq))})"
|
34
|
+
end
|
35
|
+
|
36
|
+
def as_size(s)
|
37
|
+
units = %w(B KB MB GB TB)
|
38
|
+
|
39
|
+
size, unit = units.reduce(s.to_f) do |(fsize, _), utype|
|
40
|
+
fsize > 512 ? [fsize / 1024, utype] : (break [fsize, utype])
|
41
|
+
end
|
42
|
+
|
43
|
+
"#{size > 9 || size.modulo(1) < 0.1 ? "%d" : "%.1f"} %s" % [size, unit]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
PluginMetaLogger.instance.info { "Loaded #{JekyllPluginDownloadLinkName::PLUGIN_NAME} v#{JekyllDownloadLink::VERSION} plugin." }
|
48
|
+
Liquid::Template.register_tag(JekyllPluginDownloadLinkName::PLUGIN_NAME, DownloadLink)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require_relative "../lib/jekyll_download_link"
|
5
|
+
|
6
|
+
RSpec.describe(Jekyll) do
|
7
|
+
include Jekyll
|
8
|
+
|
9
|
+
let(:config) { instance_double("Configuration") }
|
10
|
+
let(:context) {
|
11
|
+
context_ = instance_double("Liquid::Context")
|
12
|
+
context_.config = config
|
13
|
+
context_
|
14
|
+
}
|
15
|
+
|
16
|
+
it "is created properly" do
|
17
|
+
run_tag = RunTag.new("run", "echo asdf")
|
18
|
+
output = run_tag.render(context)
|
19
|
+
expect(output).to eq("asdf")
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_download_link
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Slinn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-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: 3.5.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.5.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jekyll_plugin_logger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: debase
|
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: ruby-debug-ide
|
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
|
+
description: 'Provides a Jekyll tag that generates an href to a file for the user
|
70
|
+
to download, plus human-friendly filesize.
|
71
|
+
|
72
|
+
'
|
73
|
+
email:
|
74
|
+
- mslinn@mslinn.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- jekyll_download_link.gemspec
|
85
|
+
- lib/jekyll_download_link.rb
|
86
|
+
- lib/jekyll_download_link/version.rb
|
87
|
+
- spec/jekyll_download_link.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#download
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
allowed_push_host: https://rubygems.org
|
94
|
+
bug_tracker_uri: https://github.com/mslinn/jekyll_download_link/issues
|
95
|
+
changelog_uri: https://github.com/mslinn/jekyll_download_link/CHANGELOG.md
|
96
|
+
homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#download
|
97
|
+
source_code_uri: https://github.com/mslinn/jekyll_download_link
|
98
|
+
post_install_message: |2+
|
99
|
+
|
100
|
+
Thanks for installing jekyll_download_link!
|
101
|
+
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.6.0
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.1.4
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Provides a Jekyll tag that generates an href to a file for the user to download,
|
120
|
+
plus human-friendly filesize.
|
121
|
+
test_files:
|
122
|
+
- spec/jekyll_download_link.rb
|
123
|
+
- spec/spec_helper.rb
|