jekyll_nth 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49d85c0259d029eef93fbefb103fd935ced149811c4c6b548b479e7d1e036fc6
4
- data.tar.gz: 31377d3dca4d996e2d2ff6234c9696e2e9b6933439791dfd2e8d5bcd8dba6065
3
+ metadata.gz: 52bf7aefeec224b1fff7ed106464938f18518e1133e72eea98f26deedc51c7b7
4
+ data.tar.gz: 8249f5e86dd728269c1448b4a8a87377e39794a66578a9914f485e9716dfa471
5
5
  SHA512:
6
- metadata.gz: 31e884aca763df03483c90d6c3bc79f89cb2f4cb14fae568bf7f17d257a01963d0dd59697a695e3652d444263502e2fa18d25c766c9008bab6f57a96fee6ed4e
7
- data.tar.gz: '0115284e7827391b8863d064046162d1282fb7d3d49dce3b04f18095df99bb6ad07e148dabf1224d08aaabbb851ac1b58de8d238397208b21ff64413a77625bb'
6
+ metadata.gz: f41efdd5a3817c1cc5d656345089a7d2b450ba6b3c96640a253cb0ef60e2d156c4b9ab003f578b5588b17c1c191cc9f5706538e18d1e6ae1b3cd3f1002303ece
7
+ data.tar.gz: 02a41c070c868660d761df13d9b1c69f5de0ed653770e4af988e005dd56b80a0e4eb647a31ffe27177789c50b879f9b862f86bb8cad5c6f16d2d9bae317fe6ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.1.0 / 2022-04-27
2
+ * Added tail method
3
+
1
4
  ## 1.0.0 / 2022-03-16
2
5
  * Published as a gem
3
6
 
data/README.md CHANGED
@@ -2,15 +2,26 @@
2
2
  [![Gem Version](https://badge.fury.io/rb/jekyll_nth.svg)](https://badge.fury.io/rb/jekyll_nth)
3
3
  ===========
4
4
 
5
- `jekyll_nth` is a Jekyll filter plugin that returns item n of array, origin 1.
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 2
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 = JekyllNth::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"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module JekyllNth
4
- VERSION = "1.0.0"
3
+ module JekyllNthVersion
4
+ VERSION = "1.1.0"
5
5
  end
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 Jekyll
11
+ module ArrayManipulation
12
12
  # @return nth item of an array, origin 1
13
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
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#{JekyllNth::VERSION} plugin." }
22
- Liquid::Template.register_filter(Jekyll)
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.0.0
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-03-25 00:00:00.000000000 Z
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/jekyll_nth.rb
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/jekyll_nth.rb
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