ilusm.dev

ggen

Template file generator - render a template string by substituting all ${name} placeholders with values from an object, write the result to disk, or run a batch of {path, tpl, vars} jobs at once.

Load with: use ggen

What this module does

ggen is a minimal file generator for scaffolding and code generation. It replaces ${key} tokens in a template string with the corresponding string values from a vars object, then optionally writes the result to a file path. A batch runner lets you generate many files from a list of {path, tpl, vars} records in one call.

Quick example

use ggen

tpl = "Hello, ${name}! You are ${age} years old."
out = ggenr(tpl, {name: "Alice", age: "30"})
prn(out)  # "Hello, Alice! You are 30 years old."

# Write to file
ggenw("output/hello.txt", tpl, {name: "Bob", age: "25"})

# Batch generate
jobs = [
    {path: "src/a.ilu", tpl: "use ${mod}\n", vars: {mod: "txt"}},
    {path: "src/b.ilu", tpl: "use ${mod}\n", vars: {mod: "trl"}}
]
ggenr(jobs)

Functions

Rendering

ggenr(template, vars)

Renders a template string by replacing every ${key} occurrence with the string value of vars.key. All keys in vars are iterated and substituted. Returns the rendered string. Errors if template is not a string or vars is not an object.

ggenw(path, template, vars)

Renders the template and writes the result to path using fs.wr. Returns the path string.

Batch generation

ggenr(rows)

Runs a batch of file generation jobs. rows is a list of objects each with path, tpl, and vars fields. Calls ggenw for each row and returns the list of written paths.

Notes

  • Placeholder syntax is ${key} - the braces and dollar sign are literal. There is no expression evaluation inside placeholders.
  • Requires txt, trl, fs, and eru.