pub struct PluginManager { /* private fields */ }Expand description
Manages registered plugins and executes lifecycle hooks.
§Example
use ssg::plugin::{PluginManager, PluginContext, Plugin};
use ssg::error::SsgError;
use std::path::Path;
#[derive(Debug)]
struct LogPlugin;
impl Plugin for LogPlugin {
fn name(&self) -> &str { "logger" }
fn before_compile(&self, ctx: &PluginContext) -> Result<(), SsgError> {
println!("Compiling from {:?}", ctx.content_dir);
Ok(())
}
}
let mut pm = PluginManager::new();
pm.register(LogPlugin);
assert_eq!(pm.len(), 1);
let ctx = PluginContext::new(
Path::new("content"),
Path::new("build"),
Path::new("public"),
Path::new("templates"),
);
pm.run_before_compile(&ctx).unwrap();Implementations§
Source§impl PluginManager
impl PluginManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty plugin manager.
§Examples
use ssg::plugin::PluginManager;
let pm = PluginManager::new();
assert!(pm.is_empty());Sourcepub fn register<P: Plugin + 'static>(&mut self, plugin: P)
pub fn register<P: Plugin + 'static>(&mut self, plugin: P)
Registers a plugin.
Plugins run in the order they are registered.
§Examples
use ssg::drafts::DraftPlugin;
use ssg::plugin::PluginManager;
let mut pm = PluginManager::new();
pm.register(DraftPlugin::new(false));
assert_eq!(pm.len(), 1);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of registered plugins.
§Examples
use ssg::plugin::PluginManager;
let pm = PluginManager::new();
assert_eq!(pm.len(), 0);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if no plugins are registered.
§Examples
use ssg::plugin::PluginManager;
assert!(PluginManager::new().is_empty());Sourcepub fn names(&self) -> Vec<&str>
pub fn names(&self) -> Vec<&str>
Returns the names of all registered plugins.
§Examples
use ssg::drafts::DraftPlugin;
use ssg::plugin::PluginManager;
let mut pm = PluginManager::new();
pm.register(DraftPlugin::new(false));
assert_eq!(pm.names(), vec!["drafts"]);Sourcepub fn inventory(&self) -> Vec<PluginInfo<'_>>
pub fn inventory(&self) -> Vec<PluginInfo<'_>>
Returns an inventory of every registered plugin, in execution order.
This is the single source of truth for “which plugins run, and what do
they do” — consumed by ssg plugins list and by the README sync check,
so a plugin added or removed cannot silently leave the documentation
claiming a stale count.
§Examples
use ssg::drafts::DraftPlugin;
use ssg::plugin::PluginManager;
let mut pm = PluginManager::new();
pm.register(DraftPlugin::new(false));
let inv = pm.inventory();
assert_eq!(inv.len(), 1);
assert_eq!(inv[0].name, "drafts");
assert_eq!(inv[0].order, 0);Sourcepub fn run_before_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
pub fn run_before_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
Runs the before_compile hook on all registered plugins.
Plugins execute in registration order. If any plugin returns an error, execution stops and the error is propagated.
§Examples
use ssg::plugin::{PluginContext, PluginManager};
use std::path::Path;
let pm = PluginManager::new();
let ctx = PluginContext::new(
Path::new("content"), Path::new("build"),
Path::new("site"), Path::new("templates"),
);
assert!(pm.run_before_compile(&ctx).is_ok());Sourcepub fn run_after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
pub fn run_after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
Runs the after_compile hook on all registered plugins.
Plugins execute in registration order. If any plugin returns an error, execution stops and the error is propagated.
§Examples
use ssg::plugin::{PluginContext, PluginManager};
use std::path::Path;
let pm = PluginManager::new();
let ctx = PluginContext::new(
Path::new("content"), Path::new("build"),
Path::new("site"), Path::new("templates"),
);
assert!(pm.run_after_compile(&ctx).is_ok());Sourcepub fn run_fused_transforms(&self, ctx: &PluginContext) -> Result<(), SsgError>
pub fn run_fused_transforms(&self, ctx: &PluginContext) -> Result<(), SsgError>
Runs the fused HTML transform pass: reads each HTML file once,
pipes through all plugins with has_transform() == true, writes once.
This eliminates N separate read/write cycles (where N = number of transform plugins) per HTML file.
§Examples
use ssg::plugin::{PluginContext, PluginManager};
use std::path::Path;
let pm = PluginManager::new();
let ctx = PluginContext::new(
Path::new("content"), Path::new("build"),
Path::new("site"), Path::new("templates"),
);
// No transform plugins ⇒ trivial Ok.
assert!(pm.run_fused_transforms(&ctx).is_ok());Sourcepub fn run_on_serve(&self, ctx: &PluginContext) -> Result<(), SsgError>
pub fn run_on_serve(&self, ctx: &PluginContext) -> Result<(), SsgError>
Runs the on_serve hook on all registered plugins.
Plugins execute in registration order. If any plugin returns an error, execution stops and the error is propagated.
§Examples
use ssg::plugin::{PluginContext, PluginManager};
use std::path::Path;
let pm = PluginManager::new();
let ctx = PluginContext::new(
Path::new("content"), Path::new("build"),
Path::new("site"), Path::new("templates"),
);
assert!(pm.run_on_serve(&ctx).is_ok());Trait Implementations§
Source§impl Debug for PluginManager
impl Debug for PluginManager
Source§impl Default for PluginManager
impl Default for PluginManager
Source§fn default() -> PluginManager
fn default() -> PluginManager
Auto Trait Implementations§
impl !RefUnwindSafe for PluginManager
impl !UnwindSafe for PluginManager
impl Freeze for PluginManager
impl Send for PluginManager
impl Sync for PluginManager
impl Unpin for PluginManager
impl UnsafeUnpin for PluginManager
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more