jekyll_all_collections 0.3.6 → 0.4.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.
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ # Ruby's binary search is unsuitable because ordering requirements are not stable.
4
+ # the value to be searched for changes the required ordering
5
+
6
+ RSpec.describe(Array) do
7
+ before { skip('Never gonna give you up/Never gonna let you down') }
8
+
9
+ sorted_ints = [0, 4, 7, 10, 12]
10
+ sorted_strings = %w[aaa aab aac bbb bbc bbd ccc ccd cce].sort.reverse
11
+
12
+ it 'returns index of first int match' do
13
+ actual = sorted_ints.bsearch_index { |x| x >= 4 }
14
+ expect(actual).to eq(1)
15
+
16
+ actual = sorted_ints.bsearch_index { |x| x >= 6 }
17
+ expect(actual).to eq(2)
18
+
19
+ actual = sorted_ints.bsearch_index { |x| x >= -1 }
20
+ expect(actual).to eq(0)
21
+
22
+ actual = sorted_ints.bsearch_index { |x| x >= 100 }
23
+ expect(actual).to be_nil
24
+ end
25
+
26
+ # See https://stackoverflow.com/q/79333097/553865
27
+ it 'returns index of first string match' do
28
+ puts(sorted_strings.map { |x| x.start_with? 'a' })
29
+ index = sorted_strings.bsearch_index { |x| x.start_with? 'a' }
30
+ expect(sorted_strings[index]).to eq('aac')
31
+
32
+ index = sorted_strings.bsearch_index { |x| x.start_with? 'aa' }
33
+ expect(sorted_strings[index]).to eq('aac')
34
+
35
+ index = sorted_strings.bsearch_index { |x| x.start_with? 'aaa' }
36
+ expect(sorted_strings[index]).to eq('aaa')
37
+
38
+ index = sorted_strings.bsearch_index { |x| x.start_with? 'b' }
39
+ expect(sorted_strings[index]).to eq('bbd')
40
+
41
+ index = sorted_strings.bsearch_index { |x| x.start_with? 'bb' }
42
+ expect(sorted_strings[index]).to eq('bbd')
43
+
44
+ index = sorted_strings.bsearch_index { |x| x.start_with? 'bbc' }
45
+ expect(sorted_strings[index]).to eq('bbc')
46
+
47
+ index = sorted_strings.bsearch_index { |x| x.start_with? 'cc' }
48
+ expect(sorted_strings[index]).to eq('cce')
49
+ end
50
+ end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
+ require_relative '../lib/jekyll_all_collections'
3
+
4
+ # Verifies how data comparisons work
2
5
 
3
- # See https://stackoverflow.com/a/75377832/553865
4
6
  class Obj
5
7
  # `last_modified` is primary sort key
6
8
  # `date` (when specified) is secondary sort key
@@ -12,11 +14,11 @@ class Obj
12
14
  end
13
15
  end
14
16
 
15
- RSpec.describe(Obj) do # rubocop:disable Metrics/BlockLength
16
- let(:o1) { Obj.new('2000-01-01', '2001-01-01') }
17
- let(:o2) { Obj.new('2010-01-01', '2001-01-01') }
18
- let(:o3) { Obj.new('2010-01-01', '2011-01-01') }
19
- let(:o4) { Obj.new('2020-01-01', '2011-01-01') }
17
+ RSpec.describe(Obj) do
18
+ let(:o1) { described_class.new('2000-01-01', '2001-01-01') }
19
+ let(:o2) { described_class.new('2010-01-01', '2001-01-01') }
20
+ let(:o3) { described_class.new('2010-01-01', '2011-01-01') }
21
+ let(:o4) { described_class.new('2020-01-01', '2011-01-01') }
20
22
  let(:objs) { [o1, o2, o3, o4] }
21
23
 
