Hwaro::Utils::CrinjaUtils
Constants
Pre-allocated nil value to avoid repeated allocations in hot paths
Instance methods
Convert an extra field value (from front matter) to Crinja::Value.
Recursive so nested [extra.*] hashes and arrays-of-hashes
traverse via {{ page.extra.a.b }} in templates.
Convert a JSON::Any value to Crinja::Value
Convert a Hash(String, TOML::Any) to Crinja::Value
Convert a TOML::Any value to Crinja::Value
Convert a YAML::Any value to Crinja::Value.
depth guards against a self-referencing YAML anchor, whose parsed
graph is cyclic and would otherwise recurse until the stack dies
(see Utils::Nesting). Both call sites — DataDisk.parse_file
and the load_data template function — already rescue and degrade, so
the raise surfaces as "data file skipped" rather than a crash.
Parse a data payload into the Crinja::Value templates see, dispatching
on a bare format name ("json", "toml", "yaml"/"yml", "csv"). This is the
one place that mapping lives: data/ files (DataDisk.parse_file),
the load_data() template function, and [[data.remote]] payloads
(RemoteData#parse_body) all route through it, so a key can move between
a disk file, a template call and a remote source and parse identically.
CSV matches the long-standing load_data() shape: an array of rows,
each an array of stripped string cells.
Returns nil for an unrecognized format — every caller owns its own error policy (warn and drop the key, debug-log and return none, or raise a classified fetch error), and no two of them agree, so this helper neither logs nor raises. Parse exceptions propagate to the caller for the same reason.
BOM stripping is the caller's call too: the data/ and remote paths
strip it (JSON and TOML both reject a leading BOM outright), while
load_data() deliberately never has — see its call site.
Coerce a template/filter argument to an Int32 count, clamped to
[min, max], with default for anything that isn't a number at all.
Numeric arguments reach templates as strings far more often than not:
parse_shortcode_args_jinja produces a Hash(String, String), so every
value a shortcode forwards is a String. Crinja::Value#as_number raises
Crinja::TypeError on those, and the raise propagated out of the filter
and aborted the whole page render — resize_image(width="800") killed
the page instead of resizing. Out-of-range and NaN values clamp here too
rather than raising OverflowError from Float64#to_i.