From 1b51cd244ec2d85e58673325dc3c836a8555d47a Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Mon, 11 Dec 2017 11:29:30 +1100 Subject: [PATCH] Moved the book examples to the top level lib.rs --- src/book/mod.rs | 34 ++-------------------------------- src/lib.rs | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 557dc713..5116e175 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -1,39 +1,9 @@ //! The internal representation of a book and infrastructure for loading it from //! disk and building it. //! -//! # Examples +//! For examples on using `MDBook`, consult the [top-level documentation][1]. //! -//! If creating a new book from scratch, you'll want to get a `BookBuilder` via -//! the `MDBook::init()` method. -//! -//! ```rust,no_run -//! use mdbook::MDBook; -//! use mdbook::config::Config; -//! -//! let root_dir = "/path/to/book/root"; -//! -//! let mut cfg = Config::default(); -//! cfg.book.title = Some("My Book".to_string()); -//! cfg.book.authors.push("Michael-F-Bryan".to_string()); -//! -//! MDBook::init(root_dir) -//! .create_gitignore(true) -//! .with_config(cfg) -//! .build() -//! .expect("Book generation failed"); -//! ``` -//! -//! You can also load an existing book and build it. -//! -//! ```rust,no_run -//! use mdbook::MDBook; -//! -//! let root_dir = "/path/to/book/root"; -//! -//! let mut md = MDBook::load(root_dir) -//! .expect("Unable to load the book"); -//! md.build().expect("Building failed"); -//! ``` +//! [1]: ../index.html #![deny(missing_docs)] diff --git a/src/lib.rs b/src/lib.rs index bf4de4b5..450e7e9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,24 +15,39 @@ //! - Write a new Renderer //! - ... //! -//! ## Example +//! # Examples //! -//! ```no_run -//! extern crate mdbook; +//! If creating a new book from scratch, you'll want to get a `BookBuilder` via +//! the `MDBook::init()` method. //! +//! ```rust,no_run //! use mdbook::MDBook; -//! use std::path::PathBuf; +//! use mdbook::config::Config; //! -//! fn main() { -//! let mut md = MDBook::load("my-book").unwrap(); +//! let root_dir = "/path/to/book/root"; //! -//! // tweak the book configuration a bit -//! md.config.book.src = PathBuf::from("source"); -//! md.config.build.build_dir = PathBuf::from("book"); -//! -//! // Render the book -//! md.build().unwrap(); -//! } +//! // create a default config and change a couple things +//! let mut cfg = Config::default(); +//! cfg.book.title = Some("My Book".to_string()); +//! cfg.book.authors.push("Michael-F-Bryan".to_string()); +//! +//! MDBook::init(root_dir) +//! .create_gitignore(true) +//! .with_config(cfg) +//! .build() +//! .expect("Book generation failed"); +//! ``` +//! +//! You can also load an existing book and build it. +//! +//! ```rust,no_run +//! use mdbook::MDBook; +//! +//! let root_dir = "/path/to/book/root"; +//! +//! let mut md = MDBook::load(root_dir) +//! .expect("Unable to load the book"); +//! md.build().expect("Building failed"); //! ``` //! //! ## Implementing a new Renderer