nori/codegen/templates

Template-based code generation using the handles library.

Stores default templates and provides IR-to-context converters for TypeScript code generators.

Types

pub type TsConfig {
  TsConfig(
    use_exports: Bool,
    use_interfaces: Bool,
    readonly_properties: Bool,
  )
}

Constructors

  • TsConfig(
      use_exports: Bool,
      use_interfaces: Bool,
      readonly_properties: Bool,
    )

Module specifiers the generated TypeScript imports itself by. They follow the generated_suffix setting of the typescript target, which decides whether the files on disk are types.generated.ts or types.ts — emitting a fixed specifier makes the imports name a file that was never written.

pub type TsModules {
  TsModules(types: String, client: String)
}

Constructors

  • TsModules(types: String, client: String)

Values

pub const default_template_dir: String

Default template directory (relative to project root)

pub fn default_ts_modules() -> TsModules

Specifiers for generated_suffix: true, the default.

pub fn ir_to_ts_client_context(
  ir: ir.CodegenIR,
  modules: TsModules,
) -> ctx.Value
pub fn ir_to_ts_react_query_context(
  ir: ir.CodegenIR,
  modules: TsModules,
) -> ctx.Value
pub fn ir_to_ts_swr_context(
  ir: ir.CodegenIR,
  modules: TsModules,
) -> ctx.Value
pub fn ir_to_ts_types_context(
  ir: ir.CodegenIR,
  config: TsConfig,
) -> ctx.Value
pub fn load_template(
  template_dir: String,
  name: String,
) -> String

Load a template from file, or fall back to the embedded default.

pub fn render(template_str: String, context: ctx.Value) -> String

Compile and run a handles template with the given context.

Templates can come from disk (user-customized .hbs files in templates/), so errors are surfaced inline in the generated output as a header comment instead of crashing. Grep generated files for nori: template error to detect failures in CI.

pub fn ts_modules_for_suffix(generated_suffix: Bool) -> TsModules

Specifiers for a generated_suffix setting.

Search Document