Class: Jekyll::Unirate::Generator

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll/unirate/generator.rb

Overview

Build-time generator that fetches ONE single-base UniRate snapshot and makes it available to the rest of the build. Runs early (high priority) so the snapshot is ready before any page renders.

It does two things:

1. sets {Snapshot.current}, which the Liquid filters and tags read; and
2. populates `site.data["unirate"]` so templates can iterate the raw
   rate map directly (`{% for pair in site.data.unirate.rates %}`).

A failed fetch is logged as a warning and never raised — the build continues and helpers degrade to unconverted amounts. This is the same “never break the build” contract the Hugo/Eleventy/Astro integrations use.

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jekyll/unirate/generator.rb', line 26

def generate(site)
  config = Config.new(site.config)
  Jekyll::Unirate.default_currency = config.default_currency

  key = config.api_key
  if key.nil? || key.to_s.empty?
    Jekyll.logger.warn("UniRate:",
                       "no API key (set UNIRATE_API_KEY or unirate.api_key in _config.yml); " \
                       "skipping rate fetch")
    return store_empty(site, config.base)
  end

  load_rates(site, config)
end