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