Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 7 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,17 @@ impl<'de> Deserialize<'de> for Config {

impl Serialize for Config {
fn serialize<S: Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> {
use serde::ser::Error;
// TODO: This should probably be removed and use a derive instead.

let mut table = self.rest.clone();

let book_config = match Value::try_from(self.book.clone()) {
Ok(cfg) => cfg,
Err(_) => {
return Err(S::Error::custom("Unable to serialize the BookConfig"));
}
};
let rust_config = Value::try_from(&self.rust).expect("should always be serializable");

let book_config = Value::try_from(&self.book).expect("should always be serializable");
table.insert("book", book_config);
table.insert("rust", rust_config);

if self.rust != RustConfig::default() {
let rust_config = Value::try_from(&self.rust).expect("should always be serializable");
table.insert("rust", rust_config);
}

table.serialize(s)
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ fn base_mdbook_init_should_create_default_content() {
println!("{}", target.display());
assert!(target.exists(), "{} doesn't exist", file);
}

let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap();
assert_eq!(
contents,
"[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"src\"\n"
);
}

/// Run `mdbook init` in a directory containing a SUMMARY.md should create the
Expand Down