jekyll_nth 1.0.0 → 1.1.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +13 -2
- data/jekyll_nth.gemspec +1 -1
- data/lib/jekyll_nth/version.rb +2 -2
- data/lib/jekyll_nth.rb +11 -5
- data/spec/jekyll_nth_spec.rb +30 -0
- data/spec/spec_helper.rb +4 -1
- metadata +4 -4
- data/spec/jekyll_nth.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52bf7aefeec224b1fff7ed106464938f18518e1133e72eea98f26deedc51c7b7
|
4
|
+
data.tar.gz: 8249f5e86dd728269c1448b4a8a87377e39794a66578a9914f485e9716dfa471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f41efdd5a3817c1cc5d656345089a7d2b450ba6b3c96640a253cb0ef60e2d156c4b9ab003f578b5588b17c1c191cc9f5706538e18d1e6ae1b3cd3f1002303ece
|
7
|
+
data.tar.gz: 02a41c070c868660d761df13d9b1c69f5de0ed653770e4af988e005dd56b80a0e4eb647a31ffe27177789c50b879f9b862f86bb8cad5c6f16d2d9bae317fe6ac
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,15 +2,26 @@
|
|
2
2
|
[](https://badge.fury.io/rb/jekyll_nth)
|
3
3
|
===========
|
4
4
|
|
5
|
-
`jekyll_nth`
|
5
|
+
`jekyll_nth` provides two Jekyll filter plugin that manipulate arrays.
|
6
|
+
|
7
|
+
* `nth` returns item `n` of the array, origin 0.
|
8
|
+
* `tail` returns the remainder of the array after the first element.
|
6
9
|
|
7
10
|
## Usage
|
8
11
|
|
9
12
|
```
|
10
|
-
{{ [1, 2, 3, 4, 5] | nth: 2 }} # returns
|
13
|
+
{{ [1, 2, 3, 4, 5] | nth: 2 }} # returns 3
|
14
|
+
{{ [1, 2, 3, 4, 5] | nth: -1 }} # returns 5
|
15
|
+
{{ [1, 2, 3, 4, 5] | nth: 99 }} # throws exception
|
11
16
|
```
|
12
17
|
: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
18
|
|
19
|
+
```
|
20
|
+
{{ [1, 2, 3, 4, 5] | tail }} # returns [2, 3, 4, 5]
|
21
|
+
{{ [1] | tail }} # returns []
|
22
|
+
{{ [] | tail }} # throws exception
|
23
|
+
```
|
24
|
+
|
14
25
|
|
15
26
|
## Installation
|
16
27
|
|
data/jekyll_nth.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.required_ruby_version = ">= 2.6.0"
|
33
33
|
spec.summary = "Provides a Jekyll filter that enables access to the nth items of an array."
|
34
34
|
spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
|
35
|
-
spec.version =
|
35
|
+
spec.version = JekyllNthVersion::VERSION
|
36
36
|
|
37
37
|
spec.add_dependency "jekyll", ">= 3.5.0"
|
38
38
|
spec.add_dependency "jekyll_plugin_logger"
|
data/lib/jekyll_nth/version.rb
CHANGED
data/lib/jekyll_nth.rb
CHANGED
@@ -8,15 +8,21 @@ module JekyllPluginNthName
|
|
8
8
|
PLUGIN_NAME = "jekyll_nth"
|
9
9
|
end
|
10
10
|
|
11
|
-
module
|
11
|
+
module ArrayManipulation
|
12
12
|
# @return nth item of an array, origin 1
|
13
13
|
def nth(array, index)
|
14
|
-
abort "
|
15
|
-
abort "
|
14
|
+
abort "jekyll_nth error: array passed to nth was empty." if array.nil? || array.empty?
|
15
|
+
abort "jekyll_nth error: array passed to nth has only #{array.length} items, but item #{index} was requested." if array.length < index.abs
|
16
16
|
|
17
17
|
array[index]
|
18
18
|
end
|
19
|
+
|
20
|
+
def tail(array)
|
21
|
+
abort "jekyll_nth error: array passed to tail was empty." if array.nil? || array.empty?
|
22
|
+
|
23
|
+
array[1..]
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
|
-
PluginMetaLogger.instance.info { "Loaded #{JekyllPluginNthName::PLUGIN_NAME} v#{
|
22
|
-
Liquid::Template.register_filter(
|
27
|
+
PluginMetaLogger.instance.info { "Loaded #{JekyllPluginNthName::PLUGIN_NAME} v#{JekyllNthVersion::VERSION} plugin." }
|
28
|
+
Liquid::Template.register_filter(ArrayManipulation)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require_relative "../lib/jekyll_nth"
|
5
|
+
|
6
|
+
RSpec.describe(ArrayManipulation) do
|
7
|
+
include ArrayManipulation
|
8
|
+
|
9
|
+
let(:config) { instance_double("Configuration") }
|
10
|
+
let(:context) do
|
11
|
+
context_ = instance_double("Liquid::Context")
|
12
|
+
context_.config = config
|
13
|
+
context_
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the usual Ruby value" do
|
17
|
+
array = [1, 2, 3, 4, 5]
|
18
|
+
expect(nth(array, -1)).to eq(5)
|
19
|
+
expect(nth(array, 0)).to eq(1)
|
20
|
+
expect(nth(array, 2)).to eq(3)
|
21
|
+
expect(nth(array, 99)).to raise_exception
|
22
|
+
expect(nth([], 1)).to raise_exception
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns normal tail" do
|
26
|
+
expect(tail([1, 2, 3, 4, 5])).to eq([2, 3, 4, 5])
|
27
|
+
expect(tail([1])).to eq([])
|
28
|
+
expect(tail([])).to raise_exception
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,10 @@ require "jekyll"
|
|
4
4
|
require_relative "../lib/jekyll_nth"
|
5
5
|
|
6
6
|
RSpec.configure do |config|
|
7
|
-
config.run_all_when_everything_filtered = true
|
8
7
|
config.filter_run :focus
|
9
8
|
config.order = "random"
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
|
11
|
+
# See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
|
12
|
+
config.example_status_persistence_file_path = "spec/status_persistence.txt"
|
10
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_nth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -84,7 +84,7 @@ files:
|
|
84
84
|
- jekyll_nth.gemspec
|
85
85
|
- lib/jekyll_nth.rb
|
86
86
|
- lib/jekyll_nth/version.rb
|
87
|
-
- spec/
|
87
|
+
- spec/jekyll_nth_spec.rb
|
88
88
|
- spec/spec_helper.rb
|
89
89
|
homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#nth
|
90
90
|
licenses:
|
@@ -118,5 +118,5 @@ signing_key:
|
|
118
118
|
specification_version: 4
|
119
119
|
summary: Provides a Jekyll filter that enables access to the nth items of an array.
|
120
120
|
test_files:
|
121
|
-
- spec/
|
121
|
+
- spec/jekyll_nth_spec.rb
|
122
122
|
- spec/spec_helper.rb
|
data/spec/jekyll_nth.rb
DELETED
@@ -1,21 +0,0 @@
|
|
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
|