Files
Marcos Paulo de3ec375ae
ci / ci (macos-latest) (push) Has been cancelled
ci / ci (ubuntu-latest) (push) Has been cancelled
ci / ci (windows-latest) (push) Has been cancelled
docs: specs and briefs for Tasks, Templater, Kanban and icons/banners
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 06:06:54 -03:00

2.8 KiB

TASK templater-segments: split a template into text and <% %> commands in the new crate notescraft-templater

Runs through OpenCode (specs/agents/opencode-runbook.md is attached automatically). Task 1 of specs/plugins-parity/templater/tasks.md. Precondition (lead step 0, done when this runs): crates/templater exists with a Cargo.toml, registered at L3. If crates/templater/Cargo.toml is missing, stop and say so.

OWNS

  • crates/templater/src/lib.rs (crate //! doc, mod segment; mod error;, pub use), crates/templater/src/error.rs (one thiserror Error, pub type Result<T>), crates/templater/src/segment.rs
  • crates/templater/tests/segment.rs

FILES TO OPEN

  • specs/plugins-parity/templater/spec.md D2 (syntax and limits)
  • crates/templates/src/expand.rs (how the existing {{ }} scanner uses find and get() without indexing; copy that style)

GOAL / API

Write crates/templater/src/segment.rs as your first tool call.

pub enum Kind { Output, Js }
pub enum Segment {
    Text(String),
    Command { src: String, line: u32, kind: Kind },   // src = text between the tags, trimmed of the marker chars
}
pub struct Template { pub segments: Vec<Segment> }
pub fn parse(src: &str) -> Result<Template>;
  • <% x %> Output. <%* x %> Js (kept, never run). Tag markers: <%- strips ALL whitespace including newlines before the tag; <%_ strips spaces and tabs before; -%> strips the following newline plus spaces; _%> strips following spaces and tabs.
  • Whitespace control edits the neighbouring Text segments (and may leave one empty: drop empty Text).
  • line is the 1-based line of the <%.
  • Errors: unterminated <% -> Error::Unterminated { line }; more than 2 000 commands -> Error::TooManyCommands; input over 1 MiB -> Error::TooLarge.
  • Text without any tag is exactly one Text equal to the input (or no segment for an empty input).

TESTS

crates/templater/tests/segment.rs: plain text; one command; three commands with lines 1, 3, 5; each of the four whitespace markers on a before/after example (write the expected strings out by hand); <%* is Js; <% with no %> gives line number; %> without an opening is plain text; CRLF input keeps \r\n outside stripped areas and -%> strips \r\n; 2 001 commands refused; 1 MiB of repeated <% returns an error in under 200 ms (use std::time::Instant, assert < 200 ms generously).

VERIFY

export PATH="$HOME/.cargo/bin:$PATH"
cargo test -p notescraft-templater
cargo clippy -p notescraft-templater --all-targets -- -D warnings
rustfmt --edition 2024 crates/templater/src/*.rs crates/templater/tests/*.rs

DO NOT

Edit Cargo files or the templates crate; parse the expression inside a command (task 2); evaluate anything; use [i] or [a..b] on the input; add a dependency.