Removed the now redundant config files

This commit is contained in:
Michael Bryan 2017-09-30 21:56:22 +08:00
parent cee3296a32
commit 1743f2a39f
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
6 changed files with 0 additions and 587 deletions

View File

@ -7,18 +7,6 @@ use serde::Deserialize;
use errors::*; use errors::*;
// pub mod bookconfig;
// pub mod htmlconfig;
// pub mod playpenconfig;
// pub mod tomlconfig;
// pub mod jsonconfig;
// Re-export the config structs
// pub use self::bookconfig::BookConfig;
// pub use self::htmlconfig::HtmlConfig;
// pub use self::playpenconfig::PlaypenConfig;
// pub use self::tomlconfig::TomlConfig;
/// The overall configuration object for MDBook. /// The overall configuration object for MDBook.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]

View File

@ -1,226 +0,0 @@
use std::path::{Path, PathBuf};
use super::HtmlConfig;
use super::tomlconfig::TomlConfig;
use super::jsonconfig::JsonConfig;
/// Configuration struct containing all the configuration options available in mdBook.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BookConfig {
root: PathBuf,
source: PathBuf,
title: String,
authors: Vec<String>,
description: String,
multilingual: bool,
indent_spaces: i32,
html_config: HtmlConfig,
}
impl BookConfig {
/// Creates a new `BookConfig` struct with as root path the path given as parameter.
/// The source directory is `root/src` and the destination for the rendered book is `root/book`.
///
/// ```
/// # use std::path::PathBuf;
/// # use mdbook::config::{BookConfig, HtmlConfig};
/// #
/// let root = PathBuf::from("directory/to/my/book");
/// let config = BookConfig::new(&root);
///
/// assert_eq!(config.get_root(), &root);
/// assert_eq!(config.get_source(), PathBuf::from("directory/to/my/book/src"));
/// assert_eq!(config.get_html_config(),
/// &HtmlConfig::new(PathBuf::from("directory/to/my/book")));
/// ```
pub fn new<T: Into<PathBuf>>(root: T) -> Self {
let root: PathBuf = root.into();
let htmlconfig = HtmlConfig::new(&root);
BookConfig {
root: root.clone(),
source: root.join("src"),
title: String::new(),
authors: Vec::new(),
description: String::new(),
multilingual: false,
indent_spaces: 4,
html_config: htmlconfig,
}
}
/// Builder method to set the source directory
pub fn with_source<T: Into<PathBuf>>(mut self, source: T) -> Self {
self.source = source.into();
self
}
/// Builder method to set the book's title
pub fn with_title<T: Into<String>>(mut self, title: T) -> Self {
self.title = title.into();
self
}
/// Builder method to set the book's description
pub fn with_description<T: Into<String>>(mut self, description: T) -> Self {
self.description = description.into();
self
}
/// Builder method to set the book's authors
pub fn with_authors<T: Into<Vec<String>>>(mut self, authors: T) -> Self {
self.authors = authors.into();
self
}
pub fn from_tomlconfig<T: Into<PathBuf>>(root: T, tomlconfig: TomlConfig) -> Self {
let root = root.into();
let mut config = BookConfig::new(&root);
config.fill_from_tomlconfig(tomlconfig);
config
}
pub fn fill_from_tomlconfig(&mut self, tomlconfig: TomlConfig) -> &mut Self {
if let Some(s) = tomlconfig.source {
self.set_source(s);
}
if let Some(t) = tomlconfig.title {
self.set_title(t);
}
if let Some(d) = tomlconfig.description {
self.set_description(d);
}
if let Some(a) = tomlconfig.authors {
self.set_authors(a);
}
if let Some(a) = tomlconfig.author {
self.set_authors(vec![a]);
}
if let Some(tomlhtmlconfig) = tomlconfig.output.and_then(|o| o.html) {
let root = self.root.clone();
self.get_mut_html_config()
.fill_from_tomlconfig(root, tomlhtmlconfig);
}
self
}
/// The JSON configuration file is **deprecated** and should not be used anymore.
/// Please, migrate to the TOML configuration file.
pub fn from_jsonconfig<T: Into<PathBuf>>(root: T, jsonconfig: JsonConfig) -> Self {
let root = root.into();
let mut config = BookConfig::new(&root);
config.fill_from_jsonconfig(jsonconfig);
config
}
/// The JSON configuration file is **deprecated** and should not be used anymore.
/// Please, migrate to the TOML configuration file.
pub fn fill_from_jsonconfig(&mut self, jsonconfig: JsonConfig) -> &mut Self {
if let Some(s) = jsonconfig.src {
self.set_source(s);
}
if let Some(t) = jsonconfig.title {
self.set_title(t);
}
if let Some(d) = jsonconfig.description {
self.set_description(d);
}
if let Some(a) = jsonconfig.author {
self.set_authors(vec![a]);
}
if let Some(d) = jsonconfig.dest {
let root = self.get_root().to_owned();
self.get_mut_html_config().set_destination(&root, &d);
}
if let Some(d) = jsonconfig.theme_path {
let root = self.get_root().to_owned();
self.get_mut_html_config().set_theme(&root, &d);
}
self
}
pub fn set_root<T: Into<PathBuf>>(&mut self, root: T) -> &mut Self {
self.root = root.into();
self
}
pub fn get_root(&self) -> &Path {
&self.root
}
pub fn set_source<T: Into<PathBuf>>(&mut self, source: T) -> &mut Self {
let mut source = source.into();
// If the source path is relative, start with the root path
if source.is_relative() {
source = self.root.join(source);
}
self.source = source;
self
}
pub fn get_source(&self) -> &Path {
&self.source
}
pub fn set_title<T: Into<String>>(&mut self, title: T) -> &mut Self {
self.title = title.into();
self
}
pub fn get_title(&self) -> &str {
&self.title
}
pub fn set_description<T: Into<String>>(&mut self, description: T) -> &mut Self {
self.description = description.into();
self
}
pub fn get_description(&self) -> &str {
&self.description
}
pub fn set_authors<T: Into<Vec<String>>>(&mut self, authors: T) -> &mut Self {
self.authors = authors.into();
self
}
/// Returns the authors of the book as specified in the configuration file
pub fn get_authors(&self) -> &[String] {
self.authors.as_slice()
}
pub fn set_html_config(&mut self, htmlconfig: HtmlConfig) -> &mut Self {
self.html_config = htmlconfig;
self
}
/// Returns the configuration for the HTML renderer or None of there isn't any
pub fn get_html_config(&self) -> &HtmlConfig {
&self.html_config
}
pub fn get_mut_html_config(&mut self) -> &mut HtmlConfig {
&mut self.html_config
}
}

