Skip to content

Commit

Permalink
Merge pull request rust-lang#883 from anp/custom_summary
Browse files Browse the repository at this point in the history
Expose API for building a book with a custom Summary.
  • Loading branch information
Dylan-DPC authored Apr 29, 2019
2 parents 0488da0 + ce22978 commit 931fe7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/book/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Chapter {
///
/// You need to pass in the book's source directory because all the links in
/// `SUMMARY.md` give the chapter locations relative to it.
fn load_book_from_disk<P: AsRef<Path>>(summary: &Summary, src_dir: P) -> Result<Book> {
pub(crate) fn load_book_from_disk<P: AsRef<Path>>(summary: &Summary, src_dir: P) -> Result<Book> {
debug!("Loading the book from disk");
let src_dir = src_dir.as_ref();

Expand Down
23 changes: 23 additions & 0 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ impl MDBook {
})
}

/// Load a book from its root directory using a custom config and a custom summary.
pub fn load_with_config_and_summary<P: Into<PathBuf>>(
book_root: P,
config: Config,
summary: Summary
) -> Result<MDBook> {
let root = book_root.into();

let src_dir = root.join(&config.book.src);
let book = book::load_book_from_disk(&summary, &src_dir)?;

let renderers = determine_renderers(&config);
let preprocessors = determine_preprocessors(&config)?;

Ok(MDBook {
root,
config,
book,
renderers,
preprocessors,
})
}

/// Returns a flat depth-first iterator over the elements of the book,
/// it returns an [BookItem enum](bookitem.html):
/// `(section: String, bookitem: &BookItem)`
Expand Down

0 comments on commit 931fe7d

Please sign in to comment.