Class: Jekyll::L10n::ExtractionConfigLoader
- Inherits:
-
Object
- Object
- Jekyll::L10n::ExtractionConfigLoader
- Defined in:
- lib/jekyll-l10n/extraction/config_loader.rb
Overview
Loads and validates extraction configuration for files during build.
ExtractionConfigLoader finds extraction configuration for generated HTML files by matching them against Jekyll site pages. It validates whether extraction is enabled and configured for a file, loads page-specific settings, and identifies files to skip (localized page variants).
Key responsibilities:
-
Match generated HTML files to Jekyll site pages
-
Validate that extraction is enabled for a file
-
Load page-specific extraction configuration
-
Identify localized page variants to skip
-
Extract CSS selectors for element exclusion
Instance Method Summary collapse
-
#extract_exclude_selectors(config) ⇒ Array<String>
Extract CSS selectors for element exclusion from configuration.
-
#find_page_config_for_file(file_path) ⇒ Hash?
Find page configuration for a file.
-
#initialize(site, dest) ⇒ ExtractionConfigLoader
constructor
Initialize a new ExtractionConfigLoader.
-
#load_page_config(file_path) ⇒ PageLocalesConfig
Load extraction configuration for a file.
-
#skip_localized_page?(file_path) ⇒ Boolean
Check if a file is a localized page variant that should be skipped.
-
#valid_for_extraction?(file_path) ⇒ Boolean
Check if a file is valid for extraction.
Constructor Details
#initialize(site, dest) ⇒ ExtractionConfigLoader
Initialize a new ExtractionConfigLoader.
31 32 33 34 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 31 def initialize(site, dest) @site = site @dest = dest end |
Instance Method Details
#extract_exclude_selectors(config) ⇒ Array<String>
Extract CSS selectors for element exclusion from configuration.
Returns CSS selectors of elements to exclude from extraction (e.g., script, style, code blocks). Defaults to sensible defaults if not configured.
108 109 110 111 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 108 def extract_exclude_selectors(config) config.data.dig('with_locales_data', 'extraction', 'exclude_selectors') || ['script', 'style', 'code.language-plaintext', 'pre code'] end |
#find_page_config_for_file(file_path) ⇒ Hash?
Find page configuration for a file.
Matches a generated file path to a Jekyll page with extraction enabled. Returns the page’s front matter data, or nil if no match found.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 70 def find_page_config_for_file(file_path) @site.pages.each do |page| next unless page.data['with_locales'] == true page_output = page.output_ext ? page.destination('') : page.destination('/') next unless file_path.end_with?(page_output.sub(%r{/$}, '/index.html')) return page.data end nil end |
#load_page_config(file_path) ⇒ PageLocalesConfig
Load extraction configuration for a file.
Finds the Jekyll page matching this file and returns its localization configuration wrapped in PageLocalesConfig.
58 59 60 61 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 58 def load_page_config(file_path) page_config = find_page_config_for_file(file_path) PageLocalesConfig.new(page_config) end |
#skip_localized_page?(file_path) ⇒ Boolean
Check if a file is a localized page variant that should be skipped.
Localized pages are generated copies in locale subdirectories that shouldn’t be re-extracted (extraction happens on original pages only).
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 90 def skip_localized_page?(file_path) relative_path = file_path.sub(@dest, '') all_locales = @site.pages.map do |p| p.data.dig('with_locales_data', 'locales') || [] end all_locales.flatten! all_locales.uniq! all_locales.any? { |locale| relative_path.start_with?("/#{locale}/") } end |
#valid_for_extraction?(file_path) ⇒ Boolean
Check if a file is valid for extraction.
Matches the file to a Jekyll page and verifies extraction is enabled for that page in the configuration.
43 44 45 46 47 48 49 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 43 def valid_for_extraction?(file_path) page_config = find_page_config_for_file(file_path) return false unless page_config config = PageLocalesConfig.new(page_config) config.enabled? && config.extract_on_build? end |