Class: Ucode::Site::ConfigEmitter

Inherits:
Object
  • Object
show all
Includes:
Repo::AtomicWrites
Defined in:
lib/ucode/site/config_emitter.rb

Overview

Writes ‘site/.vitepress/config.ts` from the JSON output tree.

Reads:

output/planes/<n>.json     → top nav (17 planes)
output/blocks/index.json   → sidebar groups (one per plane)

Writes:

site/.vitepress/config.ts  — TypeScript module that exports the
Vitepress `defineConfig` payload. Idempotent via AtomicWrites.

Pure: reads JSON, writes TS. No Vitepress dependency on the Ruby side; the site is a thin shell that imports this generated config and re-exports ‘defineConfig(config)`.

Instance Method Summary collapse

Methods included from Repo::AtomicWrites

#same_content?, #to_pretty_json, #write_atomic

Constructor Details

#initialize(output_root:, site_root:) ⇒ ConfigEmitter

Returns a new instance of ConfigEmitter.

Parameters:

  • output_root (String, Pathname)

    dataset root

  • site_root (String, Pathname)

    Vitepress project root



28
29
30
31
# File 'lib/ucode/site/config_emitter.rb', line 28

def initialize(output_root:, site_root:)
  @output_root = Pathname.new(output_root)
  @site_root = Pathname.new(site_root)
end

Instance Method Details

#emitBoolean

Read the output tree, render config.ts, write atomically.

Returns:

  • (Boolean)

    true if the file was (re)written, false if skipped



40
41
42
# File 'lib/ucode/site/config_emitter.rb', line 40

def emit
  write_atomic(target_path, render(load_planes, load_blocks))
end

#target_pathPathname

Returns the config file path that #emit writes.

Returns:

  • (Pathname)

    the config file path that #emit writes



34
35
36
# File 'lib/ucode/site/config_emitter.rb', line 34

def target_path
  @site_root.join(".vitepress", "config.ts")
end