View File

@ -1,177 +0,0 @@
use std::path::{Path, PathBuf};
use super::tomlconfig::TomlHtmlConfig;
use super::playpenconfig::PlaypenConfig;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct HtmlConfig {
destination: PathBuf,
theme: PathBuf,
curly_quotes: bool,
mathjax_support: bool,
google_analytics: Option<String>,
additional_css: Vec<PathBuf>,
additional_js: Vec<PathBuf>,
playpen: PlaypenConfig,
}
impl HtmlConfig {
/// Creates a new `HtmlConfig` struct containing
/// the configuration parameters for the HTML renderer.
///
/// ```
/// # use std::path::PathBuf;
/// # use mdbook::config::HtmlConfig;
/// #
/// let output = PathBuf::from("root/book");
/// let config = HtmlConfig::new(PathBuf::from("root"));
///
/// assert_eq!(config.get_destination(), &output);
/// ```
pub fn new<T: Into<PathBuf>>(root: T) -> Self {
let root = root.into();
let theme = root.join("theme");
HtmlConfig {
destination: root.clone().join("book"),
theme: theme.clone(),
curly_quotes: false,
mathjax_support: false,
google_analytics: None,
additional_css: Vec::new(),
additional_js: Vec::new(),
playpen: PlaypenConfig::new(theme),
}
}
pub fn fill_from_tomlconfig<T: Into<PathBuf>>(&mut self,
root: T,
tomlconfig: TomlHtmlConfig)
-> &mut Self {
let root = root.into();
if let Some(d) = tomlconfig.destination {
self.set_destination(&root, &d);
}
if let Some(t) = tomlconfig.theme {
self.set_theme(&root, &t);
}
if let Some(curly_quotes) = tomlconfig.curly_quotes {
self.curly_quotes = curly_quotes;
}
if let Some(mathjax_support) = tomlconfig.mathjax_support {
self.mathjax_support = mathjax_support;
}
if tomlconfig.google_analytics.is_some() {
self.google_analytics = tomlconfig.google_analytics;
}
if let Some(stylepaths) = tomlconfig.additional_css {
for path in stylepaths {
if path.is_relative() {
self.additional_css.push(root.join(path));
} else {
self.additional_css.push(path);
}
}
}
if let Some(scriptpaths) = tomlconfig.additional_js {
for path in scriptpaths {
if path.is_relative() {
self.additional_js.push(root.join(path));
} else {
self.additional_js.push(path);
}
}
}
if let Some(playpen) = tomlconfig.playpen {
self.playpen.fill_from_tomlconfig(&self.theme, playpen);
}
self
}
pub fn set_destination<T: Into<PathBuf>>(&mut self, root: T, destination: T) -> &mut Self {
let d = destination.into();
if d.is_relative() {
self.destination = root.into().join(d);
} else {
self.destination = d;
}
self
}
pub fn get_destination(&self) -> &Path {
&self.destination
}
pub fn get_theme(&self) -> &Path {
&self.theme
}
pub fn set_theme<T: Into<PathBuf>>(&mut self, root: T, theme: T) -> &mut Self {
let d = theme.into();
if d.is_relative() {
self.theme = root.into().join(d);
} else {
self.theme = d;
}
self
}
pub fn get_curly_quotes(&self) -> bool {
self.curly_quotes
}
pub fn set_curly_quotes(&mut self, curly_quotes: bool) {
self.curly_quotes = curly_quotes;
}
pub fn get_mathjax_support(&self) -> bool {
self.mathjax_support
}
pub fn set_mathjax_support(&mut self, mathjax_support: bool) {
self.mathjax_support = mathjax_support;
}
pub fn get_google_analytics_id(&self) -> Option<String> {
self.google_analytics.clone()
}
pub fn set_google_analytics_id(&mut self, id: Option<String>) -> &mut Self {
self.google_analytics = id;
self
}
pub fn has_additional_css(&self) -> bool {
!self.additional_css.is_empty()
}
pub fn get_additional_css(&self) -> &[PathBuf] {
&self.additional_css
}
pub fn has_additional_js(&self) -> bool {
!self.additional_js.is_empty()
}
pub fn get_additional_js(&self) -> &[PathBuf] {
&self.additional_js
}
pub fn get_playpen_config(&self) -> &PlaypenConfig {
&self.playpen
}
pub fn get_mut_playpen_config(&mut self) -> &mut PlaypenConfig {
&mut self.playpen
}
}

