Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Book representation - Attempt 3 #491

Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4c6c696
Copied across the summary parser and Book structure (doesn't compile)
Michael-F-Bryan Nov 18, 2017
cafb8b7
The library not compiles (probably completely broken)
Michael-F-Bryan Nov 18, 2017
47eb478
Introduced the `BookBuilder`.
Michael-F-Bryan Nov 18, 2017
8b21da9
Fleshed out book creation
Michael-F-Bryan Nov 18, 2017
2149863
Made sure the dummy book can build
Michael-F-Bryan Nov 18, 2017
f993677
All tests finally pass!
Michael-F-Bryan Nov 18, 2017
527fc5c
Completely removed the `create_missing` option from MDBook
Michael-F-Bryan Nov 18, 2017
751da4f
Added a test to make sure you can include rust files in chapters
Michael-F-Bryan Nov 18, 2017
12d1ed5
The example book renders correctly
Michael-F-Bryan Dec 4, 2017
9950f69
Removed the `MDBook::read_config()` method because it's redundant now
Michael-F-Bryan Dec 10, 2017
ace0b51
Put the `create_missing` feature back in
Michael-F-Bryan Dec 10, 2017
be4654c
Fleshed out the docs for the book module
Michael-F-Bryan Dec 11, 2017
1b51cd2
Moved the book examples to the top level lib.rs
Michael-F-Bryan Dec 11, 2017
ebcf41c
Improved error messages using error_chain::ChainedError::display_chain()
Michael-F-Bryan Dec 11, 2017
4f4e86d
Added tests to make sure we parse existing SUMMARY.md's
Michael-F-Bryan Dec 11, 2017
f5e9b85
Rewrote summary parser from a state machine to use recursive descent
Michael-F-Bryan Dec 11, 2017
148511e
Able to parse all existing SUMMARY.md files
Michael-F-Bryan Dec 11, 2017
ff9e0b0
Made sure create_missing also creates the parent directory
Michael-F-Bryan Dec 11, 2017
5041359
Updated the pulldown-cmark patch in Cargo.toml
Michael-F-Bryan Dec 11, 2017
75dac15
Fixed a couple issues with the docs
Michael-F-Bryan Dec 11, 2017
a46e2e2
Merge branch 'master' into book-representation-3
Michael-F-Bryan Dec 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed the MDBook::read_config() method because it's redundant now
Michael-F-Bryan committed Dec 10, 2017

Verified

This commit was signed with the committer’s verified signature.
Michael-F-Bryan Michael Bryan
commit 9950f69c48a25b77e6ae373517365d59422da89d
20 changes: 2 additions & 18 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
@@ -123,24 +123,6 @@ impl MDBook {
.map_err(|e| e.into())
}

/// Parses the `book.json` file (if it exists) to extract
/// the configuration parameters.
/// The `book.json` file should be in the root directory of the book.
/// The root directory is the one specified when creating a new `MDBook`
pub fn read_config(mut self) -> Result<Self> {
let config_path = self.root.join("book.toml");

if config_path.exists() {
debug!("[*] Loading the config from {}", config_path.display());
self.config = Config::from_disk(&config_path)?;
} else {
self.config = Config::default();
}

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)
@@ -155,7 +137,9 @@ impl MDBook {
.zip(library_paths.into_iter())
.flat_map(|x| vec![x.0, x.1])
.collect();

let temp_dir = TempDir::new("mdbook")?;

for item in self.iter() {
if let BookItem::Chapter(ref ch) = *item {
if !ch.path.as_os_str().is_empty() {
4 changes: 2 additions & 2 deletions tests/init.rs
Original file line number Diff line number Diff line change
@@ -62,9 +62,9 @@ fn run_mdbook_init_with_custom_book_and_src_locations() {
#[test]
fn book_toml_isnt_required() {
let temp = TempDir::new("mdbook").unwrap();
let md = MDBook::init(temp.path()).build().unwrap();
let mut md = MDBook::init(temp.path()).build().unwrap();

let _ = fs::remove_file(temp.path().join("book.toml"));

md.read_config().unwrap().build().unwrap();
md.build().unwrap();
}
17 changes: 9 additions & 8 deletions tests/rendered_output.rs
Original file line number Diff line number Diff line change
@@ -4,13 +4,12 @@ extern crate pretty_assertions;
extern crate select;
extern crate tempdir;
extern crate walkdir;
extern crate tempdir;

mod dummy_book;

use dummy_book::{assert_contains_strings, DummyBook};

use std::fs::{remove_file, File};
use std::fs;
use std::path::Path;
use std::ffi::OsStr;
use walkdir::{DirEntry, WalkDir, WalkDirIterator};
@@ -255,6 +254,7 @@ fn check_spacers() {
/// Ensure building fails if `create-missing` is false and one of the files does
/// not exist.
#[test]
#[ignore]
fn failure_on_missing_file() {
let (mut md, _temp) = create_missing_setup(false);

@@ -265,6 +265,7 @@ fn failure_on_missing_file() {

/// Ensure a missing file is created if `create-missing` is true.
#[test]
#[ignore]
fn create_missing_file_with_config() {
let (mut md, temp) = create_missing_setup(true);

@@ -277,7 +278,7 @@ fn create_missing_setup(create_missing: bool) -> (MDBook, TempDir) {
let mut md = MDBook::load(temp.path()).unwrap();

md.config.build.create_missing = create_missing;
remove_file(temp.path().join("src").join("intro.md")).unwrap();
fs::remove_file(temp.path().join("src").join("intro.md")).unwrap();

(md, temp)
}
@@ -301,10 +302,10 @@ fn able_to_include_rust_files_in_chapters() {

#[test]
fn example_book_can_build() {
let example_book_dir = dummy_book::new_copy_of_example_book().unwrap();
let example_book_dir = dummy_book::new_copy_of_example_book().unwrap();

let mut md = MDBook::load(example_book_dir.path()).unwrap();
let mut md = MDBook::load(example_book_dir.path()).unwrap();

let got = md.build();
assert!(got.is_ok());
}
let got = md.build();
assert!(got.is_ok());
}