jekyll-sanelist 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +32 -5
- data/README.md +32 -1
- data/jekyll-sanelist.gemspec +1 -0
- data/lib/jekyll-sanelist.rb +3 -1
- data/lib/jekyll/sanelist.rb +54 -2
- data/lib/jekyll/sanelist/version.rb +1 -1
- data/spec/jekyll/sanelist/version_spec.rb +7 -0
- data/spec/jekyll/sanelist_spec.rb +60 -5
- data/spec/sanelist_helpers.rb +20 -0
- data/spec/spec_helper.rb +4 -0
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448ded78b7d926f56b51050f132b078208aa6d26770fd08bb40ecbe826549ccf
|
4
|
+
data.tar.gz: bb307c842042613403d2ddf3ae5f645c80280cd8f4592b7367a9eca161b57ef3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b33e6f509cb0e03e06d30e65524d66da61b083e2f5d9e53a5a8d3915082d755a3cbf23d5e6c5c4b74717dd0bd683b56bd9f3265afd2d5893a3d4f7f29ec290
|
7
|
+
data.tar.gz: 10dbb1574ad244054aca0c0bd00f67c703b5395d629d945e3b3edcabe375d3d508388426e861ad59af3cd557b42f3f4c957688e0e2004c34ec838a114e5d01fa
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,11 +1,27 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2021-04-26
|
3
|
+
# on 2021-04-26 10:37:31 UTC using RuboCop version 1.13.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 18
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
16
|
+
# IgnoredMethods: refine
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Max: 57
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Max: 12
|
24
|
+
|
9
25
|
# Offense count: 1
|
10
26
|
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
11
27
|
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
@@ -14,8 +30,19 @@ Naming/FileName:
|
|
14
30
|
- 'lib/jekyll-sanelist.rb'
|
15
31
|
|
16
32
|
# Offense count: 1
|
17
|
-
#
|
18
|
-
|
33
|
+
# Cop supports --auto-correct.
|
34
|
+
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
|
35
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
|
36
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
37
|
+
# FunctionalMethods: let, let!, subject, watch
|
38
|
+
# IgnoredMethods: lambda, proc, it
|
39
|
+
Style/BlockDelimiters:
|
19
40
|
Exclude:
|
20
|
-
- 'spec
|
21
|
-
|
41
|
+
- 'spec/jekyll/sanelist_spec.rb'
|
42
|
+
|
43
|
+
# Offense count: 3
|
44
|
+
# Cop supports --auto-correct.
|
45
|
+
# Configuration parameters: MinSize, WordRegex.
|
46
|
+
# SupportedStyles: percent, brackets
|
47
|
+
Style/WordArray:
|
48
|
+
EnforcedStyle: brackets
|
data/README.md
CHANGED
@@ -22,7 +22,38 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```html
|
26
|
+
<html>
|
27
|
+
{% assign asanelist = alist | sanelist %}
|
28
|
+
{% if asanelist.size == 0 %}
|
29
|
+
<!-- Do something for empty list -->
|
30
|
+
{% elsif asanelist.size == 1 %}
|
31
|
+
<!-- Do something for single-item list -->
|
32
|
+
{% elsif asanelist.size > 1 %}
|
33
|
+
<!-- Do something for multi-item list -->
|
34
|
+
{% endif %}
|
35
|
+
|
36
|
+
{% for element in asanelist %}
|
37
|
+
{% case element.type %{
|
38
|
+
{% when "item" %}
|
39
|
+
<!-- Do someting with element.data in the below block based on where it appears -->
|
40
|
+
{% if element.isFirst and element.isLast %}
|
41
|
+
{% elsif element.isFirst %}
|
42
|
+
{% elsif element.isLast %}
|
43
|
+
{% else %}
|
44
|
+
{% endif %}
|
45
|
+
|
46
|
+
{% when "delimiter" %}
|
47
|
+
<!-- Insert appropriate delimiter in the below block based on where it appears -->
|
48
|
+
{% if element.isFirst and element.isLast %}
|
49
|
+
{% elsif element.isFirst %}
|
50
|
+
{% elsif element.isLast %}
|
51
|
+
{% else %}
|
52
|
+
{% endif %}
|
53
|
+
{% endcase %}
|
54
|
+
{% endfor %}
|
55
|
+
</html>
|
56
|
+
```
|
26
57
|
|
27
58
|
## Development
|
28
59
|
|
data/jekyll-sanelist.gemspec
CHANGED
@@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'liquid', '~> 5.0'
|
29
29
|
spec.add_development_dependency 'rake', '~> 13.0'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.10'
|
31
|
+
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.2'
|
31
32
|
spec.add_development_dependency 'rubocop', '~> 1.13'
|
32
33
|
end
|
data/lib/jekyll-sanelist.rb
CHANGED
@@ -4,7 +4,9 @@ require 'jekyll-sanelist'
|
|
4
4
|
|
5
5
|
module Jekyll
|
6
6
|
##
|
7
|
-
#
|
7
|
+
# Sanelist plugin contains the sanelist filter
|
8
|
+
# The filter is used to produce a list consisting of prefix, items, delimiters and suffix
|
9
|
+
# While iterating you can generate each item appropriately
|
8
10
|
module Sanelist
|
9
11
|
end
|
10
12
|
end
|
data/lib/jekyll/sanelist.rb
CHANGED
@@ -1,10 +1,62 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'liquid'
|
3
4
|
require_relative 'sanelist/version'
|
4
5
|
|
5
6
|
module Jekyll
|
6
7
|
module Sanelist
|
7
|
-
|
8
|
-
#
|
8
|
+
##
|
9
|
+
# Module containg sanelist filters
|
10
|
+
module SanelistFilter
|
11
|
+
ITEM = 'item'
|
12
|
+
DELIMITER = 'delimiter'
|
13
|
+
|
14
|
+
##
|
15
|
+
# Takes a regular list and outputs a sanelist
|
16
|
+
# @param [Array] input The input list which needs to be converted into a sanelist
|
17
|
+
# @return [Array] A list of sane objects of items separated by delimiters
|
18
|
+
def sanelist(input)
|
19
|
+
raise ArgumentError, 'Input to filter sanelist is not an Array' unless input.is_a?(Array)
|
20
|
+
|
21
|
+
output = []
|
22
|
+
|
23
|
+
input.each_with_index do |value, index|
|
24
|
+
output << get_item(value, index, input.size)
|
25
|
+
|
26
|
+
output << get_delimiter(index, input.size) if index != (input.size - 1)
|
27
|
+
end
|
28
|
+
|
29
|
+
output
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_item(data, index, input_size)
|
33
|
+
unless (index >= 0) && (input_size >= 1) && (index < input_size)
|
34
|
+
raise ArgumentError, 'Inputs index or input_size are invalid'
|
35
|
+
end
|
36
|
+
|
37
|
+
{
|
38
|
+
'data' => data,
|
39
|
+
'isFirst' => (index == 0),
|
40
|
+
'isLast' => (index == (input_size - 1)),
|
41
|
+
'type' => ITEM
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_delimiter(index, input_size)
|
46
|
+
unless (index >= 0) && (input_size >= 2) && (index < (input_size - 1))
|
47
|
+
raise ArgumentError, 'Inputs index or input_size are invalid'
|
48
|
+
end
|
49
|
+
|
50
|
+
{
|
51
|
+
'isFirst' => (index == 0),
|
52
|
+
'isLast' => (index == (input_size - 2)),
|
53
|
+
'type' => DELIMITER
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
private :get_item, :get_delimiter
|
58
|
+
end
|
9
59
|
end
|
10
60
|
end
|
61
|
+
|
62
|
+
Liquid::Template.register_filter(Jekyll::Sanelist::SanelistFilter)
|
@@ -1,11 +1,66 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe Jekyll::Sanelist do
|
4
|
-
|
5
|
-
|
3
|
+
RSpec.describe Jekyll::Sanelist::SanelistFilter do
|
4
|
+
include Jekyll::Sanelist::SanelistFilter
|
5
|
+
|
6
|
+
it "throws exception when input isn\'t array" do
|
7
|
+
expect {
|
8
|
+
sanelist('Not an array')
|
9
|
+
}.to raise_error(ArgumentError, 'Input to filter sanelist is not an Array')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'gives empty list for an empty list' do
|
13
|
+
input = []
|
14
|
+
output = sanelist(input)
|
15
|
+
|
16
|
+
expect(output).to have(0).things
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'gives one item for a sinleton list' do
|
20
|
+
input = ['foo']
|
21
|
+
output = sanelist(input)
|
22
|
+
|
23
|
+
expect(output).to have(1).things
|
24
|
+
|
25
|
+
expect(output[0]).to eq item(input[0], true, true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'gives two items spearated by a delimiter for a list of two item' do
|
29
|
+
input = ['foo', 'bar']
|
30
|
+
output = sanelist(input)
|
31
|
+
|
32
|
+
expect(output).to have(3).things
|
33
|
+
|
34
|
+
expect(output[0]).to eq item(input[0], true, false)
|
35
|
+
expect(output[1]).to eq delimiter(true, true)
|
36
|
+
expect(output[2]).to eq item(input[1], false, true)
|
6
37
|
end
|
7
38
|
|
8
|
-
it '
|
9
|
-
|
39
|
+
it 'gives three items spearated by two delimiters for a list of three item' do
|
40
|
+
input = ['foo', 'and', 'bar']
|
41
|
+
output = sanelist(input)
|
42
|
+
|
43
|
+
expect(output).to have(5).things
|
44
|
+
|
45
|
+
expect(output[0]).to eq item(input[0], true, false)
|
46
|
+
expect(output[1]).to eq delimiter(true, false)
|
47
|
+
expect(output[2]).to eq item(input[1], false, false)
|
48
|
+
expect(output[3]).to eq delimiter(false, true)
|
49
|
+
expect(output[4]).to eq item(input[2], false, true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'gives four items spearated by three delimiters for a list of four item' do
|
53
|
+
input = ['foo', 'and', 'bar', 'list']
|
54
|
+
output = sanelist(input)
|
55
|
+
|
56
|
+
expect(output).to have(7).things
|
57
|
+
|
58
|
+
expect(output[0]).to eq item(input[0], true, false)
|
59
|
+
expect(output[1]).to eq delimiter(true, false)
|
60
|
+
expect(output[2]).to eq item(input[1], false, false)
|
61
|
+
expect(output[3]).to eq delimiter(false, false)
|
62
|
+
expect(output[4]).to eq item(input[2], false, false)
|
63
|
+
expect(output[5]).to eq delimiter(false, true)
|
64
|
+
expect(output[6]).to eq item(input[3], false, true)
|
10
65
|
end
|
11
66
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SanelistHelpers
|
4
|
+
def item(data, first, last)
|
5
|
+
{
|
6
|
+
'data' => data,
|
7
|
+
'isFirst' => first,
|
8
|
+
'isLast' => last,
|
9
|
+
'type' => 'item'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def delimiter(first, last)
|
14
|
+
{
|
15
|
+
'isFirst' => first,
|
16
|
+
'isLast' => last,
|
17
|
+
'type' => 'delimiter'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'jekyll/sanelist'
|
4
|
+
require 'rspec/collection_matchers'
|
5
|
+
require_relative 'sanelist_helpers'
|
4
6
|
|
5
7
|
RSpec.configure do |config|
|
6
8
|
# Enable flags like --only-failures and --next-failure
|
@@ -9,6 +11,8 @@ RSpec.configure do |config|
|
|
9
11
|
# Disable RSpec exposing methods globally on `Module` and `main`
|
10
12
|
config.disable_monkey_patching!
|
11
13
|
|
14
|
+
include SanelistHelpers
|
15
|
+
|
12
16
|
config.expect_with :rspec do |c|
|
13
17
|
c.syntax = :expect
|
14
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-sanelist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sampath Sukesh Ravolaparthi
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-collection_matchers
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,7 +118,9 @@ files:
|
|
104
118
|
- lib/jekyll/sanelist/version.rb
|
105
119
|
- script/bootstrap
|
106
120
|
- script/fmt
|
121
|
+
- spec/jekyll/sanelist/version_spec.rb
|
107
122
|
- spec/jekyll/sanelist_spec.rb
|
123
|
+
- spec/sanelist_helpers.rb
|
108
124
|
- spec/spec_helper.rb
|
109
125
|
homepage: https://rsampaths16.github.io/jekyll-sanelist
|
110
126
|
licenses:
|
@@ -133,5 +149,7 @@ signing_key:
|
|
133
149
|
specification_version: 4
|
134
150
|
summary: Human oriented lists filter for Jekyll
|
135
151
|
test_files:
|
152
|
+
- spec/jekyll/sanelist/version_spec.rb
|
136
153
|
- spec/jekyll/sanelist_spec.rb
|
154
|
+
- spec/sanelist_helpers.rb
|
137
155
|
- spec/spec_helper.rb
|