View File

@ -1,41 +0,0 @@
extern crate serde_json;
use std::path::PathBuf;
use errors::*;
/// The JSON configuration is **deprecated** and will be removed in the near future.
/// Please migrate to the TOML configuration.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct JsonConfig {
pub src: Option<PathBuf>,
pub dest: Option<PathBuf>,
pub title: Option<String>,
pub author: Option<String>,
pub description: Option<String>,
pub theme_path: Option<PathBuf>,
pub google_analytics: Option<String>,
}
/// Returns a `JsonConfig` from a JSON string
///
/// ```
/// # use mdbook::config::jsonconfig::JsonConfig;
/// # use std::path::PathBuf;
/// let json = r#"{
/// "title": "Some title",
/// "dest": "htmlbook"
/// }"#;
///
/// let config = JsonConfig::from_json(&json).expect("Should parse correctly");
/// assert_eq!(config.title, Some(String::from("Some title")));
/// assert_eq!(config.dest, Some(PathBuf::from("htmlbook")));
/// ```
impl JsonConfig {
pub fn from_json(input: &str) -> Result<Self> {
let config: JsonConfig = serde_json::from_str(input).chain_err(|| "Could not parse JSON")?;
Ok(config)
}
}

View File

@ -1,71 +0,0 @@
use std::path::{Path, PathBuf};
use super::tomlconfig::TomlPlaypenConfig;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PlaypenConfig {
editor: PathBuf,
editable: bool,
}
impl PlaypenConfig {
/// Creates a new `PlaypenConfig` for playpen configuration.
///
/// ```
/// # use std::path::PathBuf;
/// # use mdbook::config::PlaypenConfig;
/// #
/// let editor = PathBuf::from("root/editor");
/// let config = PlaypenConfig::new(PathBuf::from("root"));
///
/// assert_eq!(config.get_editor(), &editor);
/// assert_eq!(config.is_editable(), false);
/// ```
pub fn new<T: Into<PathBuf>>(root: T) -> Self {
PlaypenConfig {
editor: root.into().join("editor"),
editable: false,
}
}
pub fn fill_from_tomlconfig<T: Into<PathBuf>>(&mut self,
root: T,
tomlplaypenconfig: TomlPlaypenConfig)
-> &mut Self {
let root = root.into();
if let Some(editor) = tomlplaypenconfig.editor {
if editor.is_relative() {
self.editor = root.join(editor);
} else {
self.editor = editor;
}
}
if let Some(editable) = tomlplaypenconfig.editable {
self.editable = editable;
}
self
}
pub fn is_editable(&self) -> bool {
self.editable
}
pub fn get_editor(&self) -> &Path {
&self.editor
}
pub fn set_editor<T: Into<PathBuf>>(&mut self, root: T, editor: T) -> &mut Self {
let editor = editor.into();
if editor.is_relative() {
self.editor = root.into().join(editor);
} else {
self.editor = editor;
}
self
}
}

View File

@ -1,60 +0,0 @@
extern crate toml;
use std::path::PathBuf;
use errors::*;
#[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>,
}
#[serde(rename_all = "kebab-case")]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct TomlHtmlConfig {
pub destination: Option<PathBuf>,
pub theme: Option<PathBuf>,
pub google_analytics: Option<String>,
pub curly_quotes: Option<bool>,
pub mathjax_support: Option<bool>,
pub additional_css: Option<Vec<PathBuf>>,
pub additional_js: Option<Vec<PathBuf>>,
pub playpen: Option<TomlPlaypenConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct TomlPlaypenConfig {
pub editor: Option<PathBuf>,
pub editable: Option<bool>,
}
/// 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<Self> {
let config: TomlConfig = toml::from_str(input).chain_err(|| "Could not parse TOML")?;
Ok(config)
}
}