jekyll_all_collections 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +40 -21
- data/CHANGELOG.md +7 -0
- data/README.md +52 -36
- data/jekyll_all_collections.gemspec +3 -3
- data/lib/all_collections_hooks.rb +12 -12
- data/lib/all_collections_tag.rb +39 -26
- data/lib/jekyll_all_collections/version.rb +1 -1
- data/spec/{lambda_sort_spec.rb → all_collections_tag_sort_spec.rb} +26 -32
- data/spec/date_sort_spec.rb +10 -10
- metadata +9 -10
- data/spec/status_persistence.txt +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7f7fa2e1b1ca3dc3ee52ef85f6b1f55db8710bca3fed39386469d686bd6341f
|
4
|
+
data.tar.gz: 3827c3d5b908b972fb2d4efb3b6c0f703d84fbd710d5887485f1f6e0810718f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fed15d67819f65a6711f9b4a3550fd4d309184f06e774cffe4ba9e9a4673f04e422e785a62c17c4151f12e1e98685f8317bec2e02542cfebac87ec94c9557a0c
|
7
|
+
data.tar.gz: 750f6e7f00532dc66bd992269c6cc0651deaebf2e10b385883c29010e4032a52ea7a925de12d55ecc064cdc2c604c919d6eb1a0807a641a31e7055f99a588048
|
data/.rubocop.yml
CHANGED
@@ -1,52 +1,71 @@
|
|
1
|
+
require:
|
2
|
+
# - rubocop-jekyll
|
3
|
+
- rubocop-md
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
7
|
+
|
1
8
|
AllCops:
|
2
9
|
Exclude:
|
10
|
+
- exe/**/*
|
3
11
|
- vendor/**/*
|
4
12
|
- Gemfile*
|
5
|
-
- '*.gemspec'
|
6
13
|
NewCops: enable
|
7
14
|
TargetRubyVersion: 2.6
|
8
15
|
|
9
|
-
|
10
|
-
|
16
|
+
Gemspec/DeprecatedAttributeAssignment:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Gemspec/RequireMFA:
|
20
|
+
Enabled: false
|
11
21
|
|
12
22
|
Layout/HashAlignment:
|
23
|
+
EnforcedColonStyle: table
|
13
24
|
EnforcedHashRocketStyle: table
|
14
25
|
|
15
26
|
Layout/LineLength:
|
16
27
|
Max: 150
|
17
28
|
|
29
|
+
Metrics/AbcSize:
|
30
|
+
Max: 45
|
31
|
+
|
18
32
|
Metrics/BlockLength:
|
19
33
|
Exclude:
|
20
|
-
-
|
21
|
-
Max:
|
22
|
-
|
23
|
-
Metrics/AbcSize:
|
24
|
-
Max: 42
|
34
|
+
- jekyll_all_collections.gemspec
|
35
|
+
Max: 30
|
25
36
|
|
26
37
|
Metrics/CyclomaticComplexity:
|
27
38
|
Max: 25
|
28
39
|
|
29
40
|
Metrics/MethodLength:
|
30
|
-
Max:
|
31
|
-
|
32
|
-
Metrics/ModuleLength:
|
33
|
-
Enabled: false
|
41
|
+
Max: 30
|
34
42
|
|
35
43
|
Metrics/PerceivedComplexity:
|
36
|
-
Max:
|
44
|
+
Max: 25
|
37
45
|
|
38
|
-
|
39
|
-
|
46
|
+
Naming/FileName:
|
47
|
+
Exclude:
|
48
|
+
- Rakefile
|
40
49
|
|
41
|
-
|
50
|
+
RSpec/ExampleLength:
|
51
|
+
Max: 30
|
52
|
+
|
53
|
+
RSpec/FilePath:
|
42
54
|
Enabled: false
|
55
|
+
IgnoreMethods: true
|
56
|
+
SpecSuffixOnly: true
|
43
57
|
|
44
|
-
|
58
|
+
RSpec/IndexedLet:
|
45
59
|
Enabled: false
|
46
60
|
|
47
|
-
|
48
|
-
|
49
|
-
- spec/**/*
|
61
|
+
RSpec/MultipleExpectations:
|
62
|
+
Max: 15
|
50
63
|
|
51
|
-
Style/
|
64
|
+
Style/Documentation:
|
52
65
|
Enabled: false
|
66
|
+
|
67
|
+
Style/FrozenStringLiteralComment:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Style/TrailingCommaInHashLiteral:
|
71
|
+
EnforcedStyleForMultiline: comma
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.3.3 / 2023-05-22
|
2
|
+
* Corrected key presence checks in APage.initialize
|
3
|
+
* Using `warn_short_trace` from `jekyll_plugin_support` for non-fatal errors.
|
4
|
+
|
5
|
+
## 0.3.2 / 2023-04-05
|
6
|
+
* Modified dependency `'jekyll_plugin_support', '>= 0.5.0'`
|
7
|
+
|
1
8
|
## 0.3.1 / 2023-03-16
|
2
9
|
* Reduced the verbosity of the `@logger` message
|
3
10
|
|
data/README.md
CHANGED
@@ -15,25 +15,39 @@ The collection consists of an array of objects with the following properties:
|
|
15
15
|
Pages that are not in any collection are not included.
|
16
16
|
|
17
17
|
|
18
|
+
## Installation
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
group :jekyll_plugins do
|
23
|
+
gem 'jekyll_all_collections'
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
|
18
32
|
## Requirements
|
19
33
|
All the pages in the Jekyll website must have an implicit date (for example, all posts are assigned this property by Jekyll),
|
20
34
|
or an explicit `date` set in front matter, like this:
|
21
35
|
```
|
22
36
|
---
|
23
|
-
date
|
37
|
+
date: 2022-01-01
|
24
38
|
---
|
25
39
|
```
|
26
40
|
If a front matter variable called `last_modified` or `last_modified_at` exists, its value will be converted to a Ruby `Date`:
|
27
41
|
```
|
28
42
|
---
|
29
|
-
last_modified
|
43
|
+
last_modified: 2023-01-01
|
30
44
|
---
|
31
45
|
```
|
32
46
|
|
33
47
|
Or:
|
34
48
|
```
|
35
49
|
---
|
36
|
-
last_modified_at
|
50
|
+
last_modified_at: 2023-01-01
|
37
51
|
---
|
38
52
|
```
|
39
53
|
|
@@ -79,7 +93,12 @@ exclude_from_all: true
|
|
79
93
|
#### General Form
|
80
94
|
The general form of the Jekyll tag is:
|
81
95
|
```
|
82
|
-
{% all_collections
|
96
|
+
{% all_collections
|
97
|
+
date_column='date|last_modified'
|
98
|
+
heading='All Posts'
|
99
|
+
id='asdf'
|
100
|
+
sort_by='SORT_KEYS'
|
101
|
+
%}
|
83
102
|
```
|
84
103
|
|
85
104
|
#### `date_column` Attribute
|
@@ -89,19 +108,6 @@ or `last_modified`.
|
|
89
108
|
The default value for the `date_column` attribute is `date`.
|
90
109
|
|
91
110
|
|
92
|
-
#### `id` Attribute
|
93
|
-
If your Jekyll layout employs [`jekyll-toc`](https://github.com/allejo/jekyll-toc), then `id` attributes are important.
|
94
|
-
The `jekyll-toc` include checks for `id` attributes in `h2` ... `h6` tags, and if found, and if the attribute value is enclosed in double quotes (`id="my_id"`, not `id='my_id'`),
|
95
|
-
then the heading is included in the table of contents.
|
96
|
-
|
97
|
-
To suppress an `id` from being generated,
|
98
|
-
and thereby preventing the heading from appearing in the automatically generated table of contents from `jekyll-toc`,
|
99
|
-
specify an empty string for the value of `id`, like this:
|
100
|
-
```
|
101
|
-
{% all_collections id='' %}
|
102
|
-
```
|
103
|
-
|
104
|
-
|
105
111
|
#### `heading` Attribute
|
106
112
|
If no `heading` attribute is specified, a heading will automatically be generated, which contains the `sort_by` values, for example:
|
107
113
|
```
|
@@ -109,7 +115,7 @@ If no `heading` attribute is specified, a heading will automatically be generate
|
|
109
115
|
```
|
110
116
|
Generates a heading like:
|
111
117
|
```
|
112
|
-
<h2 id="abcdef">All Posts Sorted By
|
118
|
+
<h2 id="abcdef">All Posts Sorted By last_modified</h2>
|
113
119
|
```
|
114
120
|
|
115
121
|
To suppress both a `h2` heading (and the enclosed `id`) from being generated,
|
@@ -119,13 +125,39 @@ specify an empty string for the value of `heading`:
|
|
119
125
|
```
|
120
126
|
|
121
127
|
|
128
|
+
#### `id` Attribute
|
129
|
+
If your Jekyll layout employs [`jekyll-toc`](https://github.com/allejo/jekyll-toc), then `id` attributes are important.
|
130
|
+
The `jekyll-toc` include checks for `id` attributes in `h2` ... `h6` tags, and if found, and if the attribute value is enclosed in double quotes (`id="my_id"`, not `id='my_id'`),
|
131
|
+
then the heading is included in the table of contents.
|
132
|
+
|
133
|
+
To suppress an `id` from being generated,
|
134
|
+
and thereby preventing the heading from appearing in the automatically generated table of contents from `jekyll-toc`,
|
135
|
+
specify an empty string for the value of `id`, like this:
|
136
|
+
```
|
137
|
+
{% all_collections id='' %}
|
138
|
+
```
|
139
|
+
|
140
|
+
|
122
141
|
#### `SORT_KEYS` Values
|
123
142
|
`SORT_KEYS` specifies how to sort the collection.
|
124
143
|
Values can include one or more of the following attributes:
|
125
|
-
`date`, `destination`, `draft`, `label`, `last_modified`, `path`, `relative_path`, `title`, `type`, and `url`.
|
144
|
+
`date`, `destination`, `draft`, `label`, `last_modified`, `last_modified_at`, `path`, `relative_path`, `title`, `type`, and `url`.
|
126
145
|
Ascending sorts are the default, however a descending sort can be achieved by prepending `-` before an attribute.
|
127
146
|
|
128
|
-
To specify more than one sort key, provide
|
147
|
+
To specify more than one sort key, provide a comma-delimited string of values.
|
148
|
+
Included spaces are ignored.
|
149
|
+
For example, specify the primary sort key as <code>draft</code>,
|
150
|
+
the secondary sort key as <code>last_modified</code>,
|
151
|
+
and the tertiary key as <code>label</code>:
|
152
|
+
|
153
|
+
```
|
154
|
+
{% all_collections
|
155
|
+
date_column='last_modified'
|
156
|
+
heading='All Posts'
|
157
|
+
id='asdf'
|
158
|
+
sort_by='draft, last_modified, label'
|
159
|
+
%}
|
160
|
+
```
|
129
161
|
|
130
162
|
|
131
163
|
#### Usage Examples
|
@@ -237,22 +269,6 @@ More information is available on Mike Slinn's website about
|
|
237
269
|
[Jekyll plugins](https://www.mslinn.com/blog/index.html#Jekyll).
|
238
270
|
|
239
271
|
|
240
|
-
## Installation
|
241
|
-
This has already been done for the demo;
|
242
|
-
these instructions are for incorporating the plugin(s) into other Jekyll websites.
|
243
|
-
Add this line to your application's Gemfile:
|
244
|
-
|
245
|
-
```ruby
|
246
|
-
group :jekyll_plugins do
|
247
|
-
gem 'jekyll_all_collections'
|
248
|
-
end
|
249
|
-
```
|
250
|
-
|
251
|
-
And then execute:
|
252
|
-
|
253
|
-
$ bundle install
|
254
|
-
|
255
|
-
|
256
272
|
## Development
|
257
273
|
|
258
274
|
After checking out the repo, run `bin/setup` to install dependencies.
|
@@ -12,9 +12,9 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.executables = []
|
13
13
|
|
14
14
|
# Specify which files should be added to the gem when it is released.
|
15
|
-
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile',
|
15
|
+
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
16
16
|
|
17
|
-
spec.homepage = 'https://www.mslinn.com/
|
17
|
+
spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html'
|
18
18
|
spec.license = 'MIT'
|
19
19
|
spec.metadata = {
|
20
20
|
'allowed_push_host' => 'https://rubygems.org',
|
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.add_dependency 'jekyll', '>= 3.5.0'
|
33
33
|
spec.add_dependency 'jekyll_draft', '~> 1.1.1'
|
34
|
-
spec.add_dependency 'jekyll_plugin_support', '
|
34
|
+
spec.add_dependency 'jekyll_plugin_support', '>= 0.7.0'
|
35
35
|
end
|
@@ -66,22 +66,22 @@ module AllCollectionsHooks
|
|
66
66
|
end
|
67
67
|
|
68
68
|
class APage
|
69
|
-
attr_reader :content, :data, :date, :description, :destination, :draft, :excerpt, :ext,
|
69
|
+
attr_reader :content, :data, :date, :description, :destination, :draft, :excerpt, :ext,
|
70
70
|
:label, :last_modified, :layout, :path, :relative_path, :tags, :title, :type, :url
|
71
71
|
|
72
72
|
# Verify each property exists before accessing it; this helps write tests
|
73
73
|
def initialize(obj) # rubocop:disable Metrics/AbcSize
|
74
74
|
@data = obj.data if obj.respond_to? :data
|
75
75
|
|
76
|
-
@categories = @data['categories'] if
|
76
|
+
@categories = @data['categories'] if @data.key? 'categories'
|
77
77
|
@content = obj.content if obj.respond_to? :content
|
78
|
-
@date = @data['date'].to_date if
|
79
|
-
@description = @data['description'] if
|
78
|
+
@date = (@data['date'].to_date if @data&.key?('date')) || Date.today
|
79
|
+
@description = @data['description'] if @data.key? 'description'
|
80
80
|
@destination = obj.destination('') if obj.respond_to? :destination # TODO: What _config.yml setting should be passed to destination()?
|
81
81
|
@draft = Jekyll::Draft.draft?(obj)
|
82
|
-
@excerpt = @data['excerpt'] if
|
83
|
-
@ext = @data['ext'] if
|
84
|
-
@label = obj.collection.label if obj.respond_to? :label
|
82
|
+
@excerpt = @data['excerpt'] if @data.key? 'excerpt'
|
83
|
+
@ext = @data['ext'] if @data.key? 'ext'
|
84
|
+
@label = obj.collection.label if obj&.collection.respond_to? :label
|
85
85
|
@last_modified = @data['last_modified'] || @data['last_modified_at'] || @date
|
86
86
|
@last_modified_field = case @data
|
87
87
|
when @data.key?('last_modified')
|
@@ -89,11 +89,11 @@ module AllCollectionsHooks
|
|
89
89
|
when @data.key?('last_modified_at')
|
90
90
|
'last_modified_at'
|
91
91
|
end
|
92
|
-
@layout = @data['layout'] if
|
92
|
+
@layout = @data['layout'] if @data.key? 'layout'
|
93
93
|
@path = obj.path if obj.respond_to? :path
|
94
94
|
@relative_path = obj.relative_path if obj.respond_to? :relative_path
|
95
|
-
@tags = @data['tags'] if
|
96
|
-
@title = @data['title'] if
|
95
|
+
@tags = @data['tags'] if @data.key? 'tags'
|
96
|
+
@title = @data['title'] if @data.key? 'title'
|
97
97
|
@type = obj.type if obj.respond_to? :type
|
98
98
|
@url = obj.url
|
99
99
|
end
|
@@ -105,9 +105,9 @@ module AllCollectionsHooks
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
PluginMetaLogger.instance.logger.info
|
108
|
+
PluginMetaLogger.instance.logger.info do
|
109
109
|
"Loaded AllCollectionsHooks v#{JekyllAllCollectionsVersion::VERSION} :site, :pre_render, :normal hook plugin."
|
110
|
-
|
110
|
+
end
|
111
111
|
end
|
112
112
|
|
113
113
|
Liquid::Template.register_filter(AllCollectionsHooks)
|
data/lib/all_collections_tag.rb
CHANGED
@@ -18,6 +18,7 @@ end
|
|
18
18
|
module AllCollectionsTag
|
19
19
|
PLUGIN_NAME = 'all_collections'.freeze
|
20
20
|
CRITERIA = %w[date destination draft label last_modified last_modified_at path relative_path title type url].freeze
|
21
|
+
DRAFT_HTML = '<i class="jekyll_draft">Draft</i>'.freeze
|
21
22
|
|
22
23
|
class AllCollectionsTag < JekyllSupport::JekyllTag
|
23
24
|
include JekyllAllCollectionsVersion
|
@@ -28,18 +29,22 @@ module AllCollectionsTag
|
|
28
29
|
AllCollectionsHooks.compute(@site) unless @site.class.method_defined? :all_collections
|
29
30
|
|
30
31
|
@date_column = @helper.parameter_specified?('date_column') || 'date'
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
unless %w[date last_modified].include?(@date_column)
|
33
|
+
# TODO: should this just issue a warning and return instead of dieing?
|
34
|
+
abort "Error: the date_column attribute must either have value 'date' or 'last_modified', " \
|
35
|
+
"but '#{@date_column}' was specified"
|
36
|
+
end
|
34
37
|
@id = @helper.parameter_specified?('id') || SecureRandom.hex(10)
|
35
|
-
sort_by_param = @helper.parameter_specified?
|
38
|
+
sort_by_param = @helper.parameter_specified? 'sort_by'
|
36
39
|
sort_by = (sort_by_param&.gsub(' ', '')&.split(',') if sort_by_param != false) || ['-date']
|
37
40
|
@heading = @helper.parameter_specified?('heading') || self.class.default_head(sort_by)
|
38
41
|
sort_lambda_string = self.class.create_lambda_string(sort_by)
|
39
|
-
@logger.debug
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
@logger.debug do
|
43
|
+
"#{@page['path']} sort_by_param=#{sort_by_param} " \
|
44
|
+
"sort_lambda_string = #{sort_lambda_string}\n"
|
45
|
+
end
|
46
|
+
sort_lambda = self.class.evaluate sort_lambda_string
|
47
|
+
generate_output sort_lambda
|
43
48
|
end
|
44
49
|
|
45
50
|
def self.default_head(sort_by)
|
@@ -57,9 +62,9 @@ module AllCollectionsTag
|
|
57
62
|
criteria_lhs_array = []
|
58
63
|
criteria_rhs_array = []
|
59
64
|
verify_sort_by_type(criteria).each do |c|
|
60
|
-
descending_sort = c.start_with?
|
65
|
+
descending_sort = c.start_with? '-'
|
61
66
|
c.delete_prefix! '-'
|
62
|
-
abort("Error: '#{c}' is not a valid sort field. Valid field names are: #{CRITERIA.join
|
67
|
+
abort("Error: '#{c}' is not a valid sort field. Valid field names are: #{CRITERIA.join ', '}") \
|
63
68
|
unless CRITERIA.include?(c)
|
64
69
|
criteria_lhs_array << (descending_sort ? "b.#{c}" : "a.#{c}")
|
65
70
|
criteria_rhs_array << (descending_sort ? "a.#{c}" : "b.#{c}")
|
@@ -92,30 +97,38 @@ module AllCollectionsTag
|
|
92
97
|
|
93
98
|
private
|
94
99
|
|
100
|
+
def last_modified_value(post)
|
101
|
+
@logger.debug { " post.last_modified='#{post.last_modified}'; post.last_modified_at='#{post.last_modified_at}'; @date_column='#{@date_column}'" }
|
102
|
+
last_modified = if @date_column == 'last_modified' && post.respond_to?(:last_modified)
|
103
|
+
post.last_modified
|
104
|
+
elsif post.respond_to? :last_modified_at
|
105
|
+
post.last_modified_at
|
106
|
+
else
|
107
|
+
post.date
|
108
|
+
end
|
109
|
+
last_modified ||= post.date || Date.today
|
110
|
+
last_modified
|
111
|
+
end
|
112
|
+
|
95
113
|
def generate_output(sort_lambda)
|
96
|
-
id = @id.to_s.empty? ? '' : " id='#{@id}'"
|
97
|
-
heading = @heading.to_s.empty? ? '' : "<h2#{id}>#{@heading}</h2>"
|
98
|
-
@site.all_collections.each do |post|
|
99
|
-
# @logger.debug "#{post.relative_path}: last_modified=#{post.last_modified}(#{post.last_modified.class}) date=#{post.date}(#{post.date.class})"
|
100
|
-
@logger.debug "Error: #{post.relative_path} has no value for last_modified" if post.last_modified.to_s.empty?
|
101
|
-
end
|
114
|
+
id = @id.to_s.strip.empty? ? '' : " id='#{@id}'"
|
115
|
+
heading = @heading.strip.to_s.empty? ? '' : "<h2#{id}>#{@heading}</h2>"
|
102
116
|
collection = @site.all_collections.sort(&sort_lambda)
|
103
117
|
<<~END_TEXT
|
104
118
|
#{heading}
|
105
119
|
<div class="posts">
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
120
|
+
#{(collection.map do |post|
|
121
|
+
last_modified = last_modified_value post
|
122
|
+
date = last_modified.strftime '%Y-%m-%d'
|
123
|
+
draft = post.draft ? DRAFT_HTML : ''
|
124
|
+
href = "<a href='#{post.url}'>#{post.title}</a>"
|
125
|
+
@logger.debug { " date='#{date}' #{post.title}\n" }
|
126
|
+
" <span>#{date}</span><span>#{href}#{draft}</span>"
|
127
|
+
end).join "\n"}
|
114
128
|
</div>
|
115
129
|
END_TEXT
|
116
130
|
rescue ArgumentError => e
|
117
|
-
|
118
|
-
puts e.backtrace.join("\n")
|
131
|
+
warn_short_trace e
|
119
132
|
end
|
120
133
|
|
121
134
|
JekyllPluginHelper.register(self, PLUGIN_NAME)
|
@@ -20,95 +20,89 @@ def show(lambda_string, result, expected)
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# See https://stackoverflow.com/a/75388137/553865
|
23
|
-
RSpec.describe(AllCollectionsTag) do
|
23
|
+
RSpec.describe(AllCollectionsTag::AllCollectionsTag) do
|
24
24
|
let(:o1) { APageStub.new('2020-01-01', '2020-01-01', 'a_A') }
|
25
25
|
let(:o2) { APageStub.new('2021-01-01', '2020-01-01', 'b_A') }
|
26
26
|
let(:o3) { APageStub.new('2021-01-01', '2023-01-01', 'b_B') }
|
27
27
|
let(:o4) { APageStub.new('2022-01-01', '2023-01-01', 'c_B') }
|
28
28
|
let(:objs) { [o1, o2, o3, o4] }
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'defines sort_by lambda with last_modified' do
|
31
31
|
sort_lambda = ->(a, b) { [a.last_modified] <=> [b.last_modified] }
|
32
32
|
result = objs.sort(&sort_lambda)
|
33
33
|
expect(result).to eq([o1, o2, o3, o4])
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
sort_lambda = eval
|
36
|
+
it 'makes sort_by lambdas from stringified date' do
|
37
|
+
sort_lambda = eval '->(a, b) { a.last_modified <=> b.last_modified }',
|
38
38
|
NullBinding.new.min_binding, __FILE__, __LINE__ - 1
|
39
39
|
result = objs.sort(&sort_lambda)
|
40
40
|
expect(result).to eq([o1, o2, o3, o4])
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
sort_lambda = ->(a, b) { [a.last_modified] <=> [b.last_modified] }
|
45
|
-
result = objs.sort(&sort_lambda)
|
46
|
-
expect(result).to eq([o1, o2, o3, o4])
|
47
|
-
end
|
48
|
-
|
49
|
-
it "makes sort_by lambdas from stringified array of last_modified" do
|
50
|
-
sort_lambda = eval "->(a, b) { [a.last_modified] <=> [b.last_modified] }",
|
43
|
+
it 'makes sort_by lambdas from stringified array of last_modified' do
|
44
|
+
sort_lambda = eval '->(a, b) { [a.last_modified] <=> [b.last_modified] }',
|
51
45
|
NullBinding.new.min_binding, __FILE__, __LINE__ - 1
|
52
46
|
result = objs.sort(&sort_lambda)
|
53
47
|
expect(result).to eq([o1, o2, o3, o4])
|
54
48
|
end
|
55
49
|
|
56
|
-
it
|
57
|
-
sort_lambda = eval
|
50
|
+
it 'makes sort_by lambdas with descending keys from stringified array of last_modified' do
|
51
|
+
sort_lambda = eval '->(a, b) { [b.last_modified] <=> [a.last_modified] }',
|
58
52
|
NullBinding.new.min_binding, __FILE__, __LINE__ - 1
|
59
53
|
result = objs.sort(&sort_lambda)
|
60
54
|
expected = [o3, o4, o1, o2]
|
61
55
|
expect(result).to eq(expected)
|
62
56
|
end
|
63
57
|
|
64
|
-
it
|
65
|
-
lambda_string =
|
66
|
-
sort_lambda =
|
58
|
+
it 'create_lambda with 1 date key, descending' do
|
59
|
+
lambda_string = described_class.create_lambda_string('-last_modified')
|
60
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
67
61
|
result = objs.sort(&sort_lambda)
|
68
62
|
expected = [o3, o4, o1, o2]
|
69
63
|
# show(lambda_string, result, expected)
|
70
64
|
expect(result).to eq(expected)
|
71
65
|
end
|
72
66
|
|
73
|
-
it
|
74
|
-
lambda_string =
|
75
|
-
sort_lambda =
|
67
|
+
it 'create_lambda with 1 date key, ascending' do
|
68
|
+
lambda_string = described_class.create_lambda_string('date')
|
69
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
76
70
|
result = objs.sort(&sort_lambda)
|
77
71
|
expected = [o1, o2, o3, o4]
|
78
72
|
# show(lambda_string, result, expected)
|
79
73
|
expect(result).to eq(expected)
|
80
74
|
end
|
81
75
|
|
82
|
-
it
|
83
|
-
lambda_string =
|
84
|
-
sort_lambda =
|
76
|
+
it 'create_lambda with 2 date keys, both ascending' do
|
77
|
+
lambda_string = described_class.create_lambda_string(%w[date last_modified])
|
78
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
85
79
|
result = objs.sort(&sort_lambda)
|
86
80
|
expected = [o1, o2, o3, o4]
|
87
81
|
# show(lambda_string, result, expected)
|
88
82
|
expect(result).to eq(expected)
|
89
83
|
end
|
90
84
|
|
91
|
-
it
|
92
|
-
lambda_string =
|
93
|
-
sort_lambda =
|
85
|
+
it 'create_lambda with 2 date keys, both descending' do
|
86
|
+
lambda_string = described_class.create_lambda_string(['-date', '-last_modified'])
|
87
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
94
88
|
result = objs.sort(&sort_lambda)
|
95
89
|
expected = [o4, o3, o2, o1]
|
96
90
|
# show(lambda_string, result, expected)
|
97
91
|
expect(result).to eq(expected)
|
98
92
|
end
|
99
93
|
|
100
|
-
it
|
101
|
-
lambda_string =
|
102
|
-
sort_lambda =
|
94
|
+
it 'create_lambda with 2 date keys, first descending and second ascending' do
|
95
|
+
lambda_string = described_class.create_lambda_string(['-date', 'last_modified'])
|
96
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
103
97
|
result = objs.sort(&sort_lambda)
|
104
98
|
expected = [o4, o2, o3, o1]
|
105
99
|
# show(lambda_string, result, expected)
|
106
100
|
expect(result).to eq(expected)
|
107
101
|
end
|
108
102
|
|
109
|
-
it
|
110
|
-
lambda_string =
|
111
|
-
sort_lambda =
|
103
|
+
it 'create_lambda with 2 date keys, first ascending and second descending' do
|
104
|
+
lambda_string = described_class.create_lambda_string(['date', '-last_modified'])
|
105
|
+
sort_lambda = described_class.evaluate(lambda_string)
|
112
106
|
result = objs.sort(&sort_lambda)
|
113
107
|
expected = [o1, o3, o2, o4]
|
114
108
|
# show(lambda_string, result, expected)
|
data/spec/date_sort_spec.rb
CHANGED
@@ -20,61 +20,61 @@ RSpec.describe(Obj) do # rubocop:disable Metrics/BlockLength
|
|
20
20
|
let(:objs) { [o1, o2, o3, o4] }
|
21
21
|
|
22
22
|
# See https://ruby-doc.org/3.2.0/Comparable.html
|
23
|
-
it
|
23
|
+
it 'compares one key with ascending dates' do
|
24
24
|
expect([o1.last_modified] <=> [o2.last_modified]).to eq(-1)
|
25
25
|
expect([o2.last_modified] <=> [o3.last_modified]).to eq(0)
|
26
26
|
expect([o3.last_modified] <=> [o4.last_modified]).to eq(-1)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'compares two keys with ascending dates' do
|
30
30
|
expect([o1.last_modified, o1.date] <=> [o2.last_modified, o2.date]).to eq(-1)
|
31
31
|
expect([o2.last_modified, o2.date] <=> [o3.last_modified, o3.date]).to eq(-1)
|
32
32
|
expect([o3.last_modified, o3.date] <=> [o4.last_modified, o4.date]).to eq(-1)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'compares one key with descending dates' do
|
36
36
|
expect([o1.last_modified] <=> [o2.last_modified]).to eq(-1)
|
37
37
|
expect([o2.last_modified] <=> [o3.last_modified]).to eq(0)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'compares two keys with descending dates' do
|
41
41
|
expect([o2.last_modified, o2.date] <=> [o1.last_modified, o1.date]).to eq(1)
|
42
42
|
expect([o3.last_modified, o3.date] <=> [o2.last_modified, o2.date]).to eq(1)
|
43
43
|
expect([o4.last_modified, o4.date] <=> [o3.last_modified, o3.date]).to eq(1)
|
44
44
|
end
|
45
45
|
|
46
46
|
# See https://ruby-doc.org/3.2.0/Enumerable.html#method-i-sort
|
47
|
-
it
|
47
|
+
it 'sort with one key ascending' do
|
48
48
|
sort_lambda = ->(a, b) { [a.last_modified] <=> [b.last_modified] }
|
49
49
|
result = objs.sort(&sort_lambda)
|
50
50
|
expect(result).to eq([o1, o2, o3, o4])
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'sort with one key descending' do
|
54
54
|
sort_lambda = ->(a, b) { [b.last_modified] <=> [a.last_modified] }
|
55
55
|
result = objs.sort(&sort_lambda)
|
56
56
|
expect(result).to eq([o4, o2, o3, o1])
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'sort with two keys ascending' do
|
60
60
|
sort_lambda = ->(a, b) { [a.last_modified, a.date] <=> [b.last_modified, b.date] }
|
61
61
|
result = objs.sort(&sort_lambda)
|
62
62
|
expect(result).to eq([o1, o2, o3, o4])
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it 'sort with both keys descending' do
|
66
66
|
sort_lambda = ->(a, b) { [b.last_modified, b.date] <=> [a.last_modified, a.date] }
|
67
67
|
result = objs.sort(&sort_lambda)
|
68
68
|
expect(result).to eq([o4, o3, o2, o1])
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
71
|
+
it 'sort with last_modified descending and date ascending' do
|
72
72
|
sort_lambda = ->(a, b) { [b.last_modified, a.date] <=> [a.last_modified, b.date] }
|
73
73
|
result = objs.sort(&sort_lambda)
|
74
74
|
expect(result).to eq([o4, o2, o3, o1])
|
75
75
|
end
|
76
76
|
|
77
|
-
it
|
77
|
+
it 'sort with last_modified ascending and date descending' do
|
78
78
|
sort_lambda = ->(a, b) { [a.last_modified, b.date] <=> [b.last_modified, a.date] }
|
79
79
|
result = objs.sort(&sort_lambda)
|
80
80
|
expect(result).to eq([o1, o3, o2, o4])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_all_collections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: jekyll_plugin_support
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.7.0
|
55
55
|
description: 'Provides a collection of all collections in site.all_collections.
|
56
56
|
|
57
57
|
'
|
@@ -71,18 +71,17 @@ files:
|
|
71
71
|
- lib/all_collections_tag.rb
|
72
72
|
- lib/jekyll_all_collections.rb
|
73
73
|
- lib/jekyll_all_collections/version.rb
|
74
|
+
- spec/all_collections_tag_sort_spec.rb
|
74
75
|
- spec/date_sort_spec.rb
|
75
|
-
- spec/lambda_sort_spec.rb
|
76
76
|
- spec/spec_helper.rb
|
77
|
-
|
78
|
-
homepage: https://www.mslinn.com/blog/2020/12/30/jekyll-plugin-template-collection.html
|
77
|
+
homepage: https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html
|
79
78
|
licenses:
|
80
79
|
- MIT
|
81
80
|
metadata:
|
82
81
|
allowed_push_host: https://rubygems.org
|
83
82
|
bug_tracker_uri: https://github.com/mslinn/jekyll_all_collections/issues
|
84
83
|
changelog_uri: https://github.com/mslinn/jekyll_all_collections/CHANGELOG.md
|
85
|
-
homepage_uri: https://www.mslinn.com/
|
84
|
+
homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html
|
86
85
|
source_code_uri: https://github.com/mslinn/jekyll_all_collections
|
87
86
|
post_install_message:
|
88
87
|
rdoc_options: []
|
data/spec/status_persistence.txt
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
example_id | status | run_time |
|
2
|
-
-------------------------------- | ------ | --------------- |
|
3
|
-
./spec/date_sort_spec.rb[1:1] | passed | 0.00111 seconds |
|
4
|
-
./spec/date_sort_spec.rb[1:2] | passed | 0.00019 seconds |
|
5
|
-
./spec/date_sort_spec.rb[1:3] | passed | 0.00014 seconds |
|
6
|
-
./spec/date_sort_spec.rb[1:4] | passed | 0.00016 seconds |
|
7
|
-
./spec/date_sort_spec.rb[1:5] | passed | 0.00016 seconds |
|
8
|
-
./spec/date_sort_spec.rb[1:6] | passed | 0.00015 seconds |
|
9
|
-
./spec/date_sort_spec.rb[1:7] | passed | 0.00014 seconds |
|
10
|
-
./spec/date_sort_spec.rb[1:8] | passed | 0.00014 seconds |
|
11
|
-
./spec/date_sort_spec.rb[1:9] | passed | 0.00016 seconds |
|
12
|
-
./spec/date_sort_spec.rb[1:10] | passed | 0.00015 seconds |
|
13
|
-
./spec/lambda_sort_spec.rb[1:1] | passed | 0.00017 seconds |
|
14
|
-
./spec/lambda_sort_spec.rb[1:2] | passed | 0.00022 seconds |
|
15
|
-
./spec/lambda_sort_spec.rb[1:3] | passed | 0.00029 seconds |
|
16
|
-
./spec/lambda_sort_spec.rb[1:4] | passed | 0.0002 seconds |
|
17
|
-
./spec/lambda_sort_spec.rb[1:5] | passed | 0.00018 seconds |
|
18
|
-
./spec/lambda_sort_spec.rb[1:6] | passed | 0.0002 seconds |
|
19
|
-
./spec/lambda_sort_spec.rb[1:7] | passed | 0.00019 seconds |
|
20
|
-
./spec/lambda_sort_spec.rb[1:8] | passed | 0.00019 seconds |
|
21
|
-
./spec/lambda_sort_spec.rb[1:9] | passed | 0.00019 seconds |
|
22
|
-
./spec/lambda_sort_spec.rb[1:10] | passed | 0.00019 seconds |
|
23
|
-
./spec/lambda_sort_spec.rb[1:11] | passed | 0.00036 seconds |
|