Class: Jekyll::L10n::SiteConfigAccessor
- Inherits:
-
Object
- Object
- Jekyll::L10n::SiteConfigAccessor
- Defined in:
- lib/jekyll-l10n/utils/site_config_accessor.rb
Overview
Accesses Jekyll site configuration properties.
SiteConfigAccessor provides a unified interface for accessing Jekyll site properties, handling both normal Jekyll site objects and test doubles (hashes). This enables easier testing and more flexible configuration handling.
Key responsibilities:
- Extract localization data from site configuration
- Compute the union of all configured locales across site and page front matter
- Access site source directory
- Access site destination directory
- Handle both Jekyll site objects and hash-based doubles
Class Method Summary collapse
-
.all_configured_locales(site) ⇒ Array<String>
Compute the union of all locales configured anywhere on the site.
-
.dest(site) ⇒ String
Get the site destination directory.
-
.extract_locales_data(site) ⇒ Hash
Extract localization configuration from site.
-
.source(site) ⇒ String
Get the site source directory.
Class Method Details
.all_configured_locales(site) ⇒ Array<String>
Compute the union of all locales configured anywhere on the site.
Combines locales from two sources:
- The site-wide
with_locales_data.localesdefault (from_config.yml) - Any page-level
with_locales_data.localesfront-matter override, since a page-level override replaces the site default for that page rather than inheriting it, so page scanning alone misses site-wide locales when few or no ordinary pages are present.
This lets callers discover locales that exist only as a page-level override, not declared in site config, while also retaining all site-wide locales.
52 53 54 55 56 57 |
# File 'lib/jekyll-l10n/utils/site_config_accessor.rb', line 52 def self.all_configured_locales(site) site_wide_locales = extract_locales_data(site)['locales'] || [] pages = site.is_a?(Hash) ? site['pages'] : site.pages page_locales = pages.flat_map { |p| p.data.dig('with_locales_data', 'locales') || [] } (site_wide_locales + page_locales).uniq end |
.dest(site) ⇒ String
Get the site destination directory.
71 72 73 |
# File 'lib/jekyll-l10n/utils/site_config_accessor.rb', line 71 def self.dest(site) site.is_a?(Hash) ? site['dest'] : site.dest end |
.extract_locales_data(site) ⇒ Hash
Extract localization configuration from site.
Accesses the with_locales_data configuration which contains the locales, extraction settings, and other localization options.
31 32 33 34 35 36 |
# File 'lib/jekyll-l10n/utils/site_config_accessor.rb', line 31 def self.extract_locales_data(site) config = site.is_a?(Hash) ? site['config'] : site.config defaults = config['defaults'] || [] entry = defaults.find { |d| d.dig('values', 'with_locales_data') } entry&.dig('values', 'with_locales_data') || {} end |
.source(site) ⇒ String
Get the site source directory.
63 64 65 |
# File 'lib/jekyll-l10n/utils/site_config_accessor.rb', line 63 def self.source(site) site.is_a?(Hash) ? site['source'] : site.source end |