From f993677626e7a9c8b4f580f203447e98f093918d Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sat, 18 Nov 2017 22:16:35 +0800 Subject: [PATCH] All tests finally pass! --- src/book/mod.rs | 35 ++++---------------- src/lib.rs | 5 +-- src/renderer/html_handlebars/hbs_renderer.rs | 2 +- tests/dummy_book/src/SUMMARY.md | 2 ++ tests/init.rs | 2 +- tests/rendered_output.rs | 20 +++++------ 6 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index b42a66cd..b7393b26 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -61,11 +61,11 @@ impl MDBook { /// # use mdbook::book::BookItem; /// # #[allow(unused_variables)] /// # fn main() { - /// # let book = MDBook::new("mybook"); + /// # let book = MDBook::load("mybook").unwrap(); /// for item in book.iter() { /// match *item { /// BookItem::Chapter(ref chapter) => {}, - /// BookItem::Spacer => {}, + /// BookItem::Separator => {}, /// } /// } /// @@ -140,32 +140,11 @@ impl MDBook { Ok(self) } - /// You can change the default renderer to another one - /// by using this method. The only requirement - /// is for your renderer to implement the - /// [Renderer trait](../../renderer/renderer/trait.Renderer.html) - /// - /// ```no_run - /// extern crate mdbook; - /// use mdbook::MDBook; - /// use mdbook::renderer::HtmlHandlebars; - /// - /// # #[allow(unused_variables)] - /// fn main() { - /// let book = MDBook::new("mybook") - /// .set_renderer(Box::new(HtmlHandlebars::new())); - /// - /// // In this example we replace the default renderer - /// // by the default renderer... - /// // Don't forget to put your renderer in a Box - /// } - /// ``` - /// - /// **note:** Don't forget to put your renderer in a `Box` - /// before passing it to `set_renderer()` - - pub fn set_renderer(mut self, renderer: Box) -> Self { - self.renderer = renderer; + /// You can change the default renderer to another one by using this method. + /// The only requirement is for your renderer to implement the [Renderer + /// trait](../../renderer/renderer/trait.Renderer.html) + pub fn set_renderer(mut self, renderer: R) -> Self { + self.renderer = Box::new(renderer); self } diff --git a/src/lib.rs b/src/lib.rs index 647f5b24..bf4de4b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ //! use std::path::PathBuf; //! //! fn main() { -//! let mut md = MDBook::new("my-book"); +//! let mut md = MDBook::load("my-book").unwrap(); //! //! // tweak the book configuration a bit //! md.config.book.src = PathBuf::from("source"); @@ -52,7 +52,8 @@ //! # fn main() { //! # let your_renderer = HtmlHandlebars::new(); //! # -//! let book = MDBook::new("my-book").set_renderer(Box::new(your_renderer)); +//! let mut book = MDBook::load("my-book").unwrap(); +//! book.set_renderer(your_renderer); //! # } //! ``` //! If you make a renderer, you get the book constructed in form of `Vec` and you get diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 342aef76..810ba766 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -9,7 +9,7 @@ use theme::{Theme, playpen_editor}; use errors::*; use regex::{Captures, Regex}; -use std::ascii::AsciiExt; +#[allow(unused_imports)] use std::ascii::AsciiExt; use std::path::{Path, PathBuf}; use std::fs::{self, File}; use std::io::{self, Read}; diff --git a/tests/dummy_book/src/SUMMARY.md b/tests/dummy_book/src/SUMMARY.md index f5f3a4c4..350b6440 100644 --- a/tests/dummy_book/src/SUMMARY.md +++ b/tests/dummy_book/src/SUMMARY.md @@ -6,4 +6,6 @@ - [Nested Chapter](./first/nested.md) - [Second Chapter](./second.md) +--- + [Conclusion](./conclusion.md) diff --git a/tests/init.rs b/tests/init.rs index 56faf6bb..be3fc603 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -46,7 +46,7 @@ fn run_mdbook_init_with_custom_book_and_src_locations() { cfg.book.src = PathBuf::from("in"); cfg.build.build_dir = PathBuf::from("out"); - let mut md = MDBook::init(temp.path()).with_config(cfg).build().unwrap(); + MDBook::init(temp.path()).with_config(cfg).build().unwrap(); for file in &created_files { let target = temp.path().join(file); diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index a68031ca..0fcd07a5 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -61,10 +61,10 @@ fn make_sure_bottom_level_files_contain_links_to_chapters() { let dest = temp.path().join("book"); let links = vec![ r#"href="intro.html""#, - r#"href="./first/index.html""#, - r#"href="./first/nested.html""#, - r#"href="./second.html""#, - r#"href="./conclusion.html""#, + r#"href="first/index.html""#, + r#"href="first/nested.html""#, + r#"href="second.html""#, + r#"href="conclusion.html""#, ]; let files_in_bottom_dir = vec!["index.html", "intro.html", "second.html", "conclusion.html"]; @@ -84,10 +84,10 @@ fn check_correct_cross_links_in_nested_dir() { let links = vec![ r#""#, r#"href="intro.html""#, - r#"href="./first/index.html""#, - r#"href="./first/nested.html""#, - r#"href="./second.html""#, - r#"href="./conclusion.html""#, + r#"href="first/index.html""#, + r#"href="first/nested.html""#, + r#"href="second.html""#, + r#"href="conclusion.html""#, ]; let files_in_nested_dir = vec!["index.html", "nested.html"]; @@ -99,14 +99,14 @@ fn check_correct_cross_links_in_nested_dir() { assert_contains_strings( first.join("index.html"), &[ - r##"href="./first/index.html#some-section" id="some-section""##, + r##"href="first/index.html#some-section" id="some-section""##, ], ); assert_contains_strings( first.join("nested.html"), &[ - r##"href="./first/nested.html#some-section" id="some-section""##, + r##"href="first/nested.html#some-section" id="some-section""##, ], ); }