summaryrefslogtreecommitdiff
path: root/src/directive/shortcut.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/directive/shortcut.rs')
-rw-r--r--src/directive/shortcut.rs31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/directive/shortcut.rs b/src/directive/shortcut.rs
index 7b397d4..fa3f783 100644
--- a/src/directive/shortcut.rs
+++ b/src/directive/shortcut.rs
@@ -1,3 +1,4 @@
+use crate::directive::DirectiveImplementation;
use crate::error::SiteError;
use crate::page::PageMeta;
use crate::site::{Shortcut as S, Site};
@@ -10,32 +11,32 @@ pub struct Shortcut {
shortcut: S,
}
-impl Shortcut {
- pub const REQUIRED: &'static [&'static str] = &["name", "url"];
- pub const ALLOWED: &'static [&'static str] = &["desc"];
- pub const ALLOW_ANY_UNNAMED: bool = false;
+impl DirectiveImplementation for Shortcut {
+ const REQUIRED: &'static [&'static str] = &["name", "url"];
+ const ALLOWED: &'static [&'static str] = &["desc"];
+ const ALLOW_ANY_UNNAMED: bool = false;
- pub fn new(shortcut: S) -> Self {
- Self { shortcut }
+ fn from_parsed(p: &ParsedDirective) -> Self {
+ let args = p.args();
+ let name = args.get("name").unwrap();
+ let desc = args.get("desc").unwrap_or(&"");
+ let url = args.get("url").unwrap();
+ Self::new(S::new(name, desc, url))
}
- pub fn prepare(&self, site: &mut Site) -> Result<(), SiteError> {
+ fn prepare(&self, site: &mut Site) -> Result<(), SiteError> {
trace!("shortcut: prepare");
site.add_shortcut(self.shortcut.clone());
Ok(())
}
- pub fn process(&self, _site: &mut Site, _meta: &mut PageMeta) -> Result<String, SiteError> {
+ fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> {
Ok("".into())
}
}
-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_or(&"");
- let url = args.get("url").unwrap();
- Self::new(S::new(name, desc, url))
+impl Shortcut {
+ pub fn new(shortcut: S) -> Self {
+ Self { shortcut }
}
}