(feat) adopt new handlebars navigate api

Signed-off-by: Ning Sun <sunng@about.me>
This commit is contained in:
Ning Sun 2017-05-05 08:41:50 +08:00
parent 435682e95c
commit d1f9174e7f
No known key found for this signature in database
GPG Key ID: 2A61AA38AB6BD92E
2 changed files with 28 additions and 17 deletions

View File

@ -14,9 +14,12 @@ pub fn previous(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(
// get value from context data
// 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
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()
.replace("\"", "");
@ -115,9 +118,12 @@ pub fn next(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(), R
// get value from context data
// 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
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()
.replace("\"", "");

View File

@ -15,8 +15,13 @@ impl HelperDef for RenderToc {
// get value from context data
// 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
let chapters = rc.context().navigate(rc.get_path(), &VecDeque::new(), "chapters").to_owned();
let current = rc.context().navigate(rc.get_path(), &VecDeque::new(), "path").to_string().replace("\"", "");
let chapters = rc.context()
.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()));
// Decode json format
@ -28,7 +33,8 @@ impl HelperDef for RenderToc {
// Spacer
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;
}
@ -66,7 +72,8 @@ impl HelperDef for RenderToc {
try!(rc.writer.write_all("<a href=\"".as_bytes()));
// 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(_)"))
.with_extension("html")
.to_str()
@ -101,15 +108,13 @@ impl HelperDef for RenderToc {
// Render only inline code blocks
// filter all events that are not inline code blocks
let parser = Parser::new(name).filter(|event| {
match *event {
Event::Start(Tag::Code) |
Event::End(Tag::Code) |
Event::InlineHtml(_) |
Event::Text(_) => true,
_ => false,
}
});
let parser = Parser::new(name).filter(|event| match *event {
Event::Start(Tag::Code) |
Event::End(Tag::Code) |
Event::InlineHtml(_) |
Event::Text(_) => true,
_ => false,
});
// render markdown to html
let mut markdown_parsed_name = String::with_capacity(name.len() * 3 / 2);