Compare commits
2 Commits
c538b44f6b
...
d41b7610cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
d41b7610cd
|
|||
|
587094185d
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -372,7 +372,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "webTemplate"
|
||||
version = "0.4.3"
|
||||
version = "0.5.0-2"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"hashlink",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "webTemplate"
|
||||
version = "0.4.3"
|
||||
version = "0.5.0-2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::render::Template;
|
||||
pub enum Error {
|
||||
NoCurrentEvent,
|
||||
JinjaError(JinjaError),
|
||||
TemplateNotFound
|
||||
TemplateNotFound(String)
|
||||
}
|
||||
impl PartialEq for Error {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
@@ -73,13 +73,13 @@ impl<'a> Parser<'a> {
|
||||
fn md_preprocessor(&self) -> Result<String, Error> {
|
||||
let mut new = String::with_capacity(self.md.len());
|
||||
let mut last_match = 0;
|
||||
let re = Regex::new(r"\{\% *(.*)\((.*)\).*\%\}").unwrap();
|
||||
let re = Regex::new(r"\{\% ([^}]*)\(([^}]*)\) \%\}").unwrap();
|
||||
for caps in re.captures_iter(self.md) {
|
||||
let m = caps.get(0).unwrap();
|
||||
new.push_str(&self.md[last_match..m.start()]);
|
||||
let template = &caps[1];
|
||||
let args = &caps[2];
|
||||
new.push_str(&self.render_component(template, context! { args => parse_args(args)})?);
|
||||
new.push_str(&self.render_component(template, parse_args(args))?);
|
||||
last_match = m.end();
|
||||
}
|
||||
new.push_str(&self.md[last_match..]);
|
||||
@@ -120,8 +120,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<p>{content}</p>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -134,8 +134,8 @@ impl<'a> Parser<'a> {
|
||||
level => level as u8,
|
||||
id, classes, attrs
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<h{level}>{content}</h{level}>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -147,7 +147,7 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
block_quote_kind
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -159,8 +159,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<p><code>{content}</code></p>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -172,7 +172,7 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
container_kind
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -184,8 +184,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(content)
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -196,8 +196,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<ul>{content}</ul>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -208,8 +208,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<li>{content}</li>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -232,7 +232,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -244,7 +244,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -256,7 +256,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -269,7 +269,7 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
alignments
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -281,8 +281,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<th>{content}</th>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -293,8 +293,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<tr>{content}</tr>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -305,8 +305,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<td>{content}</td>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -317,7 +317,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -329,7 +329,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -341,7 +341,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -353,7 +353,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -365,7 +365,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -388,8 +388,8 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
link_type, dest_url, title, id, args
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<a href=\"{dest_url}\">{content}</a>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -401,7 +401,7 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
link_type, dest_url, title, id
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -414,7 +414,7 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
metadata_block_kind
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -427,8 +427,8 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
text
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("{content}"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -439,8 +439,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<code>{content}</code>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -451,7 +451,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -463,32 +463,32 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Html(_) => {
|
||||
TreeEvent::Html(html) => {
|
||||
self.render_component("Html", context! {
|
||||
content,
|
||||
content => html,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(html)
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::InlineHtml(_) => {
|
||||
TreeEvent::InlineHtml(html) => {
|
||||
self.render_component("InlineHtml", context! {
|
||||
content,
|
||||
content => html,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(html)
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -499,7 +499,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -511,8 +511,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!(" "))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -523,8 +523,8 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
todo!()
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("</br>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
@@ -535,7 +535,7 @@ impl<'a> Parser<'a> {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -548,7 +548,7 @@ impl<'a> Parser<'a> {
|
||||
parents => branch,
|
||||
checked
|
||||
}).or_else(|e| {
|
||||
if e == Error::TemplateNotFound {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
@@ -568,7 +568,8 @@ impl<'a> Parser<'a> {
|
||||
},
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
minijinja::ErrorKind::TemplateNotFound => Err(Error::TemplateNotFound),
|
||||
minijinja::ErrorKind::TemplateNotFound =>
|
||||
Err(Error::TemplateNotFound(format!("components/{component}"))),
|
||||
_ => Err(Error::JinjaError(e)),
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user