- source = **STRING** - change the the filetype of the source file
- filetype = **STRING** - change the filetype of the output file
- pandoc = **BOOL** - toggles if pandoc is ran on this file to convert between filetypes
+- copy_only = **BOOL** - copys file or directory without processing anything
--- /dev/null
+#{ copy_only = true }
+
+variable: ${this} should get copied verbatim
for f in fs::read_dir(&self.path)? {
let file = f?.path();
+ if self.global.header.copy_only {
+ let dest = self.global.dest()?;
+ fs::copy(file, &dest.parent().unwrap_or(&self.opts.build))?;
+ continue;
+ }
+
if file.is_dir() {
let dir = DirNode::build(file, self.opts)?;
self.dirs.push(dir);
return Err(Box::new(MetaError::Ignored));
}
+ if self.header.copy_only {
+ let dest = self.dest().map_err(MetaError::from)?;
+ let source: String = self.source.iter().map(|s| s.to_string()).collect();
+ std::fs::write(dest, source).unwrap();
+ return Err(Box::new(MetaError::Ignored));
+ }
+
let html = self.to_html().map_err(MetaError::from)?;
let pattern = self.get_pattern("base").map_err(MetaError::from)?;
pub source: String,
pub pandoc: bool,
pub ignore: bool,
+ pub copy_only: bool,
}
impl Header {
source: String::from("markdown"),
pandoc: true,
ignore: false,
+ copy_only: false,
}
}
}
"filetype" => header.filetype = val.to_string(),
"source" => header.source = val.to_string(),
"ignore" => header.ignore = val == "true",
+ "copy_only" => header.copy_only = val == "true",
_ => continue,
}
}
-use crate::{MetaFile, Options};
+use crate::{MetaError, MetaFile, Options};
use eyre::Result;
use std::{fs, path::PathBuf};
let mut path = test_dir.join($file);
path.set_extension("meta");
let file = MetaFile::build(path, &opts)?;
- assert_eq!(file.construct()?, $test);
+
+ let str = match file.construct() {
+ Ok(f) => f,
+ Err(e) => match *e {
+ MetaError::Ignored => return Ok(()),
+ e => return Err(e.into())
+ }
+
+ };
+
+ assert_eq!(str, $test);
Ok(())
}
};
"<html>\n<p>GOOD GOOD</p>\n\n\n\n</html>\n"
);
+unit_test!(
+ copy_header,
+ "header/copy",
+ r#"variable: ${this} should get copied verbatim"#
+);
+
panic_test!(ignore, "ignore.meta", "");
#[test]