From fe287a1eca5135a4a0fd249dae359f872f7d8e21 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Sat, 31 Dec 2016 18:33:17 -0800 Subject: [PATCH] Code cleanup: Remove unnecessary .remove() calls `BTreeMap::insert` will replace any existing value, so there's no need to remove the old value first. --- src/renderer/html_handlebars/hbs_renderer.rs | 25 ++++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 0e4ef8df..bcb55522 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -81,8 +81,7 @@ impl Renderer for HtmlHandlebars { content = utils::render_markdown(&content); print_content.push_str(&content); - // Remove content from previous file and render content for this one - data.remove("path"); + // Update the context with data for this file match ch.path.to_str() { Some(p) => { data.insert("path".to_owned(), p.to_json()); @@ -92,20 +91,11 @@ impl Renderer for HtmlHandlebars { "Could not convert path to str"))) }, } - - // Remove content from previous file and render content for this one - data.remove("content"); data.insert("content".to_owned(), content.to_json()); - - // Remove chapter title from previous file and add title for this one - data.remove("chapter_title"); data.insert("chapter_title".to_owned(), ch.name.to_json()); - - // Remove path to root from previous file and render content for this one - data.remove("path_to_root"); data.insert("path_to_root".to_owned(), utils::fs::path_to_root(&ch.path).to_json()); - // Rendere the handlebars template with the data + // Render the handlebars template with the data debug!("[*]: Render template"); let rendered = try!(handlebars.render("index", &data)); @@ -147,19 +137,12 @@ impl Renderer for HtmlHandlebars { // Print version - // Remove content from previous file and render content for this one - data.remove("path"); + // Update the context with data for this file data.insert("path".to_owned(), "print.md".to_json()); - - // Remove content from previous file and render content for this one - data.remove("content"); data.insert("content".to_owned(), print_content.to_json()); - - // Remove path to root from previous file and render content for this one - data.remove("path_to_root"); data.insert("path_to_root".to_owned(), utils::fs::path_to_root(Path::new("print.md")).to_json()); - // Rendere the handlebars template with the data + // Render the handlebars template with the data debug!("[*]: Render template"); let rendered = try!(handlebars.render("index", &data)); let mut file = try!(utils::fs::create_file(&book.get_dest().join("print").with_extension("html")));