From 4d20badb243c2ae57b8b54d0c5e025b43957dd8f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 5 Aug 2022 22:44:40 +0300 Subject: feat: placeholder for toc directive Sponsored-by: author --- src/directive/mod.rs | 9 +++++++++ src/directive/toc.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/directive/toc.rs diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 59c352c..0767c9d 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -17,6 +17,7 @@ pub enum Directive { Inline(Inline), PageStats(PageStats), Tag(Tag), + Toc(Toc), } impl TryFrom for Directive { @@ -64,6 +65,10 @@ impl TryFrom for Directive { Self::check_args(&p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?; Directive::Tag(Tag::from(p)) } + "toc" => { + Self::check_args(&p, Toc::REQUIRED, Toc::ALLOWED, Toc::ALLOW_ANY_UNNAMED)?; + Directive::Toc(Toc::from(p)) + } _ => return Err(SiteError::UnknownDirective(p.name().into())), }; Ok(d) @@ -115,6 +120,7 @@ impl Directive { Self::Meta(x) => x.process(site, meta), Self::PageStats(x) => x.process(site, meta), Self::Tag(x) => x.process(site, meta), + Self::Toc(x) => x.process(site, meta), } } } @@ -133,3 +139,6 @@ pub use pagestats::PageStats; mod tag; use tag::Tag; + +mod toc; +use toc::Toc; diff --git a/src/directive/toc.rs b/src/directive/toc.rs new file mode 100644 index 0000000..6db46d2 --- /dev/null +++ b/src/directive/toc.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Toc {} + +impl Toc { + pub const REQUIRED: &'static [&'static str] = &[]; + pub const ALLOWED: &'static [&'static str] = &["levels"]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { + Ok("FIXME:inline".into()) + } +} + +impl From for Toc { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} -- cgit v1.2.1