22
24
  # See https://ruby-doc.org/3.2.0/Comparable.html
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/hooks/all_files'
3
+
4
+ def build_msbs(sorted_strings)
5
+ sorted_strings.each do |string|
6
+ $msbs.insert LruFile.new(string.reverse, "Page #{string}") # { |x| x.url.start_with? string }
7
+ end
8
+ $msbs.enable_search
9
+ end
10
+
11
+ RSpec.describe(MSlinnBinarySearch) do
12
+ $msbs = described_class.new [:url, %i[start_with? placeholder]]
13
+ build_msbs %w[aaa.html baa.html caa.html bbb.html cbb.html dbb.html ccc.html ccd.html cce.html]
14
+
15
+ it 'handles an empty search string by returning the index of the first item (0)' do
16
+ index = $msbs.find_index '' # { |x| x.url.start_with? '' }
17
+ expect(index).to be_zero
18
+ end
19
+
20
+ it 'returns the index of the first partial match' do
21
+ index = $msbs.find_index 'a.html' # { |x| x.url.start_with? 'a.html' }
22
+ expect(index).to eq(0)
23
+
24
+ index = $msbs.find_index 'baa.html' # { |x| x.url.start_with? 'baa.html' }
25
+ expect(index).to eq(1)
26
+
27
+ index = $msbs.find_index 'c.html' # { |x| x.url.start_with? 'c.html' }
28
+ expect(index).to eq(6)
29
+
30
+ index = $msbs.find_index 'cce.html' # { |x| x.url.start_with? 'cce.html' }
31
+ expect(index).to eq(8)
32
+ end
33
+
34
+ it 'returns the item of the first match' do
35
+ item = $msbs.find 'a.html' # { |x| x.url.start_with? 'a.html' }
36
+ expect(item.url.reverse).to eq('aaa.html')
37
+
38
+ item = $msbs.find 'baa.html' # { |x| x.url.start_with? 'baa.html' }
39
+ expect(item.url.reverse).to eq('baa.html')
40
+
41
+ item = $msbs.find 'c.html' # { |x| x.url.start_with? 'c.html' }
42
+ expect(item.url.reverse).to eq('ccc.html')
43
+
44
+ item = $msbs.find 'cce.html' # { |x| x.url.start_with? 'cce.html' }
45
+ expect(item.url.reverse).to eq('cce.html')
46
+ end
47
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/util/send_chain'
3
+
4
+ unless defined? LruFile
5
+ LruFile = Struct.new(:url, :page) do
6
+ include SendChain
7
+ end
8
+ end
9
+
10
+ RSpec.describe(LruFile) do
11
+ lru_file = described_class.new 'abc', 'def'
12
+
13
+ it 'can perform a simple call if no arguments are required' do
14
+ # Equivalent to: lru_file.url.reverse
15
+ actual = lru_file.send_chain %i[url reverse]
16
+ expect(actual).to eq('cba')
17
+ end
18
+
19
+ it 'can accept a scalar argument in stages' do
20
+ lru_file.new_chain [:url, %i[end_with? placeholder]]
21
+ # Equivalent to: lru_file.url.end_with?('bc')
22
+ substituted_chain = lru_file.substitute_chain_with 'bc'
23
+ actual = lru_file.send_chain substituted_chain
24
+ expect(actual).to be true
25
+ end
26
+
27
+ it 'can accept a vector argument in stages' do
28
+ lru_file.new_chain [:url, %i[end_with? placeholder]]
29
+ # Next 2 lines are equivalent to: lru_file.url.end_with?('bc')
30
+ substituted_chain = lru_file.substitute_chain_with ['bc']
31
+ actual = lru_file.send_chain substituted_chain
32
+ expect(actual).to be true
33
+ end
34
+
35
+ it 'can accept a scalar argument in one stage' do
36
+ lru_file.new_chain [:url, %i[end_with? placeholder]]
37
+ # Equivalent to: lru_file.url.end_with?('bc')
38
+ actual = lru_file.substitute_and_send_chain_with 'bc'
39
+ expect(actual).to be true
40
+ end
41
+
42
+ it 'can accept an array argument in one stage' do
43
+ lru_file.new_chain [:url, %i[end_with? placeholder]]
44
+ # Equivalent to: lru_file.url.end_with?('bc')
45
+ actual = lru_file.substitute_and_send_chain_with ['bc']
46
+ expect(actual).to be true
47
+ end
48
+
49
+ it 'can use the evaluate_with alias' do
50
+ lru_file.new_chain [:url, %i[end_with? placeholder]]
51
+ # Equivalent to: lru_file.url.end_with?('bc')
52
+ actual = lru_file.evaluate_with ['bc']
53
+ expect(actual).to be true
54
+ end
55
+
56
+ it 'can reuse the chain with different values' do
57
+ lru_file.new_chain [:url, %i[end_with? placeholder]]
58
+
59
+ # Equivalent to: lru_file.url.end_with?('bc')
60
+ actual = lru_file.substitute_and_send_chain_with 'bc'
61
+ expect(actual).to be true
62
+
63
+ # Equivalent to: lru_file.url.end_with?('abc')
64
+ substituted_chain = lru_file.substitute_chain_with ['abc']
65
+ actual = lru_file.send_chain substituted_chain
66
+ expect(actual).to be true
67
+
68
+ # Equivalent to: lru_file.url.end_with?('de')
69
+ actual = lru_file.substitute_and_send_chain_with 'de'
70
+ expect(actual).to be false
71
+ end
72
+ end
data/spec/send_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ # Exploring how to set date attributes in an object
4
+
5
+ class Obj
6
+ # `last_modified` is primary sort key
7
+ # `date` (when specified) is secondary sort key
8
+ attr_reader :date, :last_modified
9
+
10
+ def initialize(param1, param2)
11
+ @last_modified = Date.parse(param1)
12
+ @date = Date.parse(param2)
13
+ end
14
+ end
15
+
16
+ RSpec.describe(Obj) do
17
+ let(:obj) { described_class.new('2000-01-01', '2001-01-01') }
18
+
19
+ it 'can send date' do
20
+ date = obj.send :date
21
+ expect(obj.date).to eq(date)
22
+ end
23
+
24
+ it 'can send last_modified' do
25
+ last_modified = obj.send :last_modified
26
+ expect(obj.last_modified).to eq(last_modified)
27
+ end
28
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/hooks/all_files'
3
+
4
+ RSpec.describe(SortedLruFiles) do
5
+ expected1 = 'first-page.html'
6
+ expected2 = 'second-page.html'
7
+ expected3 = 'third-page.html'
8
+
9
+ it 'can read back an inserted item' do
10
+ sorted_files = described_class.new
11
+ sorted_files.insert(expected1, "https://mslinn.com/#{expected1}") # insert reverses expected1
12
+ sorted_files.enable_search
13
+
14
+ actual = sorted_files.select expected1
15
+ expect(actual.length).to eq(1)
16
+ expect(actual.first&.reverse&.start_with?(expected1.reverse)).to be true
17
+
18
+ actual = sorted_files.select expected1[5..]
19
+ expect(actual.length).to eq(1)
20
+ expect(actual.first&.reverse&.start_with?(expected1[5..].reverse)).to be true
21
+
22
+ actual = sorted_files.select 'should_not_match'
23
+ expect(actual).to be_empty
24
+ end
25
+
26
+ it 'works with 2 items and one match' do
27
+ sorted_files = described_class.new
28
+ sorted_files.insert(expected1, "https://mslinn.com/#{expected1}") # insert reverses expected1
29
+ sorted_files.insert(expected2, "https://mslinn.com/#{expected2}")
30
+ sorted_files.enable_search
31
+
32
+ expect(sorted_files.msbs.array[0].url).to be <= sorted_files.msbs.array[1].url
33
+
34
+ actual = sorted_files.select expected1
35
+ expect(actual.length).to eq(1)
36
+ expect(actual.first&.end_with?(expected1)).to be true
37
+
38
+ actual = sorted_files.select expected2
39
+ expect(actual.length).to eq(1)
40
+ expect(actual.first&.end_with?(expected2)).to be true
41
+ end
42
+
43
+ it 'handles multiple matches' do
44
+ sorted_files = described_class.new
45
+ sorted_files.insert(expected1, "https://mslinn.com/#{expected1}") # insert reverses expected1
46
+ sorted_files.insert(expected2, "https://mslinn.com/#{expected2}")
47
+ sorted_files.enable_search
48
+
49
+ expected = '.html'
50
+ actual = sorted_files.select expected
51
+ expect(actual.length).to eq(2)
52
+ expect(actual.first&.end_with?(expected)).to be true
53
+ end
54
+
55
+ it 'works with 3 items' do
56
+ sorted_files = described_class.new
57
+ sorted_files.insert(expected1, "https://mslinn.com/#{expected1}") # insert reverses expected1
58
+ sorted_files.insert(expected2, "https://mslinn.com/#{expected2}")
59
+ sorted_files.insert(expected3, "https://mslinn.com/#{expected3}")
60
+ sorted_files.enable_search
61
+
62
+ expect(sorted_files.msbs.array[0].url).to be <= sorted_files.msbs.array[1].url
63
+ expect(sorted_files.msbs.array[1].url).to be <= sorted_files.msbs.array[2].url
64
+
65
+ actual = sorted_files.select expected1
66
+ expect(actual.length).to eq(1)
67
+ expect(actual.first&.end_with?(expected1)).to be true
68
+
69
+ actual = sorted_files.select expected2
70
+ expect(actual.length).to eq(1)
71
+ expect(actual.first&.end_with?(expected2)).to be true
72
+
73
+ actual = sorted_files.select expected3
74
+ expect(actual.length).to eq(1)
75
+ expect(actual.first&.end_with?(expected3)).to be true
76
+
77
+ expected = '.html'
78
+ actual = sorted_files.select expected
79
+ expect(actual.length).to eq(3)
80
+ expect(actual.first&.end_with?(expected)).to be true
81
+ end
82
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require 'jekyll'
2
2
  require 'date'
