diff options
Diffstat (limited to 'src/directive/mod.rs')
-rw-r--r-- | src/directive/mod.rs | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 40def2f..e885404 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -10,12 +10,17 @@ pub enum Processed { Markdown(String), } -trait DirectiveImplementation { +pub trait DirectiveImplementation { const REQUIRED: &'static [&'static str]; const ALLOWED: &'static [&'static str]; const ALLOW_ANY_UNNAMED: bool; + fn from_parsed(p: &ParsedDirective) -> Self; fn process(&self, site: &Site, meta: &mut PageMeta) -> Result<String, SiteError>; + + fn prepare(&self, _site: &mut Site) -> Result<(), SiteError> { + Ok(()) + } } #[derive(Debug, Eq, PartialEq)] @@ -92,15 +97,15 @@ impl TryFrom<&ParsedDirective> for Directive { Format::ALLOWED, Format::ALLOW_ANY_UNNAMED, )?; - Directive::Format(Format::from(p)) + Directive::Format(Format::from_parsed(p)) } "graph" => { Self::check_args(p, Graph::REQUIRED, Graph::ALLOWED, Graph::ALLOW_ANY_UNNAMED)?; - Directive::Graph(Graph::from(p)) + Directive::Graph(Graph::from_parsed(p)) } "img" => { Self::check_args(p, Img::REQUIRED, Img::ALLOWED, Img::ALLOW_ANY_UNNAMED)?; - Directive::Img(Img::from(p)) + Directive::Img(Img::from_parsed(p)) } "inline" => { Self::check_args( @@ -109,15 +114,15 @@ impl TryFrom<&ParsedDirective> for Directive { Inline::ALLOWED, Inline::ALLOW_ANY_UNNAMED, )?; - Directive::Inline(Inline::from(p)) + Directive::Inline(Inline::from_parsed(p)) } "map" => { Self::check_args(p, Map::REQUIRED, Map::ALLOWED, Map::ALLOW_ANY_UNNAMED)?; - Directive::Map(Map::from(p)) + Directive::Map(Map::from_parsed(p)) } "meta" => { Self::check_args(p, Meta::REQUIRED, Meta::ALLOWED, Meta::ALLOW_ANY_UNNAMED)?; - Directive::Meta(Meta::from(p)) + Directive::Meta(Meta::from_parsed(p)) } "pagestats" => { Self::check_args( @@ -126,7 +131,7 @@ impl TryFrom<&ParsedDirective> for Directive { PageStats::ALLOWED, PageStats::ALLOW_ANY_UNNAMED, )?; - Directive::PageStats(PageStats::from(p)) + Directive::PageStats(PageStats::from_parsed(p)) } "shortcut" => { Self::check_args( @@ -135,7 +140,7 @@ impl TryFrom<&ParsedDirective> for Directive { Shortcut::ALLOWED, Shortcut::ALLOW_ANY_UNNAMED, )?; - Directive::Shortcut(Shortcut::from(p)) + Directive::Shortcut(Shortcut::from_parsed(p)) } "sidebar" => { Self::check_args( @@ -144,19 +149,19 @@ impl TryFrom<&ParsedDirective> for Directive { Sidebar::ALLOWED, Sidebar::ALLOW_ANY_UNNAMED, )?; - Directive::Sidebar(Sidebar::from(p)) + Directive::Sidebar(Sidebar::from_parsed(p)) } "tag" => { Self::check_args(p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?; - Directive::Tag(Tag::from(p)) + Directive::Tag(Tag::from_parsed(p)) } "table" => { Self::check_args(p, Table::REQUIRED, Table::ALLOWED, Table::ALLOW_ANY_UNNAMED)?; - Directive::Table(Table::from(p)) + Directive::Table(Table::from_parsed(p)) } "toc" => { Self::check_args(p, Toc::REQUIRED, Toc::ALLOWED, Toc::ALLOW_ANY_UNNAMED)?; - Directive::Toc(Toc::from(p)) + Directive::Toc(Toc::from_parsed(p)) } "traillink" => { Self::check_args( @@ -165,7 +170,7 @@ impl TryFrom<&ParsedDirective> for Directive { TrailLink::ALLOWED, TrailLink::ALLOW_ANY_UNNAMED, )?; - Directive::TrailLink(TrailLink::from(p)) + Directive::TrailLink(TrailLink::from_parsed(p)) } _ => return Err(SiteError::UnknownDirective(p.name().into())), }; |