(feat) adopt new handlebars navigate api
Signed-off-by: Ning Sun <sunng@about.me>
This commit is contained in:
parent
435682e95c
commit
d1f9174e7f
|
@ -14,9 +14,12 @@ pub fn previous(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(
|
||||||
// get value from context data
|
// get value from context data
|
||||||
// rc.get_path() is current json parent path, you should always use it like this
|
// rc.get_path() is current json parent path, you should always use it like this
|
||||||
// param is the key of value you want to display
|
// param is the key of value you want to display
|
||||||
let chapters = rc.context().navigate(rc.get_path(), &VecDeque::new(), "chapters").to_owned();
|
let chapters = rc.context()
|
||||||
|
.navigate(rc.get_path(), &VecDeque::new(), "chapters")?
|
||||||
|
.to_owned();
|
||||||
|
|
||||||
let current = rc.context().navigate(rc.get_path(), &VecDeque::new(), "path")
|
let current = rc.context()
|
||||||
|
.navigate(rc.get_path(), &VecDeque::new(), "path")?
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace("\"", "");
|
.replace("\"", "");
|
||||||
|
|
||||||
|
@ -115,9 +118,12 @@ pub fn next(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(), R
|
||||||
// get value from context data
|
// get value from context data
|
||||||
// rc.get_path() is current json parent path, you should always use it like this
|
// rc.get_path() is current json parent path, you should always use it like this
|
||||||
// param is the key of value you want to display
|
// param is the key of value you want to display
|
||||||
let chapters = rc.context().navigate(rc.get_path(), &VecDeque::new(), "chapters").to_owned();
|
let chapters = rc.context()
|
||||||
|
.navigate(rc.get_path(), &VecDeque::new(), "chapters")?
|
||||||
|
.to_owned();
|
||||||
|
|
||||||
let current = rc.context().navigate(rc.get_path(), &VecDeque::new(), "path")
|
let current = rc.context()
|
||||||
|
.navigate(rc.get_path(), &VecDeque::new(), "path")?
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace("\"", "");
|
.replace("\"", "");
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,13 @@ impl HelperDef for RenderToc {
|
||||||
// get value from context data
|
// get value from context data
|
||||||
// rc.get_path() is current json parent path, you should always use it like this
|
// rc.get_path() is current json parent path, you should always use it like this
|
||||||
// param is the key of value you want to display
|
// param is the key of value you want to display
|
||||||
let chapters = rc.context().navigate(rc.get_path(), &VecDeque::new(), "chapters").to_owned();
|
let chapters = rc.context()
|
||||||
let current = rc.context().navigate(rc.get_path(), &VecDeque::new(), "path").to_string().replace("\"", "");
|
.navigate(rc.get_path(), &VecDeque::new(), "chapters")?
|
||||||
|
.to_owned();
|
||||||
|
let current = rc.context()
|
||||||
|
.navigate(rc.get_path(), &VecDeque::new(), "path")?
|
||||||
|
.to_string()
|
||||||
|
.replace("\"", "");
|
||||||
try!(rc.writer.write_all("<ul class=\"chapter\">".as_bytes()));
|
try!(rc.writer.write_all("<ul class=\"chapter\">".as_bytes()));
|
||||||
|
|
||||||
// Decode json format
|
// Decode json format
|
||||||
|
@ -28,7 +33,8 @@ impl HelperDef for RenderToc {
|
||||||
|
|
||||||
// Spacer
|
// Spacer
|
||||||
if item.get("spacer").is_some() {
|
if item.get("spacer").is_some() {
|
||||||
try!(rc.writer.write_all("<li class=\"spacer\"></li>".as_bytes()));
|
try!(rc.writer
|
||||||
|
.write_all("<li class=\"spacer\"></li>".as_bytes()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +72,8 @@ impl HelperDef for RenderToc {
|
||||||
try!(rc.writer.write_all("<a href=\"".as_bytes()));
|
try!(rc.writer.write_all("<a href=\"".as_bytes()));
|
||||||
|
|
||||||
// Add link
|
// Add link
|
||||||
try!(rc.writer.write_all(Path::new(item.get("path")
|
try!(rc.writer
|
||||||
|
.write_all(Path::new(item.get("path")
|
||||||
.expect("Error: path should be Some(_)"))
|
.expect("Error: path should be Some(_)"))
|
||||||
.with_extension("html")
|
.with_extension("html")
|
||||||
.to_str()
|
.to_str()
|
||||||
|
@ -101,14 +108,12 @@ impl HelperDef for RenderToc {
|
||||||
// Render only inline code blocks
|
// Render only inline code blocks
|
||||||
|
|
||||||
// filter all events that are not inline code blocks
|
// filter all events that are not inline code blocks
|
||||||
let parser = Parser::new(name).filter(|event| {
|
let parser = Parser::new(name).filter(|event| match *event {
|
||||||
match *event {
|
|
||||||
Event::Start(Tag::Code) |
|
Event::Start(Tag::Code) |
|
||||||
Event::End(Tag::Code) |
|
Event::End(Tag::Code) |
|
||||||
Event::InlineHtml(_) |
|
Event::InlineHtml(_) |
|
||||||
Event::Text(_) => true,
|
Event::Text(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// render markdown to html
|
// render markdown to html
|
||||||
|
|
Loading…
Reference in New Issue