3
3
 
4
- require_relative '../lib/jekyll_all_collections'
5
-
6
4
  Jekyll.logger.log_level = :info
7
5
 
8
6
  RSpec.configure do |config|
@@ -10,5 +8,5 @@ RSpec.configure do |config|
10
8
  config.filter_run_when_matching focus: true
11
9
 
12
10
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
13
- config.example_status_persistence_file_path = 'spec/status_persistence.txt'
11
+ config.example_status_persistence_file_path = '../spec/status_persistence.txt'
14
12
  end
@@ -1,22 +1,32 @@
1
- example_id | status | run_time |
2
- ----------------------------------------------------------------- | ------ | --------------- |
3
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:1] | passed | 0.00138 seconds |
4
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:2] | passed | 0.00185 seconds |
5
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:3] | passed | 0.0016 seconds |
6
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:4] | passed | 0.00169 seconds |
7
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:5] | passed | 0.0012 seconds |
8
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:6] | passed | 0.00154 seconds |
9
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:7] | passed | 0.00122 seconds |
10
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:8] | passed | 0.0015 seconds |
11
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:9] | passed | 0.00141 seconds |
12
- ./spec/all_collections_tag/all_collections_tag_sort_spec.rb[1:10] | passed | 0.00118 seconds |
13
- ./spec/date_sort_spec.rb[1:1] | passed | 0.00007 seconds |
14
- ./spec/date_sort_spec.rb[1:2] | passed | 0.00005 seconds |
15
- ./spec/date_sort_spec.rb[1:3] | passed | 0.00005 seconds |
16
- ./spec/date_sort_spec.rb[1:4] | passed | 0.00005 seconds |
17
- ./spec/date_sort_spec.rb[1:5] | passed | 0.00011 seconds |
18
- ./spec/date_sort_spec.rb[1:6] | passed | 0.00004 seconds |
19
- ./spec/date_sort_spec.rb[1:7] | passed | 0.00006 seconds |
20
- ./spec/date_sort_spec.rb[1:8] | passed | 0.00004 seconds |
21
- ./spec/date_sort_spec.rb[1:9] | passed | 0.00004 seconds |
22
- ./spec/date_sort_spec.rb[1:10] | passed | 0.00005 seconds |
1
+ example_id | status | run_time |
2
+ ------------------------------------------------------------------------------------------- | ------- | --------------- |
3
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/bsearch_spec.rb[1:1] | pending | 0.00041 seconds |
4
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/bsearch_spec.rb[1:2] | pending | 0.00005 seconds |
5
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:1] | passed | 0.00135 seconds |
6
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:2] | passed | 0.00012 seconds |
7
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:3] | passed | 0.00036 seconds |
8
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:4] | passed | 0.00149 seconds |
9
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:5] | passed | 0.00016 seconds |
10
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:6] | passed | 0.00046 seconds |
11
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:7] | passed | 0.00075 seconds |
12
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:8] | passed | 0.00056 seconds |
13
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:9] | passed | 0.00029 seconds |
14
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/date_sort_spec.rb[1:10] | passed | 0.00015 seconds |
15
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/mslinn_binary_search_spec.rb[1:1] | passed | 0.00274 seconds |
16
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/mslinn_binary_search_spec.rb[1:2] | passed | 0.0001 seconds |
17
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/mslinn_binary_search_spec.rb[1:3] | passed | 0.00022 seconds |
18
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_chain_spec.rb[1:1] | passed | 0.00022 seconds |
19
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_chain_spec.rb[1:2] | passed | 0.00126 seconds |
20
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_chain_spec.rb[1:3] | passed | 0.00004 seconds |
21
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_chain_spec.rb[1:4] | passed | 0.00093 seconds |
22
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_chain_spec.rb[1:5] | passed | 0.0001 seconds |
23
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_chain_spec.rb[1:6] | passed | 0.00003 seconds |
24
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_chain_spec.rb[1:7] | passed | 0.00026 seconds |
25
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_spec.rb[1:1] | passed | 0.00038 seconds |
26
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/send_spec.rb[1:2] | passed | 0.00007 seconds |
27
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/sorted_lru_files_spec.rb[1:1] | passed | 0.00139 seconds |
28
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/sorted_lru_files_spec.rb[1:2] | passed | 0.00044 seconds |
29
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/sorted_lru_files_spec.rb[1:3] | passed | 0.0001 seconds |
30
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/sorted_lru_files_spec.rb[1:4] | passed | 0.00057 seconds |
31
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/testable_spec.rb[1:1] | passed | 0.00027 seconds |
32
+ /mnt/f/work/jekyll/my_plugins/jekyll_all_collections/spec/testable_spec.rb[2:1] | passed | 0.00171 seconds |
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ # Exploring how to invoke methods from classes and modules
4
+ # See https://mslinn.com/jekyll/10700-designing-for-testability.html
5
+
6
+ module TestModule
7
+ def a_method
8
+ 'a_method says Hi!'
9
+ end
10
+ end
11
+
12
+ class TestClass
13
+ extend TestModule # Defines class methods
14
+
15
+ def initialize(param1, param2)
16
+ super()
17
+ @param1 = param1
18
+ @param2 = param2
19
+ end
20
+ end
21
+
22
+ RSpec.describe(TestModule) do
23
+ extend described_class
24
+
25
+ it 'Invokes a_method from module' do
26
+ result = self.class.a_method
27
+ expect(result).to eq('a_method says Hi!')
28
+ end
29
+ end
30
+
31
+ RSpec.describe(TestClass) do
32
+ let(:o1) { described_class.new('value1', 'value2') }
33
+
34
+ it 'Invokes a_method from class' do
35
+ result = o1.class.a_method
36
+ expect(result).to eq('a_method says Hi!')
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_all_collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
9
- bindir: exe
8
+ bindir: bin
10
9
  cert_chain: []
