Use fixed list of output types
This commit is contained in:
parent
9f15c57970
commit
1faed7ed86
5 changed files with 14 additions and 9 deletions
|
@ -9,10 +9,16 @@ use std::io::Read;
|
|||
pub mod consts;
|
||||
pub mod csl;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Hash, Clone)]
|
||||
pub enum OutputType {
|
||||
PDF,
|
||||
HTML
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
|
||||
pub struct Config {
|
||||
input: Vec<PathBuf>,
|
||||
output: HashMap<String, PathBuf>,
|
||||
output: HashMap<OutputType, PathBuf>,
|
||||
pub title: String,
|
||||
|
||||
#[serde(default = "default_verbosity")]
|
||||
|
@ -30,11 +36,11 @@ pub struct References {
|
|||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ fn get_config(args: ArgMatches) -> Config {
|
|||
fn main() {
|
||||
let args = args::get_matches();
|
||||
let subcommand = args.subcommand_name().expect("subcommand error");
|
||||
|
||||
match subcommand {
|
||||
"build" => {
|
||||
let config = get_config(args.clone());
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use config::Config;
|
||||
use config::{Config, OutputType};
|
||||
|
||||
pub mod pdf;
|
||||
|
||||
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));
|
||||
}
|
||||
return Ok(());
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use config::Config;
|
||||
use config::{Config, OutputType};
|
||||
use utils::result_override;
|
||||
|
||||
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> {
|
||||
let output_location = &config.absolute_output("pdf".into());
|
||||
let output_location = &config.absolute_output(OutputType::PDF);
|
||||
let mut pdf_app =
|
||||
try!(result_override(PdfApplication::new(), "Failed to create PDF Application".into()));
|
||||
let mut base_builder = pdf_app.builder();
|
||||
|
|
|
@ -6,7 +6,7 @@ input:
|
|||
- ipsum.md
|
||||
- end.md
|
||||
output:
|
||||
pdf: output.pdf
|
||||
PDF: output.pdf
|
||||
title: test title
|
||||
references:
|
||||
bibliography: bib.yaml
|
||||
|
|
Reference in a new issue