Class: Jekyll::Plugins::PaginateV3::Templates::VariantExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-paginate-v3/templates/variant_expander.rb

Overview

Expands template pagination config into concrete variants before the paginator emits index pages.

This class generalises grouped and multi-layout behaviour so both explicit templates and generated templates share one execution path.

Instance Method Summary collapse

Constructor Details

#initialize(site:, site_config:, template:, template_config:, template_pagination_source:, merge_template_pagination_lambda:, normalise_template_config_lambda:, resolve_items_lambda:, log_lambda:) ⇒ VariantExpander

Builds an expander for one template and its normalised pagination config.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jekyll-paginate-v3/templates/variant_expander.rb', line 18

def initialize(site:, site_config:, template:, template_config:, template_pagination_source:, merge_template_pagination_lambda:, normalise_template_config_lambda:, resolve_items_lambda:, log_lambda:)
	@site = site
	@site_config = site_config
	@template = template
	@template_config = template_config
	@template_pagination_source = Utils.safe_hash(template_pagination_source)
	@merge_template_pagination_lambda = merge_template_pagination_lambda
	@normalise_template_config_lambda = normalise_template_config_lambda
	@resolve_items_lambda = resolve_items_lambda
	@log_lambda = log_lambda
	@equivalents = site_config['equivalents']
	@active_template_config = Utils.deep_copy(template_config)
	@active_split_delimiter = @active_template_config.key?('split') ? @active_template_config['split'] : site_config.dig('syntax', 'split')
	@active_nested_separator = @active_template_config['separator'] || site_config.dig('syntax', 'separator')
	@site_frontmatter_path = Jekyll::Plugins::PaginateV3::Support::FrontmatterPath.new(
		separator: site_config.dig('syntax', 'separator'),
		arrays: :expand,
		equivalents: @equivalents
	)
	@site_string_array = Jekyll::Plugins::PaginateV3::Support::StringArray.new(delimiter: site_config.dig('syntax', 'split'))
	@active_frontmatter_path = @site_frontmatter_path.with(separator: @active_nested_separator)
	@active_string_array = @site_string_array.with(delimiter: @active_split_delimiter)
end

Instance Method Details

#expandObject

Expands one template into grouped/layout variants.



43
44
45
46
47
48
# File 'lib/jekyll-paginate-v3/templates/variant_expander.rb', line 43

def expand
	layout_entries = Utils.arrayify(@template_config['layouts']).map { |entry| entry.to_s.strip }.reject(&:empty?)
	layout_entries = [nil] if layout_entries.empty?

	build_variants(layout_entries)
end