summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2021-11-28 16:37:04 +0100
committerMinijackson <minijackson@riseup.net>2021-11-28 16:37:04 +0100
commit6e133b25e02edba228c488a4239334885b5ebc85 (patch)
tree4c83e59278b2aea2951bf16586feeec19516df50
parente1d7691ebd38e27b14f2549e01e59c08ea84d821 (diff)
downloadpandoc-docbook-6e133b25e02edba228c488a4239334885b5ebc85.tar.gz
pandoc-docbook-6e133b25e02edba228c488a4239334885b5ebc85.zip
config: add way for setting pandoc default optionsHEADmaster
and update Cargo.lock
-rw-r--r--Cargo.lock21
-rw-r--r--Cargo.toml1
-rw-r--r--src/build.rs13
-rw-r--r--src/config.rs30
4 files changed, 41 insertions, 24 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 81f5135..57fb5a0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -72,9 +72,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
72 72
73[[package]] 73[[package]]
74name = "cc" 74name = "cc"
75version = "1.0.71" 75version = "1.0.72"
76source = "registry+https://github.com/rust-lang/crates.io-index" 76source = "registry+https://github.com/rust-lang/crates.io-index"
77checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" 77checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
78 78
79[[package]] 79[[package]]
80name = "cfg-if" 80name = "cfg-if"
@@ -284,9 +284,9 @@ dependencies = [
284 284
285[[package]] 285[[package]]
286name = "libc" 286name = "libc"
287version = "0.2.106" 287version = "0.2.108"
288source = "registry+https://github.com/rust-lang/crates.io-index" 288source = "registry+https://github.com/rust-lang/crates.io-index"
289checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" 289checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
290 290
291[[package]] 291[[package]]
292name = "linked-hash-map" 292name = "linked-hash-map"
@@ -380,9 +380,9 @@ checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55"
380 380
381[[package]] 381[[package]]
382name = "pandoc" 382name = "pandoc"
383version = "0.8.6" 383version = "0.8.8"
384source = "registry+https://github.com/rust-lang/crates.io-index" 384source = "registry+https://github.com/rust-lang/crates.io-index"
385checksum = "8c5ab1abdd81ed62e852d412d18964925e42c8f154c61e89c6296b1a06b6daeb" 385checksum = "0eac785b7de8de25c5ec48b3a9df1be552de03906f99145ed6d7da3d696c0dbb"
386dependencies = [ 386dependencies = [
387 "itertools", 387 "itertools",
388] 388]
@@ -401,6 +401,7 @@ dependencies = [
401 "pandoc", 401 "pandoc",
402 "pandoc_ast", 402 "pandoc_ast",
403 "serde 1.0.130", 403 "serde 1.0.130",
404 "serde_json",
404 "tempfile", 405 "tempfile",
405] 406]
406 407
@@ -601,9 +602,9 @@ dependencies = [
601 602
602[[package]] 603[[package]]
603name = "serde_json" 604name = "serde_json"
604version = "1.0.69" 605version = "1.0.72"
605source = "registry+https://github.com/rust-lang/crates.io-index" 606source = "registry+https://github.com/rust-lang/crates.io-index"
606checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8" 607checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527"
607dependencies = [ 608dependencies = [
608 "itoa", 609 "itoa",
609 "ryu", 610 "ryu",
@@ -633,9 +634,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
633 634
634[[package]] 635[[package]]
635name = "syn" 636name = "syn"
636version = "1.0.81" 637version = "1.0.82"
637source = "registry+https://github.com/rust-lang/crates.io-index" 638source = "registry+https://github.com/rust-lang/crates.io-index"
638checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" 639checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
639dependencies = [ 640dependencies = [
640 "proc-macro2", 641 "proc-macro2",
641 "quote", 642 "quote",
diff --git a/Cargo.toml b/Cargo.toml
index e8783c8..bd6ae48 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,4 +20,5 @@ pandoc = "0.8"
20# TODO: change this when new version is released 20# TODO: change this when new version is released
21pandoc_ast = { git = "https://github.com/oli-obk/pandoc-ast", rev = "d73a7d0a065f568d60bcee6cff2340f75065273e" } 21pandoc_ast = { git = "https://github.com/oli-obk/pandoc-ast", rev = "d73a7d0a065f568d60bcee6cff2340f75065273e" }
22serde = { version = "1", features = [ "derive" ] } 22serde = { version = "1", features = [ "derive" ] }
23serde_json = "1"
23tempfile = "3" 24tempfile = "3"
diff --git a/src/build.rs b/src/build.rs
index 1c12476..cf34e2f 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -14,12 +14,22 @@ const HTML_TEMPLATE: &str = include_str!("../res/template.html");
14 14
15pub fn do_build(config: &crate::config::Config) -> Result<()> { 15pub fn do_build(config: &crate::config::Config) -> Result<()> {
16 let tmpdir = tempfile::tempdir().wrap_err("Could not create temporary directory")?; 16 let tmpdir = tempfile::tempdir().wrap_err("Could not create temporary directory")?;
17 debug!("Created temporary directory at: '{}'", tmpdir.path().display()); 17 debug!(
18 "Created temporary directory at: '{}'",
19 tmpdir.path().display()
20 );
21
18 let template_path = tmpdir.path().join("template.html"); 22 let template_path = tmpdir.path().join("template.html");
19 trace!("Writing HTML template to: '{}'", template_path.display()); 23 trace!("Writing HTML template to: '{}'", template_path.display());
20 std::fs::write(&template_path, HTML_TEMPLATE) 24 std::fs::write(&template_path, HTML_TEMPLATE)
21 .wrap_err("Could not save HTML template in temporary directory")?; 25 .wrap_err("Could not save HTML template in temporary directory")?;
22 26
27 let defaults_path = tmpdir.path().join("defaults.yaml");
28 debug!("Generating file: '{}'", defaults_path.display());
29 let defaults =
30 std::fs::File::create(&defaults_path).wrap_err("Could not create defaults.yaml")?;
31 serde_json::to_writer(defaults, &config.pandoc).wrap_err("Could not create defaults.yaml")?;
32
23 let source_root = Path::new(&config.book.summary) 33 let source_root = Path::new(&config.book.summary)
24 .parent() 34 .parent()
25 .expect("Summary has no parent"); 35 .expect("Summary has no parent");
@@ -99,6 +109,7 @@ pub fn do_build(config: &crate::config::Config) -> Result<()> {
99 .set_output_format(pandoc::OutputFormat::Html5, vec![]) 109 .set_output_format(pandoc::OutputFormat::Html5, vec![])
100 .add_options(&[ 110 .add_options(&[
101 pandoc::PandocOption::Css(style_path.to_string()), 111 pandoc::PandocOption::Css(style_path.to_string()),
112 pandoc::PandocOption::Defaults(defaults_path.clone()),
102 pandoc::PandocOption::SectionDivs, 113 pandoc::PandocOption::SectionDivs,
103 pandoc::PandocOption::Standalone, 114 pandoc::PandocOption::Standalone,
104 pandoc::PandocOption::Template(template_path.clone()), 115 pandoc::PandocOption::Template(template_path.clone()),
diff --git a/src/config.rs b/src/config.rs
index 53922b0..9b95f9a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,3 +1,5 @@
1use std::collections::HashMap;
2
1use log::debug; 3use log::debug;
2use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
3 5
@@ -7,6 +9,21 @@ pub struct Config {
7 pub book: BookConfig, 9 pub book: BookConfig,
8 #[serde(default)] 10 #[serde(default)]
9 pub build: BuildConfig, 11 pub build: BuildConfig,
12 #[serde(default)]
13 pub pandoc: HashMap<String, serde_json::Value>,
14}
15
16impl Config {
17 pub fn new(config_file: &str) -> Result<Self, config::ConfigError> {
18 let mut s = config::Config::default();
19
20 debug!("Parsing config file: {}", config_file);
21 s.merge(config::File::with_name(config_file))?;
22 debug!("Parsing config from environment");
23 s.merge(config::Environment::with_prefix("PANDOC_DOCBOOK").separator("_"))?;
24
25 s.try_into()
26 }
10} 27}
11 28
12#[derive(Debug, Clone, Deserialize, Serialize)] 29#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -44,16 +61,3 @@ impl Default for BuildConfig {
44fn default_build_dir() -> String { 61fn default_build_dir() -> String {
45 "pdbook".to_string() 62 "pdbook".to_string()
46} 63}
47
48impl Config {
49 pub fn new(config_file: &str) -> Result<Self, config::ConfigError> {
50 let mut s = config::Config::default();
51
52 debug!("Parsing config file: {}", config_file);
53 s.merge(config::File::with_name(config_file))?;
54 debug!("Parsing config from environment");
55 s.merge(config::Environment::with_prefix("PANDOC_DOCBOOK").separator("_"))?;
56
57 s.try_into()
58 }
59}