11
- date: 2024-07-26 00:00:00.000000000 Z
10
+ date: 2025-02-07 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: jekyll
@@ -52,7 +51,21 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- description: 'Provides a collection of all collections in site.all_collections.
54
+ - !ruby/object:Gem::Dependency
55
+ name: sorted_set
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ description: 'Provides normalized collections and extra functionality for Jekyll websites.
56
69
 
57
70
  '
58
71
  email:
@@ -67,14 +80,25 @@ files:
67
80
  - README.md
68
81
  - Rakefile
69
82
  - jekyll_all_collections.gemspec
70
- - lib/all_collections_hooks.rb
71
- - lib/all_collections_tag.rb
83
+ - lib/hooks/a_page.rb
84
+ - lib/hooks/all_collections_hooks.rb
85
+ - lib/hooks/all_files.rb
86
+ - lib/hooks/class_methods.rb
72
87
  - lib/jekyll_all_collections.rb
73
88
  - lib/jekyll_all_collections/version.rb
89
+ - lib/tag/all_collections_tag.rb
90
+ - lib/util/mslinn_binary_search.rb
91
+ - lib/util/send_chain.rb
74
92
  - spec/all_collections_tag/all_collections_tag_sort_spec.rb
93
+ - spec/bsearch_spec.rb
75
94
  - spec/date_sort_spec.rb
