diff options
Diffstat (limited to 'src/directive/shortcut.rs')
-rw-r--r-- | src/directive/shortcut.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/directive/shortcut.rs b/src/directive/shortcut.rs index 03fd648..534300a 100644 --- a/src/directive/shortcut.rs +++ b/src/directive/shortcut.rs @@ -1,27 +1,34 @@ use crate::error::SiteError; use crate::page::PageMeta; -use crate::site::Site; +use crate::site::{Shortcut as S, Site}; use crate::wikitext::ParsedDirective; -#[derive(Debug, Default, Eq, PartialEq)] -pub struct Shortcut {} +#[derive(Debug, Eq, PartialEq)] +pub struct Shortcut { + shortcut: S, +} impl Shortcut { pub const REQUIRED: &'static [&'static str] = &["desc", "name", "url"]; pub const ALLOWED: &'static [&'static str] = &[]; - pub const ALLOW_ANY_UNNAMED: bool = true; + pub const ALLOW_ANY_UNNAMED: bool = false; - pub fn new() -> Self { - Self::default() + pub fn new(shortcut: S) -> Self { + Self { shortcut } } - pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> { - Ok("FIXME:inline".into()) + pub fn process(&self, site: &mut Site, _meta: &mut PageMeta) -> Result<String, SiteError> { + site.add_shortcut(self.shortcut.clone()); + Ok("".into()) } } -impl From<ParsedDirective> for Shortcut { - fn from(_p: ParsedDirective) -> Self { - Self::new() +impl From<&ParsedDirective> for Shortcut { + fn from(p: &ParsedDirective) -> Self { + let args = p.args(); + let name = args.get("name").unwrap(); + let desc = args.get("desc").unwrap(); + let url = args.get("url").unwrap(); + Self::new(S::new(name, desc, url)) } } |