diff options
author | Minijackson <minijackson@riseup.net> | 2021-11-28 16:37:04 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2021-11-28 16:37:04 +0100 |
commit | 6e133b25e02edba228c488a4239334885b5ebc85 (patch) | |
tree | 4c83e59278b2aea2951bf16586feeec19516df50 | |
parent | e1d7691ebd38e27b14f2549e01e59c08ea84d821 (diff) | |
download | pandoc-docbook-6e133b25e02edba228c488a4239334885b5ebc85.tar.gz pandoc-docbook-6e133b25e02edba228c488a4239334885b5ebc85.zip |
and update Cargo.lock
-rw-r--r-- | Cargo.lock | 21 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/build.rs | 13 | ||||
-rw-r--r-- | src/config.rs | 30 |
4 files changed, 41 insertions, 24 deletions
@@ -72,9 +72,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | |||
72 | 72 | ||
73 | [[package]] | 73 | [[package]] |
74 | name = "cc" | 74 | name = "cc" |
75 | version = "1.0.71" | 75 | version = "1.0.72" |
76 | source = "registry+https://github.com/rust-lang/crates.io-index" | 76 | source = "registry+https://github.com/rust-lang/crates.io-index" |
77 | checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" | 77 | checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" |
78 | 78 | ||
79 | [[package]] | 79 | [[package]] |
80 | name = "cfg-if" | 80 | name = "cfg-if" |
@@ -284,9 +284,9 @@ dependencies = [ | |||
284 | 284 | ||
285 | [[package]] | 285 | [[package]] |
286 | name = "libc" | 286 | name = "libc" |
287 | version = "0.2.106" | 287 | version = "0.2.108" |
288 | source = "registry+https://github.com/rust-lang/crates.io-index" | 288 | source = "registry+https://github.com/rust-lang/crates.io-index" |
289 | checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" | 289 | checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" |
290 | 290 | ||
291 | [[package]] | 291 | [[package]] |
292 | name = "linked-hash-map" | 292 | name = "linked-hash-map" |
@@ -380,9 +380,9 @@ checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" | |||
380 | 380 | ||
381 | [[package]] | 381 | [[package]] |
382 | name = "pandoc" | 382 | name = "pandoc" |
383 | version = "0.8.6" | 383 | version = "0.8.8" |
384 | source = "registry+https://github.com/rust-lang/crates.io-index" | 384 | source = "registry+https://github.com/rust-lang/crates.io-index" |
385 | checksum = "8c5ab1abdd81ed62e852d412d18964925e42c8f154c61e89c6296b1a06b6daeb" | 385 | checksum = "0eac785b7de8de25c5ec48b3a9df1be552de03906f99145ed6d7da3d696c0dbb" |
386 | dependencies = [ | 386 | dependencies = [ |
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]] |
603 | name = "serde_json" | 604 | name = "serde_json" |
604 | version = "1.0.69" | 605 | version = "1.0.72" |
605 | source = "registry+https://github.com/rust-lang/crates.io-index" | 606 | source = "registry+https://github.com/rust-lang/crates.io-index" |
606 | checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8" | 607 | checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527" |
607 | dependencies = [ | 608 | dependencies = [ |
608 | "itoa", | 609 | "itoa", |
609 | "ryu", | 610 | "ryu", |
@@ -633,9 +634,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" | |||
633 | 634 | ||
634 | [[package]] | 635 | [[package]] |
635 | name = "syn" | 636 | name = "syn" |
636 | version = "1.0.81" | 637 | version = "1.0.82" |
637 | source = "registry+https://github.com/rust-lang/crates.io-index" | 638 | source = "registry+https://github.com/rust-lang/crates.io-index" |
638 | checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" | 639 | checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" |
639 | dependencies = [ | 640 | dependencies = [ |
640 | "proc-macro2", | 641 | "proc-macro2", |
641 | "quote", | 642 | "quote", |
@@ -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 |
21 | pandoc_ast = { git = "https://github.com/oli-obk/pandoc-ast", rev = "d73a7d0a065f568d60bcee6cff2340f75065273e" } | 21 | pandoc_ast = { git = "https://github.com/oli-obk/pandoc-ast", rev = "d73a7d0a065f568d60bcee6cff2340f75065273e" } |
22 | serde = { version = "1", features = [ "derive" ] } | 22 | serde = { version = "1", features = [ "derive" ] } |
23 | serde_json = "1" | ||
23 | tempfile = "3" | 24 | tempfile = "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 | ||
15 | pub fn do_build(config: &crate::config::Config) -> Result<()> { | 15 | pub 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 @@ | |||
1 | use std::collections::HashMap; | ||
2 | |||
1 | use log::debug; | 3 | use log::debug; |
2 | use serde::{Deserialize, Serialize}; | 4 | use 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 | |||
16 | impl 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 { | |||
44 | fn default_build_dir() -> String { | 61 | fn default_build_dir() -> String { |
45 | "pdbook".to_string() | 62 | "pdbook".to_string() |
46 | } | 63 | } |
47 | |||
48 | impl 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 | } | ||