95
+ - spec/mslinn_binary_search_spec.rb
96
+ - spec/send_chain_spec.rb
97
+ - spec/send_spec.rb
98
+ - spec/sorted_lru_files_spec.rb
76
99
  - spec/spec_helper.rb
77
100
  - spec/status_persistence.txt
101
+ - spec/testable_spec.rb
78
102
  homepage: https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html
79
103
  licenses:
80
104
  - MIT
@@ -84,7 +108,6 @@ metadata:
84
108
  changelog_uri: https://github.com/mslinn/jekyll_all_collections/CHANGELOG.md
85
109
  homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_all_collections.html
86
110
  source_code_uri: https://github.com/mslinn/jekyll_all_collections
87
- post_install_message:
88
111
  rdoc_options: []
89
112
  require_paths:
90
113
  - lib
@@ -99,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
122
  - !ruby/object:Gem::Version
100
123
  version: '0'
101
124
  requirements: []
102
- rubygems_version: 3.5.16
103
- signing_key:
125
+ rubygems_version: 3.6.3
104
126
  specification_version: 4
105
- summary: Provides a collection of all collections in site.all_collections.
127
+ summary: Provides normalized collections and extra functionality for Jekyll websites.
106
128
  test_files: []
@@ -1,118 +0,0 @@
1
- require 'jekyll'
2
- require 'jekyll_plugin_logger'
3
- require_relative 'jekyll_all_collections/version'
4
-
5
- # Creates an array of `APage` called site.all_collections, which will be available from :site, :pre_render onwards
6
- module AllCollectionsHooks
7
- @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
8
-
9
- # No, all_collections is not defined for this hook
10
- # Jekyll::Hooks.register(:site, :after_init, priority: :normal) do |site|
11
- # defined = AllCollectionsHooks.all_collections_defined?(site)
12
- # @logger.debug { "Jekyll::Hooks.register(:site, :after_init: #{defined}" }
13
- # end
14
-
15
- # Creates a `Array[APage]` property called site.all_collections if it does not already exist
16
- # Each `APage` entry is one document or page.
17
- Jekyll::Hooks.register(:site, :post_read, priority: :normal) do |site|
18
- defined = AllCollectionsHooks.all_collections_defined?(site)
19
- @logger.debug { "Jekyll::Hooks.register(:site, :post_read, :normal: #{defined}" }
20
- AllCollectionsHooks.compute(site) unless site.class.method_defined? :all_collections
21
- end
22
-
23
- # Yes, all_collections is defined for this hook
24
- # Jekyll::Hooks.register(:site, :post_read, priority: :low) do |site|
25
- # defined = AllCollectionsHooks.all_collections_defined?(site)
26
- # @logger.debug { "Jekyll::Hooks.register(:site, :post_read, :low: #{defined}" }
27
- # end
28
-
29
- # Yes, all_collections is defined for this hook
30
- # Jekyll::Hooks.register(:site, :post_read, priority: :normal) do |site|
31
- # defined = AllCollectionsHooks.all_collections_defined?(site)
32
- # @logger.debug { "Jekyll::Hooks.register(:site, :post_read, :normal: #{defined}" }
33
- # end
34
-
35
- # Yes, all_collections is defined for this hook
36
- # Jekyll::Hooks.register(:site, :pre_render, priority: :normal) do |site, _payload|
37
- # defined = AllCollectionsHooks.all_collections_defined?(site)
38
- # @logger.debug { "Jekyll::Hooks.register(:site, :pre_render: #{defined}" }
39
- # end
40
-
41
- def self.compute(site)
42
- objects = site.collections
43
- .values
44
- .map { |x| x.class.method_defined?(:docs) ? x.docs : x }
45
- .flatten
46
-
47
- site.class.module_eval { attr_accessor :all_collections }
48
- apages = AllCollectionsHooks.apages_from_objects(objects)
49
- site.all_collections = apages
50
- end
51
-
52
- @sort_by = ->(apages, criteria) { [apages.sort(criteria)] }
53
-
54
- # The collection value is just the collection label, not the entire collection object
55
- def self.apages_from_objects(objects)
56
- pages = []
57
- objects.each do |object|
58
- page = APage.new(object)
59
- pages << page unless page.data['exclude_from_all']
60
- end
61
- pages
62
- end
63
-
64
- def self.all_collections_defined?(site)
65
- "site.all_collections #{site.class.method_defined?(:all_collections) ? 'IS' : 'IS NOT'} defined"
66
- end
67
-
68
- class APage
69
- attr_reader :content, :data, :date, :description, :destination, :draft, :excerpt, :ext, :extname,
70
- :label, :last_modified, :layout, :path, :relative_path, :tags, :title, :type, :url
71
-
72
- # Verify each property exists before accessing it; this helps write tests
73
- def initialize(obj) # rubocop:disable Metrics/AbcSize
74
- @data = obj.data if obj.respond_to? :data
75
-
76
- @categories = @data['categories'] if @data.key? 'categories'
77
- @content = obj.content if obj.respond_to? :content
78
- @date = (@data['date'].to_date if @data&.key?('date')) || Date.today
79
- @description = @data['description'] if @data.key? 'description'
80
-
81
- # TODO: What _config.yml setting should be passed to destination()?
82
- @destination = obj.destination('') if obj.respond_to? :destination
83
-
84
- @draft = Jekyll::Draft.draft?(obj)
85
- @excerpt = @data['excerpt'] if @data.key? 'excerpt'
86
- @ext = obj.extname
87
- @ext ||= @data['ext'] if @data.key? 'ext'
88
- @extname = @ext # For compatibility with previous versions of all_collections
89
- @label = obj.collection.label if obj&.collection.respond_to? :label
90
- @last_modified = @data['last_modified'] || @data['last_modified_at'] || @date
91
- @last_modified_field = case @data
92
- when @data.key?('last_modified')
93
- 'last_modified'
94
- when @data.key?('last_modified_at')
95
- 'last_modified_at'
96
- end
97
- @layout = @data['layout'] if @data.key? 'layout'
98
- @path = obj.path if obj.respond_to? :path
99
- @relative_path = obj.relative_path if obj.respond_to? :relative_path
100
- @tags = @data['tags'] if @data.key? 'tags'
101
- @title = @data['title'] if @data.key? 'title'
102
- @type = obj.type if obj.respond_to? :type
103
- @url = obj.url
104
- end
105
-
106
- def to_s
107
- return @label if @label
108
-
109
- @date.to_s
110
- end
111
- end
112
-
113
- PluginMetaLogger.instance.logger.info do
114
- "Loaded AllCollectionsHooks v#{JekyllAllCollectionsVersion::VERSION} :site, :pre_render, :normal hook plugin."
115
- end
116
- end
117
-
118
- Liquid::Template.register_filter(AllCollectionsHooks)