extern crate toml; use std::path::PathBuf; use errors::*; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlConfig { pub source: Option, pub title: Option, pub author: Option, pub authors: Option>, pub description: Option, pub output: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlOutputConfig { pub html: Option, } #[serde(rename_all = "kebab-case")] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlHtmlConfig { pub destination: Option, pub theme: Option, pub google_analytics: Option, pub curly_quotes: Option, pub mathjax_support: Option, pub additional_css: Option>, pub additional_js: Option>, pub playpen: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlPlaypenConfig { pub editor: Option, pub editable: Option, } /// Returns a `TomlConfig` from a TOML string /// /// ``` /// # use mdbook::config::tomlconfig::TomlConfig; /// # use std::path::PathBuf; /// let toml = r#"title="Some title" /// [output.html] /// destination = "htmlbook" "#; /// /// let config = TomlConfig::from_toml(&toml).expect("Should parse correctly"); /// assert_eq!(config.title, Some(String::from("Some title"))); /// assert_eq!(config.output.unwrap().html.unwrap().destination, Some(PathBuf::from("htmlbook"))); /// ``` impl TomlConfig { pub fn from_toml(input: &str) -> Result { let config: TomlConfig = toml::from_str(input).chain_err(|| "Could not parse TOML")?; Ok(config) } }