archive
/
md-pdf-rs
Archived
1
Fork 0

Use fixed list of output types

This commit is contained in:
Jake Howard 2017-11-24 22:15:39 +00:00
parent 9f15c57970
commit 1faed7ed86
Signed by: jake
GPG Key ID: 57AFB45680EDD477
5 changed files with 14 additions and 9 deletions

View File

@ -9,10 +9,16 @@ use std::io::Read;
pub mod consts; pub mod consts;
pub mod csl; pub mod csl;
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Hash, Clone)]
pub enum OutputType {
PDF,
HTML
}
#[derive(Debug, Serialize, Deserialize, Default, Clone)] #[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct Config { pub struct Config {
input: Vec<PathBuf>, input: Vec<PathBuf>,
output: HashMap<String, PathBuf>, output: HashMap<OutputType, PathBuf>,
pub title: String, pub title: String,
#[serde(default = "default_verbosity")] #[serde(default = "default_verbosity")]
@ -30,11 +36,11 @@ pub struct References {
impl Config { impl Config {
pub fn absolute_output(&self, output_type: String) -> PathBuf { pub fn absolute_output(&self, output_type: OutputType) -> PathBuf {
return resolve_path(self.output.get(&output_type).unwrap()); return resolve_path(self.output.get(&output_type).unwrap());
} }
pub fn has_output(&self, output_type: String) -> bool { pub fn has_output(&self, output_type: OutputType) -> bool {
return self.output.contains_key(&output_type); return self.output.contains_key(&output_type);
} }

View File

@ -52,7 +52,6 @@ fn get_config(args: ArgMatches) -> Config {
fn main() { fn main() {
let args = args::get_matches(); let args = args::get_matches();
let subcommand = args.subcommand_name().expect("subcommand error"); let subcommand = args.subcommand_name().expect("subcommand error");
match subcommand { match subcommand {
"build" => { "build" => {
let config = get_config(args.clone()); let config = get_config(args.clone());

View File

@ -1,9 +1,9 @@
use config::Config; use config::{Config, OutputType};
pub mod pdf; pub mod pdf;
pub fn output(config: Config, output: String) -> Result<(), String> { pub fn output(config: Config, output: String) -> Result<(), String> {
if config.has_output("pdf".into()) { if config.has_output(OutputType::PDF) {
try!(pdf::output(config, output)); try!(pdf::output(config, output));
} }
return Ok(()); return Ok(());

View File

@ -1,4 +1,4 @@
use config::Config; use config::{Config, OutputType};
use utils::result_override; use utils::result_override;
use std::error::Error; use std::error::Error;
@ -25,7 +25,7 @@ fn create_builder<'a>(config: Config, builder: &'a mut PdfBuilder) -> &'a mut Pd
} }
pub fn output(config: Config, html: String) -> Result<(), String> { pub fn output(config: Config, html: String) -> Result<(), String> {
let output_location = &config.absolute_output("pdf".into()); let output_location = &config.absolute_output(OutputType::PDF);
let mut pdf_app = let mut pdf_app =
try!(result_override(PdfApplication::new(), "Failed to create PDF Application".into())); try!(result_override(PdfApplication::new(), "Failed to create PDF Application".into()));
let mut base_builder = pdf_app.builder(); let mut base_builder = pdf_app.builder();

View File

@ -6,7 +6,7 @@ input:
- ipsum.md - ipsum.md
- end.md - end.md
output: output:
pdf: output.pdf PDF: output.pdf
title: test title title: test title
references: references:
bibliography: bib.yaml bibliography: bib.yaml