Skip to content

calternal_notes_core::templates

Pure Note template rendering and frontmatter merging.

Template YAML is parsed before variable replacement. This keeps a title or date value from changing YAML structure, and the shared Note writer remains the only code that emits app-managed frontmatter fields.

Source: crates/calternal-notes-core/src/templates.rs

pub struct NoteTemplateOutput

A complete Note body produced from a template.

Fields

  • pub content: String: Markdown with the merged, canonical Note frontmatter.
  • pub cursor_offset: Option<usize>: Position of the first cursor marker in the Markdown body.

Implements: Clone, Debug, PartialEq, Eq

Source: crates/calternal-notes-core/src/templates.rs:52

pub struct RenderedTemplate

Rendered template text and the first cursor marker’s UTF-8 byte offset.

Fields

  • pub text: String: Text after known variables and all cursor markers are resolved.
  • pub cursor_offset: Option<usize>: Position of the first {{cursor}}, measured in bytes from the start.

Implements: Clone, Debug, PartialEq, Eq

Source: crates/calternal-notes-core/src/templates.rs:43

pub struct TemplateVariables<'a>

Values available to a Note template. The Notes plugin supplies the local date and time so this pure crate never reads the system clock.

Fields

  • pub date: &'a str: Local date in YYYY-MM-DD form.
  • pub time: &'a str: Local time in HH:MM form.
  • pub title: &'a str: The new Note title.
  • pub week: &'a str: ISO week in YYYY-Www form.

Implements: Clone, Copy, Debug, PartialEq, Eq

Source: crates/calternal-notes-core/src/templates.rs:30

pub enum TemplateError

An invalid or oversized Note template.

Variants

  • TooLarge: Rendering exceeded the bounded output size.
  • InvalidFrontmatter: Frontmatter is not a YAML mapping with string property names.
  • InvalidPropertyKey: A custom frontmatter property has an invalid name.
  • InvalidTags: tags must be a string or a list of strings.

Implements: Clone, Debug, PartialEq, Eq, fmt::Display, std::error::Error

Source: crates/calternal-notes-core/src/templates.rs:61

pub fn build_note_from_template(
source: &str,
variables: TemplateVariables<'_>,
patch: &NoteFrontmatterPatch,
) -> Result<NoteTemplateOutput, TemplateError>

Build a Note from a Markdown template and app-owned frontmatter patch. Template identity and timestamp fields are ignored; custom YAML keys and tags are retained through the shared frontmatter writer.

Source: crates/calternal-notes-core/src/templates.rs:130

pub fn render_template(
source: &str,
variables: TemplateVariables<'_>,
) -> Result<RenderedTemplate, TemplateError>

Render the five supported variables. Unknown variables remain byte-for-byte unchanged. All cursor markers are removed; only the first position is kept.

Source: crates/calternal-notes-core/src/templates.rs:87