agpm_cli/templating/mod.rs
1//! Markdown templating engine for AGPM resources.
2//!
3//! This module provides Tera-based templating functionality for Markdown resources,
4//! enabling dynamic content generation during installation. It supports safe, sandboxed
5//! template rendering with a rich context containing installation metadata.
6//!
7//! # Overview
8//!
9//! The templating system allows resource authors to:
10//! - Reference other resources by name and type
11//! - Access resolved installation paths and versions
12//! - Use conditional logic and loops in templates
13//! - Read and embed project-specific files (style guides, best practices, etc.)
14//!
15//! # Template Context
16//!
17//! Templates are rendered with a structured context containing:
18//! - `agpm.resource`: Current resource information (name, type, install path, etc.)
19//! - `agpm.deps`: Nested dependency information by resource type and name
20//!
21//! # Custom Filters
22//!
23//! - `content`: Read project-specific files (e.g., `{{ 'docs/guide.md' | content }}`)
24//!
25//! # Syntax Restrictions
26//!
27//! For security and safety, the following Tera features are disabled:
28//! - `{% include %}` tags (no file system access)
29//! - `{% extends %}` tags (no template inheritance)
30//! - `{% import %}` tags (no external template imports)
31//! - Custom functions that access the file system or network (except content filter)
32//!
33//! # Supported Features
34//!
35//! - Variable substitution: `{{ agpm.resource.install_path }}`
36//! - Conditional logic: `{% if agpm.resource.source %}...{% endif %}`
37//! - Loops: `{% for name, dep in agpm.deps.agents %}...{% endfor %}`
38//! - Standard Tera filters (string manipulation, formatting)
39//! - Project file embedding: `{{ 'path/to/file.md' | content }}`
40//! - Literal blocks: Protect template syntax from rendering for documentation
41
42// Module declarations
43pub mod cache;
44pub mod content;
45pub mod context;
46pub mod dependencies;
47pub mod error;
48pub mod filters;
49pub mod renderer;
50pub mod utils;
51
52#[cfg(test)]
53mod renderer_tests;
54
55// Re-exports for public API
56pub use context::{DependencyData, ResourceMetadata, TemplateContextBuilder};
57pub use error::TemplateError;
58pub use renderer::{DependencyChainEntry, RenderingMetadata, TemplateRenderer};
59pub use utils::{deep_merge_json, to_native_path_display};