From c619847d4213504ff2fb28a814d32ea642c24287 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 24 Jul 2022 09:22:04 +0300 Subject: feat: add placeholder for tag directive Sponsored-by: author --- src/directive/mod.rs | 9 +++++++++ src/directive/tag.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/directive/tag.rs diff --git a/src/directive/mod.rs b/src/directive/mod.rs index efdc799..38fb0d3 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -14,6 +14,7 @@ pub enum Directive { Meta(Meta), Img(Img), + Tag(Tag), } impl TryFrom for Directive { @@ -49,6 +50,10 @@ impl TryFrom for Directive { Self::check_args(&p, Meta::REQUIRED, Meta::ALLOWED, Meta::ALLOW_ANY_UNNAMED)?; Directive::Meta(Meta::from(p)) } + "tag" => { + Self::check_args(&p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?; + Directive::Tag(Tag::from(p)) + } _ => return Err(SiteError::UnknownDirective(p.name().into())), }; Ok(d) @@ -97,6 +102,7 @@ impl Directive { } Self::Img(x) => x.process(site, meta), Self::Meta(x) => x.process(site, meta), + Self::Tag(x) => x.process(site, meta), } } } @@ -106,3 +112,6 @@ use meta::Meta; mod img; pub use img::Img; + +mod tag; +use tag::Tag; diff --git a/src/directive/tag.rs b/src/directive/tag.rs new file mode 100644 index 0000000..9486a7b --- /dev/null +++ b/src/directive/tag.rs @@ -0,0 +1,32 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Eq, PartialEq)] +pub struct Tag { + tags: Vec, +} + +impl Tag { + pub const REQUIRED: &'static [&'static str] = &[]; + pub const ALLOWED: &'static [&'static str] = &["class"]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new(tags: Vec) -> Self { + Self { + tags, + } + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { + Ok("".into()) + } +} + +impl From for Tag { + fn from(p: ParsedDirective) -> Self { + let tags = p.unnamed_args().iter().map(|s| s.to_string()).collect(); + Tag::new(tags) + } +} -- cgit v1.2.1