Klenodexample

Docs

Data Imports

Built-in data plugins turn structured files and text files into Ruby modules with serializable default exports.

Built-In Data Formats

DataPlugin is the base for Klenods built-in data import plugins:

  • JsonPlugin handles .json with JSON.parse.
  • YamlPlugin handles .yaml and .yml with YAML.safe_load.
  • TomlPlugin handles .toml with TomlRB.parse.
  • TextPlugin handles .txt and .text as strings.

Import Values

Data files transform into Ruby modules exporting Default. Development imports return the parsed value directly.

Metrics = import("./metrics.json")
Navigation = import("./navigation.yaml")
Release = import("./release.toml")
Note = import("./note.txt")

In runtime bundles, parsed data is serialized directly so production loading does not need the build plugin.

When To Use Data Imports

Use data imports for content and configuration that should participate in the dependency graph, invalidate on file changes, and serialize into runtime bundles. Use Ruby modules when the value needs Ruby behavior, dynamic computation, or explicit methods.