Skip to main content

PluginManager

Struct PluginManager 

Source
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

Source

pub fn new() -> Self

Creates a new empty plugin manager.

§Examples
use ssg::plugin::PluginManager;

let pm = PluginManager::new();
assert!(pm.is_empty());
Source

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);
Source

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);
Source

pub fn is_empty(&self) -> bool

Returns true if no plugins are registered.

§Examples
use ssg::plugin::PluginManager;

assert!(PluginManager::new().is_empty());
Source

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"]);
Source

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);
Source

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());
Source

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());
Source

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());
Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PluginManager

Source§

fn default() -> PluginManager

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more