Class: Jekyll::Plugins::PaginateV3::Templates::GroupedIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-paginate-v3/templates/grouped_index/core.rb,
lib/jekyll-paginate-v3/templates/grouped_index/mode_detection.rb,
lib/jekyll-paginate-v3/templates/grouped_index/config_normalisation.rb,
lib/jekyll-paginate-v3/templates/grouped_index/numeric_and_datetime_entries.rb,
lib/jekyll-paginate-v3/templates/grouped_index/alphabetic_and_shared_helpers.rb

Overview

Alphabetic grouped-index builders plus shared range/token helpers. Structure: alphabetic groups are emitted first, while shared helpers provide range matching and token formatting for all grouping modes.

Constant Summary collapse

MINIMUM_GROW =
0.01
MAXIMUM_GROW =
10_000.0
MINIMUM_STEP =
0.001
MAXIMUM_STEP =
100_000_000.0
MAXIMUM_AUTOMATIC_GROUPS =
100
MAXIMUM_TOTAL_GROUPS =
10_000
MAXIMUM_ALPHABETIC_TOKEN_LENGTH =
3
DURATION_UNITS =
%w[day month year hour minute second].freeze
CALENDAR_UNITS =
%w[month year].freeze

Instance Method Summary collapse

Constructor Details

#initialize(key:, raw_group:, items:, nested_separator:, split_delimiter:, equivalents:, now_keyword:, today_keyword:, keywords: nil, log_lambda: nil) ⇒ GroupedIndex

Returns a new instance of GroupedIndex.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jekyll-paginate-v3/templates/grouped_index/core.rb', line 35

def initialize(key:, raw_group:, items:, nested_separator:, split_delimiter:, equivalents:, now_keyword:, today_keyword:, keywords: nil, log_lambda: nil)
	@key = key.to_s
	@raw_group = raw_group
	@items = items.is_a?(Array) ? items : []
	@nested_separator = nested_separator
	@split_delimiter = split_delimiter
	@equivalents = equivalents
	@frontmatter_path = Jekyll::Plugins::PaginateV3::Support::FrontmatterPath.new(
		separator: @nested_separator,
		arrays: :expand,
		equivalents: equivalents
	)
	@string_array = Jekyll::Plugins::PaginateV3::Support::StringArray.new(delimiter: @split_delimiter)
	@now_keyword = normalise_keyword(now_keyword, 'now')
	@today_keyword = normalise_keyword(today_keyword, 'today')
	@keywords = Utils.safe_hash(keywords)
	@log_lambda = log_lambda

	@duration_keyword_by_unit = build_duration_keyword_map(@keywords)
	@duration_unit_by_keyword = @duration_keyword_by_unit.each_with_object({}) do |(unit, keyword), memo|
		memo[keyword] = unit
	end
end

Instance Method Details

#build_entriesObject

Expands grouped index configuration into generated template entries.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/jekyll-paginate-v3/templates/grouped_index/core.rb', line 60

def build_entries
	mode = resolve_grouping_mode
	prepared_candidates = prepare_candidates(@items)

	case mode
	when 'numeric'
		build_numeric_entries(prepared_candidates, normalise_numeric_group_config)
	when 'datetime'
		build_datetime_entries(prepared_candidates, normalise_datetime_group_config(prepared_candidates))
	when 'alphabetic'
		build_alphabetic_entries(prepared_candidates, normalise_alphabetic_group_config)
	else
		raise ArgumentError, "Unsupported group mode '#{mode}'."
	end
end