From d1f9174e7f394c1e9de8074ec51deba62fc46e50 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Fri, 5 May 2017 08:41:50 +0800 Subject: [PATCH 1/4] (feat) adopt new handlebars navigate api Signed-off-by: Ning Sun --- .../html_handlebars/helpers/navigation.rs | 14 ++++++--- src/renderer/html_handlebars/helpers/toc.rs | 31 +++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/renderer/html_handlebars/helpers/navigation.rs b/src/renderer/html_handlebars/helpers/navigation.rs index 50dd7a4a..779c6bfb 100644 --- a/src/renderer/html_handlebars/helpers/navigation.rs +++ b/src/renderer/html_handlebars/helpers/navigation.rs @@ -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("\"", ""); diff --git a/src/renderer/html_handlebars/helpers/toc.rs b/src/renderer/html_handlebars/helpers/toc.rs index c7cc074a..454bd667 100644 --- a/src/renderer/html_handlebars/helpers/toc.rs +++ b/src/renderer/html_handlebars/helpers/toc.rs @@ -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("