Skip to main content

Module registry

Module registry 

Source
Expand description

Template registry for file-based and inline templates.

This module provides TemplateRegistry, which manages template resolution from multiple sources: inline strings, filesystem directories, or embedded content.

§Design

The registry is a thin wrapper around FileRegistry<String>, providing template-specific functionality while reusing the generic file loading infrastructure.

The registry uses a two-phase approach:

  1. Collection: Templates are collected from various sources (inline, directories, embedded)
  2. Resolution: A unified map resolves template names to their content or file paths

This separation enables:

  • Testability: Resolution logic can be tested without filesystem access
  • Flexibility: Same resolution rules apply regardless of template source
  • Hot reloading: File paths can be re-read on each render in development mode

§Template Resolution

Templates are resolved by name using these rules:

  1. Inline templates (added via TemplateRegistry::add_inline) have highest priority
  2. File templates are searched in directory registration order (first directory wins)
  3. Names can be specified with or without extension: both "config" and "config.jinja" resolve

§Supported Extensions

Template files are recognized by extension, in priority order:

PriorityExtensionDescription
1 (highest).jinjaStandard Jinja extension (MiniJinja engine)
2.jinja2Full Jinja2 extension (MiniJinja engine)
3.j2Short Jinja2 extension (MiniJinja engine)
4.stplSimple template (SimpleEngine - format strings)
5 (lowest).txtPlain text templates

If multiple files exist with the same base name but different extensions (e.g., config.jinja and config.j2), the higher-priority extension wins.

§Collision Handling

The registry enforces strict collision rules:

  • Same-directory, different extensions: Higher priority extension wins (no error)
  • Cross-directory collisions: Panic with detailed message listing conflicting files

This strict behavior catches configuration mistakes early rather than silently using an arbitrary winner.

§Example

use standout_render::TemplateRegistry;

let mut registry = TemplateRegistry::new();
registry.add_template_dir("./templates")?;
registry.add_inline("override", "Custom content");

// Resolve templates
let content = registry.get_content("config")?;

Structs§

TemplateFile
A template file discovered during directory walking.
TemplateRegistry
Registry for template resolution from multiple sources.

Enums§

RegistryError
Error type for template registry operations.
ResolvedTemplate
How a template’s content is stored or accessed.

Constants§

TEMPLATE_EXTENSIONS
Recognized template file extensions in priority order.

Functions§

walk_template_dir
Walks a template directory and collects template files.