pub struct FrontmatterParser { /* private fields */ }Expand description
Unified frontmatter parser with templating support.
This struct provides a centralized interface for parsing frontmatter from content using the grey_matter library, with optional Tera templating support. It handles YAML, TOML, and JSON frontmatter formats automatically.
Implementations§
Source§impl FrontmatterParser
impl FrontmatterParser
Sourcepub fn with_project_dir(project_dir: PathBuf) -> Result<Self>
pub fn with_project_dir(project_dir: PathBuf) -> Result<Self>
Create a new frontmatter parser with custom project directory.
§Arguments
project_dir- Project root directory for template rendering
Sourcepub fn parse_with_templating<T>(
&mut self,
content: &str,
variant_inputs: Option<&Value>,
file_path: &Path,
context: Option<&OperationContext>,
) -> Result<ParsedFrontmatter<T>>where
T: DeserializeOwned,
pub fn parse_with_templating<T>(
&mut self,
content: &str,
variant_inputs: Option<&Value>,
file_path: &Path,
context: Option<&OperationContext>,
) -> Result<ParsedFrontmatter<T>>where
T: DeserializeOwned,
Parse content and extract frontmatter with optional templating.
This method provides the complete parsing pipeline:
- Extract frontmatter using gray_matter
- Apply Tera templating if variant_inputs is provided
- Deserialize the result to the target type
§Arguments
content- The content to parsevariant_inputs- Optional template variables (project, config, etc.)file_path- Path to the file (used for error reporting)context- Optional operation context for warning deduplication
§Returns
ParsedFrontmatter<T>- The parsed result with data and content
Sourcepub fn parse<T>(&self, content: &str) -> Result<ParsedFrontmatter<T>>where
T: DeserializeOwned,
pub fn parse<T>(&self, content: &str) -> Result<ParsedFrontmatter<T>>where
T: DeserializeOwned,
Sourcepub fn has_frontmatter(&self, content: &str) -> bool
pub fn has_frontmatter(&self, content: &str) -> bool
Sourcepub fn strip_frontmatter(&self, content: &str) -> String
pub fn strip_frontmatter(&self, content: &str) -> String
Sourcepub fn extract_raw_frontmatter(&self, content: &str) -> Option<String>
pub fn extract_raw_frontmatter(&self, content: &str) -> Option<String>
Sourcepub fn apply_templating(
&mut self,
content: &str,
variant_inputs: Option<&Value>,
file_path: &Path,
) -> Result<String>
pub fn apply_templating( &mut self, content: &str, variant_inputs: Option<&Value>, file_path: &Path, ) -> Result<String>
Apply Tera templating to content.
Always renders the content as a template to catch syntax errors. If variant_inputs is provided, it’s used for template variables. Otherwise, renders with an empty context.
§Arguments
content- The content to templatevariant_inputs- Optional template variables (project, config, etc.)file_path- Path to file for error reporting
§Returns
Result<String>- Templated content or error
Trait Implementations§
Source§impl Clone for FrontmatterParser
impl Clone for FrontmatterParser
Source§impl Debug for FrontmatterParser
impl Debug for FrontmatterParser
Auto Trait Implementations§
impl Freeze for FrontmatterParser
impl !RefUnwindSafe for FrontmatterParser
impl Send for FrontmatterParser
impl Sync for FrontmatterParser
impl Unpin for FrontmatterParser
impl !UnwindSafe for FrontmatterParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more