jekyll_nth 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 +96 -0
- data/Rakefile +7 -0
- data/jekyll_nth.gemspec +46 -0
- data/lib/jekyll_nth/version.rb +5 -0
- data/lib/jekyll_nth.rb +22 -0
- data/spec/jekyll_nth.rb +21 -0
- data/spec/spec_helper.rb +10 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49d85c0259d029eef93fbefb103fd935ced149811c4c6b548b479e7d1e036fc6
|
4
|
+
data.tar.gz: 31377d3dca4d996e2d2ff6234c9696e2e9b6933439791dfd2e8d5bcd8dba6065
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31e884aca763df03483c90d6c3bc79f89cb2f4cb14fae568bf7f17d257a01963d0dd59697a695e3652d444263502e2fa18d25c766c9008bab6f57a96fee6ed4e
|
7
|
+
data.tar.gz: '0115284e7827391b8863d064046162d1282fb7d3d49dce3b04f18095df99bb6ad07e148dabf1224d08aaabbb851ac1b58de8d238397208b21ff64413a77625bb'
|
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,96 @@
|
|
1
|
+
`jekyll_nth`
|
2
|
+
[](https://badge.fury.io/rb/jekyll_nth)
|
3
|
+
===========
|
4
|
+
|
5
|
+
`jekyll_nth` is a Jekyll filter plugin that returns item n of array, origin 1.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```
|
10
|
+
{{ [1, 2, 3, 4, 5] | nth: 2 }} # returns 2
|
11
|
+
```
|
12
|
+
:warning: Important: the name of the filter must be followed by a colon (:). If you fail to do that an error will be generated and the Jekyll site building process will halt. The error message looks something like this: `Liquid Warning: Liquid syntax error (line 285): Expected end_of_string but found string in "{{ [1, 2, 3, 4, 5] | nth: '2' }}" in /some_directory/some_files.html Liquid Exception: Liquid error (line 285): wrong number of arguments (given 1, expected 2) in /some_directory/some_file.html Error: Liquid error (line 285): wrong number of arguments (given 1, expected 2)`
|
13
|
+
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'jekyll_nth'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle install
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install jekyll_nth
|
30
|
+
|
31
|
+
|
32
|
+
## Additional Information
|
33
|
+
More information is available on
|
34
|
+
[Mike Slinn’s website](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
|
35
|
+
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
40
|
+
|
41
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
|
44
|
+
### Build and Install Locally
|
45
|
+
To build and install this gem onto your local machine, run:
|
46
|
+
```shell
|
47
|
+
$ rake install:local
|
48
|
+
```
|
49
|
+
|
50
|
+
The following also does the same thing:
|
51
|
+
```shell
|
52
|
+
$ bundle exec rake install
|
53
|
+
jekyll_nth 1.0.0 built to pkg/jekyll_nth-0.1.0.gem.
|
54
|
+
jekyll_nth (1.0.0) installed.
|
55
|
+
```
|
56
|
+
|
57
|
+
Examine the newly built gem:
|
58
|
+
```
|
59
|
+
$ gem info jekyll_nth
|
60
|
+
|
61
|
+
*** LOCAL GEMS ***
|
62
|
+
|
63
|
+
jekyll_nth (1.0.0)
|
64
|
+
Author: Mike Slinn
|
65
|
+
Homepage:
|
66
|
+
https://github.com/mslinn/jekyll_nth
|
67
|
+
License: MIT
|
68
|
+
Installed at: /home/mslinn/.gems
|
69
|
+
|
70
|
+
Generates Jekyll logger with colored output.
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
### Build and Push to RubyGems
|
75
|
+
To release a new version,
|
76
|
+
1. Update the version number in `version.rb`.
|
77
|
+
2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
|
78
|
+
3. Run the following:
|
79
|
+
```shell
|
80
|
+
$ bundle exec rake release
|
81
|
+
```
|
82
|
+
The above creates a git tag for the version, commits the created tag,
|
83
|
+
and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
1. Fork the project
|
89
|
+
2. Create a descriptively named feature branch
|
90
|
+
3. Add your feature
|
91
|
+
4. Submit a pull request
|
92
|
+
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/jekyll_nth.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/jekyll_nth/version"
|
4
|
+
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
github = "https://github.com/mslinn/jekyll_nth"
|
8
|
+
|
9
|
+
spec.authors = ["Mike Slinn"]
|
10
|
+
spec.bindir = "exe"
|
11
|
+
spec.description = <<~END_OF_DESC
|
12
|
+
Provides a Jekyll filter that enables access to the nth items of an array.
|
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#nth"
|
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_nth"
|
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 filter that enables access to the nth items of an array."
|
34
|
+
spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
|
35
|
+
spec.version = JekyllNth::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
|
data/lib/jekyll_nth.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll_plugin_logger"
|
4
|
+
require "liquid"
|
5
|
+
require_relative "jekyll_nth/version"
|
6
|
+
|
7
|
+
module JekyllPluginNthName
|
8
|
+
PLUGIN_NAME = "jekyll_nth"
|
9
|
+
end
|
10
|
+
|
11
|
+
module Jekyll
|
12
|
+
# @return nth item of an array, origin 1
|
13
|
+
def nth(array, index)
|
14
|
+
abort "nth error: array was empty." if array.nil?
|
15
|
+
abort "nth error: array has only #{array.length} items, but item #{index} was requested." if array.length < index.abs
|
16
|
+
|
17
|
+
array[index]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
PluginMetaLogger.instance.info { "Loaded #{JekyllPluginNthName::PLUGIN_NAME} v#{JekyllNth::VERSION} plugin." }
|
22
|
+
Liquid::Template.register_filter(Jekyll)
|
data/spec/jekyll_nth.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require_relative "../lib/jekyll_nth"
|
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,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_nth
|
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 filter that enables access to the nth items of an
|
70
|
+
array.
|
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_nth.gemspec
|
85
|
+
- lib/jekyll_nth.rb
|
86
|
+
- lib/jekyll_nth/version.rb
|
87
|
+
- spec/jekyll_nth.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#nth
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
allowed_push_host: https://rubygems.org
|
94
|
+
bug_tracker_uri: https://github.com/mslinn/jekyll_nth/issues
|
95
|
+
changelog_uri: https://github.com/mslinn/jekyll_nth/CHANGELOG.md
|
96
|
+
homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#nth
|
97
|
+
source_code_uri: https://github.com/mslinn/jekyll_nth
|
98
|
+
post_install_message: |2+
|
99
|
+
|
100
|
+
Thanks for installing jekyll_nth!
|
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 filter that enables access to the nth items of an array.
|
120
|
+
test_files:
|
121
|
+
- spec/jekyll_nth.rb
|
122
|
+
- spec/spec_helper.rb
|