All tests finally pass!

This commit is contained in:
Michael Bryan 2017-11-18 22:16:35 +08:00
parent 21498631b3
commit f993677626
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
6 changed files with 24 additions and 42 deletions

View File

@ -61,11 +61,11 @@ impl MDBook {
/// # use mdbook::book::BookItem; /// # use mdbook::book::BookItem;
/// # #[allow(unused_variables)] /// # #[allow(unused_variables)]
/// # fn main() { /// # fn main() {
/// # let book = MDBook::new("mybook"); /// # let book = MDBook::load("mybook").unwrap();
/// for item in book.iter() { /// for item in book.iter() {
/// match *item { /// match *item {
/// BookItem::Chapter(ref chapter) => {}, /// BookItem::Chapter(ref chapter) => {},
/// BookItem::Spacer => {}, /// BookItem::Separator => {},
/// } /// }
/// } /// }
/// ///
@ -140,32 +140,11 @@ impl MDBook {
Ok(self) Ok(self)
} }
/// You can change the default renderer to another one /// You can change the default renderer to another one by using this method.
/// by using this method. The only requirement /// The only requirement is for your renderer to implement the [Renderer
/// is for your renderer to implement the /// trait](../../renderer/renderer/trait.Renderer.html)
/// [Renderer trait](../../renderer/renderer/trait.Renderer.html) pub fn set_renderer<R: Renderer + 'static>(mut self, renderer: R) -> Self {
/// self.renderer = Box::new(renderer);
/// ```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<Renderer>) -> Self {
self.renderer = renderer;
self self
} }

View File

@ -24,7 +24,7 @@
//! use std::path::PathBuf; //! use std::path::PathBuf;
//! //!
//! fn main() { //! fn main() {
//! let mut md = MDBook::new("my-book"); //! let mut md = MDBook::load("my-book").unwrap();
//! //!
//! // tweak the book configuration a bit //! // tweak the book configuration a bit
//! md.config.book.src = PathBuf::from("source"); //! md.config.book.src = PathBuf::from("source");
@ -52,7 +52,8 @@
//! # fn main() { //! # fn main() {
//! # let your_renderer = HtmlHandlebars::new(); //! # 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<BookItems>` and you get //! If you make a renderer, you get the book constructed in form of `Vec<BookItems>` and you get

View File

@ -9,7 +9,7 @@ use theme::{Theme, playpen_editor};
use errors::*; use errors::*;
use regex::{Captures, Regex}; use regex::{Captures, Regex};
use std::ascii::AsciiExt; #[allow(unused_imports)] use std::ascii::AsciiExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{self, Read}; use std::io::{self, Read};

View File

@ -6,4 +6,6 @@
- [Nested Chapter](./first/nested.md) - [Nested Chapter](./first/nested.md)
- [Second Chapter](./second.md) - [Second Chapter](./second.md)
---
[Conclusion](./conclusion.md) [Conclusion](./conclusion.md)

View File

@ -46,7 +46,7 @@ fn run_mdbook_init_with_custom_book_and_src_locations() {
cfg.book.src = PathBuf::from("in"); cfg.book.src = PathBuf::from("in");
cfg.build.build_dir = PathBuf::from("out"); 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 { for file in &created_files {
let target = temp.path().join(file); let target = temp.path().join(file);

View File

@ -61,10 +61,10 @@ fn make_sure_bottom_level_files_contain_links_to_chapters() {
let dest = temp.path().join("book"); let dest = temp.path().join("book");
let links = vec![ let links = vec![
r#"href="intro.html""#, r#"href="intro.html""#,
r#"href="./first/index.html""#, r#"href="first/index.html""#,
r#"href="./first/nested.html""#, r#"href="first/nested.html""#,
r#"href="./second.html""#, r#"href="second.html""#,
r#"href="./conclusion.html""#, r#"href="conclusion.html""#,
]; ];
let files_in_bottom_dir = vec!["index.html", "intro.html", "second.html", "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![ let links = vec![
r#"<base href="../">"#, r#"<base href="../">"#,
r#"href="intro.html""#, r#"href="intro.html""#,
r#"href="./first/index.html""#, r#"href="first/index.html""#,
r#"href="./first/nested.html""#, r#"href="first/nested.html""#,
r#"href="./second.html""#, r#"href="second.html""#,
r#"href="./conclusion.html""#, r#"href="conclusion.html""#,
]; ];
let files_in_nested_dir = vec!["index.html", "nested.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( assert_contains_strings(
first.join("index.html"), 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( assert_contains_strings(
first.join("nested.html"), first.join("nested.html"),
&[ &[
r##"href="./first/nested.html#some-section" id="some-section""##, r##"href="first/nested.html#some-section" id="some-section""##,
], ],
); );
} }