pub struct Shtola { /* private fields */ }
Expand description
The main library struct.
Implementations§
source§impl Shtola
impl Shtola
sourcepub fn ignores(&mut self, vec: &mut Vec<String>)
pub fn ignores(&mut self, vec: &mut Vec<String>)
Appends glob-matched paths to the ignore list. If a glob path matches, the file is excluded from the IR.
use shtola::Shtola;
let mut m = Shtola::new();
m.ignores(&mut vec!["node_modules".into(), "vendor/bundle/".into()])
sourcepub fn source_ignores(&mut self, path: &Path) -> Result<(), Error>
pub fn source_ignores(&mut self, path: &Path) -> Result<(), Error>
Reads paths to ignore from a file. This file needs to have one single path
per line. The most common use for this would be to read your project’s .gitignore
.
use std::path::Path;
use shtola::Shtola;
let mut m = Shtola::new();
m.source_ignores(Path::new(".gitignore"));
sourcepub fn source<T: Into<PathBuf>>(&mut self, path: T)
pub fn source<T: Into<PathBuf>>(&mut self, path: T)
Sets the source directory to read from. Should be relative.
sourcepub fn destination<T: Into<PathBuf> + Clone>(&mut self, path: T)
pub fn destination<T: Into<PathBuf> + Clone>(&mut self, path: T)
Sets the destination path to write to. This directory will be created on calling this function if it doesn’t exist.
sourcepub fn clean(&mut self, b: bool)
pub fn clean(&mut self, b: bool)
Sets whether the destination directory should be removed before building.
The removal only happens once calling Shtola::build
.
Default is false
.
sourcepub fn frontmatter(&mut self, b: bool)
pub fn frontmatter(&mut self, b: bool)
Sets whether frontmatter should be parsed. Default is true
.
sourcepub fn register(&mut self, func: Box<dyn Fn(RefIR<'_>)>)
pub fn register(&mut self, func: Box<dyn Fn(RefIR<'_>)>)
Registers a new plugin function in its middleware chain.
use shtola::{Shtola, RefIR};
let mut m = Shtola::new();
let plugin = Box::new(|mut ir: RefIR| ());
m.register(plugin);
sourcepub fn build(&mut self) -> Result<IR, Error>
pub fn build(&mut self) -> Result<IR, Error>
Performs the build process. This does a couple of things:
- If
Shtola::clean
is set, removes and recreates the destination directory - Reads from the source file and ignores files as it’s been configured
- Parses front matter for the remaining files
- Runs the middleware chain, executing all plugins
- Writes the result back to the destination directory