pub struct Templates { /* private fields */ }Implementations§
Source§impl Templates
impl Templates
Sourcepub fn new(
root_path: &Path,
template_folder: Option<&Path>,
) -> Result<Self, TemplateError>
pub fn new( root_path: &Path, template_folder: Option<&Path>, ) -> Result<Self, TemplateError>
Creates a new Templates instance.
Template loading priority:
- If
template_folderis provided, load from{template_folder}/**/*.html - Otherwise, load from
{root_path}/.mbr/**/*.html - Fall back to compiled defaults for any missing templates
Sourcepub fn reload(&self) -> Result<(), TemplateError>
pub fn reload(&self) -> Result<(), TemplateError>
Reload all templates from disk. Call this when template files change.
Sourcepub fn tera_clone(&self) -> Tera
pub fn tera_clone(&self) -> Tera
Returns a clone of the Tera engine for lock-free rendering.
Acquires the read lock once to clone the Tera instance (~KB of template AST). Use this before entering a rayon thread pool to avoid per-file lock contention.
pub fn render_markdown( &self, html: &str, frontmatter: SimpleMetadata, extra_context: HashMap<String, Value>, ) -> Result<String, TemplateError>
Sourcepub fn render_markdown_with_tera(
tera: &Tera,
html: &str,
frontmatter: SimpleMetadata,
extra_context: HashMap<String, Value>,
) -> Result<String, TemplateError>
pub fn render_markdown_with_tera( tera: &Tera, html: &str, frontmatter: SimpleMetadata, extra_context: HashMap<String, Value>, ) -> Result<String, TemplateError>
Lock-free variant of render_markdown that takes a &Tera directly.
Use with tera_clone() to avoid Arc<RwLock<Tera>> contention when
rendering many files in parallel (e.g., from a rayon thread pool).
Sourcepub fn render_template_with_tera(
tera: &Tera,
template_name: &str,
context_data: HashMap<String, Value>,
) -> Result<String, TemplateError>
pub fn render_template_with_tera( tera: &Tera, template_name: &str, context_data: HashMap<String, Value>, ) -> Result<String, TemplateError>
Lock-free generic template render that takes a &Tera directly.
Use with tera_clone() to avoid Arc<RwLock<Tera>> contention when
rendering many pages in parallel (e.g., from a rayon thread pool).
pub fn render_section( &self, context_data: HashMap<String, Value>, ) -> Result<String, TemplateError>
Sourcepub fn render_home(
&self,
context_data: HashMap<String, Value>,
) -> Result<String, TemplateError>
pub fn render_home( &self, context_data: HashMap<String, Value>, ) -> Result<String, TemplateError>
Renders the home page (root directory) using home.html template. This allows users to customize their home page differently from section pages.
Sourcepub fn render_error(
&self,
context_data: HashMap<String, Value>,
) -> Result<String, TemplateError>
pub fn render_error( &self, context_data: HashMap<String, Value>, ) -> Result<String, TemplateError>
Renders an error page using error.html template.
Context variables:
error_code: HTTP status code (e.g., 404, 500)error_title: Short error title (e.g., “Not Found”)error_message: Optional detailed messagerequested_url: The URL that was requested (useful in GUI mode without URL bar)server_mode: Boolean indicating server vs static moderelative_base: Path prefix to .mbr assets (e.g., “.mbr/”, “../.mbr/”)relative_root: Path prefix to root (e.g., “”, “../”)
Sourcepub fn render_tag(
&self,
context_data: HashMap<String, Value>,
) -> Result<String, TemplateError>
pub fn render_tag( &self, context_data: HashMap<String, Value>, ) -> Result<String, TemplateError>
Renders a tag page showing all pages with a specific tag.
Context variables:
tag_source: URL identifier for the tag source (e.g., “tags”, “performers”)tag_display_value: Original display value of the tag (e.g., “Rust”, “Joshua Jay”)tag_label: Singular label for the tag source (e.g., “Tag”, “Performer”)tag_label_plural: Plural label for the tag source (e.g., “Tags”, “Performers”)pages: Array of page objects with url_path, title, descriptionpage_count: Number of pages with this tagserver_mode: Boolean indicating server vs static moderelative_base: Path prefix to .mbr assets
Sourcepub fn render_tag_index(
&self,
context_data: HashMap<String, Value>,
) -> Result<String, TemplateError>
pub fn render_tag_index( &self, context_data: HashMap<String, Value>, ) -> Result<String, TemplateError>
Renders a tag source index showing all tags from a source.
Context variables:
tag_source: URL identifier for the tag source (e.g., “tags”, “performers”)tag_label: Singular label for the tag source (e.g., “Tag”, “Performer”)tag_label_plural: Plural label for the tag source (e.g., “Tags”, “Performers”)tags: Array of tag objects with url_value, display_value, page_counttag_count: Total number of unique tagsserver_mode: Boolean indicating server vs static moderelative_base: Path prefix to .mbr assets
Sourcepub fn render_media_viewer(
&self,
context_data: HashMap<String, Value>,
) -> Result<String, TemplateError>
pub fn render_media_viewer( &self, context_data: HashMap<String, Value>, ) -> Result<String, TemplateError>
Renders a media viewer page for video, PDF, or audio content.
Context variables:
media_type: Type of media (“video”, “pdf”, “audio”)title: Page title (defaults to filename)media_path: Path to the media filebreadcrumbs: Navigation breadcrumbsparent_path: URL to parent directory for back navigationserver_mode: Boolean indicating server vs static moderelative_base: Path prefix to .mbr assetssidebar_style: Sidebar navigation stylesidebar_max_items: Maximum items per section in sidebar
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Templates
impl !UnwindSafe for Templates
impl Freeze for Templates
impl Send for Templates
impl Sync for Templates
impl Unpin for Templates
impl UnsafeUnpin for Templates
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);