2017-05-18 19:32:08 +02:00
|
|
|
extern crate toml;
|
|
|
|
|
use std::path::PathBuf;
|
2017-06-24 23:53:08 +08:00
|
|
|
use errors::*;
|
2017-05-18 19:32:08 +02:00
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
|
|
|
pub struct TomlConfig {
|
|
|
|
|
pub source: Option<PathBuf>,
|
|
|
|
|
|
|
|
|
|
pub title: Option<String>,
|
|
|
|
|
pub author: Option<String>,
|
|
|
|
|
pub authors: Option<Vec<String>>,
|
|
|
|
|
pub description: Option<String>,
|
|
|
|
|
|
|
|
|
|
pub output: Option<TomlOutputConfig>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
|
|
|
pub struct TomlOutputConfig {
|
|
|
|
|
pub html: Option<TomlHtmlConfig>,
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 00:56:37 +02:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
2017-05-18 19:32:08 +02:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
|
|
|
pub struct TomlHtmlConfig {
|
|
|
|
|
pub destination: Option<PathBuf>,
|
|
|
|
|
pub theme: Option<PathBuf>,
|
|
|
|
|
pub google_analytics: Option<String>,
|
2017-05-31 22:28:08 -07:00
|
|
|
pub curly_quotes: Option<bool>,
|
2017-06-25 00:32:26 +02:00
|
|
|
pub mathjax_support: Option<bool>,
|
2017-05-20 13:56:01 +02:00
|
|
|
pub additional_css: Option<Vec<PathBuf>>,
|
2017-06-06 20:34:57 +02:00
|
|
|
pub additional_js: Option<Vec<PathBuf>>,
|
2017-06-29 00:35:20 -04:00
|
|
|
pub playpen: Option<TomlPlaypenConfig>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
|
|
|
pub struct TomlPlaypenConfig {
|
|
|
|
|
pub editor: Option<PathBuf>,
|
|
|
|
|
pub editable: Option<bool>,
|
2017-05-18 19:32:08 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-27 09:08:58 +02:00
|
|
|
/// Returns a `TomlConfig` from a TOML string
|
2017-05-18 19:32:08 +02:00
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// # use mdbook::config::tomlconfig::TomlConfig;
|
|
|
|
|
/// # use std::path::PathBuf;
|
|
|
|
|
/// let toml = r#"title="Some title"
|
|
|
|
|
/// [output.html]
|
|
|
|
|
/// destination = "htmlbook" "#;
|
2017-10-03 17:25:23 +05:45
|
|
|
///
|
2017-05-18 19:32:08 +02:00
|
|
|
/// 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 {
|
2017-06-24 23:53:08 +08:00
|
|
|
pub fn from_toml(input: &str) -> Result<Self> {
|
2017-10-03 17:25:23 +05:45
|
|
|
let config: TomlConfig = toml::from_str(input).chain_err(|| "Could not parse TOML")?;
|
|
|
|
|
|
2017-06-27 09:08:58 +02:00
|
|
|
Ok(config)
|
2017-05-18 19:32:08 +02:00
|
|
|
}
|
|
|
|
|
}
|