need_stdout = false
[jobs.test]
-command = [ "cargo", "test", "--color", "always" ]
-need_stdout = true
+command = [ "cargo", "test", "--color", "always", "--", "--color", "always" ]
+need_stdout = false
[jobs.doc]
command = ["cargo", "doc", "--color", "always", "--no-deps"]
}
pub fn metafile_to_string(file: &MetaFile, dirs: &RootDirs, name: Option<&str>) -> Result<String> {
- let mut output = String::default();
+ let mut output = String::new();
+ let mut arrays = false;
for section in file.source.iter() {
match section {
let expanded = match sub {
Substitution::Variable(key) => file
.get_var(key)
+ .filter(|val| *val != "BLANK")
.map(|val| val.to_string())
.unwrap_or_default(),
Substitution::Pattern(key) => get_pattern(key, file, dirs)?,
// comments have already been removed at this point,
// so we use them to mark keys for array substitution
- Substitution::Array(key) => format!("-{{{key}}}"),
+ Substitution::Array(key) => {
+ arrays = true;
+ format!("-{{{key}}}")
+ }
};
output.push_str(&format!("\n{}\n", expanded));
}
}
}
+ println!("{}", output);
+
// deal with arrays
- expand_arrays(output, file, name)
+ if arrays {
+ expand_arrays(output, file, name)
+ } else {
+ Ok(output)
+ }
}
fn get_pattern(key: &str, file: &MetaFile, dirs: &RootDirs) -> Result<String> {
- let filename = file.get_pat(key).unwrap_or("default");
+ let mut filename = file.get_pat(key).unwrap_or("default");
+ if filename == "BLANK" {
+ return Ok(String::new());
+ };
+
+ if filename == "DEFAULT" {
+ filename = "default";
+ }
let pattern_path = key.replace('.', "/") + "/" + filename;
let mut path = dirs.pattern.join(pattern_path);
path.set_extension("meta");
+ eprintln!("{:?}", path);
let pattern = &fs::read_to_string(path.to_str().unwrap_or_default())?;
- let pattern = parse_file(pattern)?;
+ let mut pattern = parse_file(pattern)?;
+
+ pattern.variables = file.variables.clone();
+ pattern.arrays = file.arrays.clone();
+ pattern.patterns = file.patterns.clone();
+
metafile_to_string(&pattern, dirs, Some(key))
}
} else {
key = array.to_string();
}
- // let key = dbg!(name.unwrap_or_default().to_owned() + "." + array);
let value = file.get_arr(&key).unwrap_or_default();
(*array, value)
})
}
if Rule::value == pair.as_rule() {
let tmp = pair.as_str();
- // blank and default shoud be handled by whoever is getting the value
- // set it to empty strings to remove it from the HashMap
- if tmp == "BLANK" || tmp == "DEFAULT" {
- return ("", "");
+
+ if tmp == "BLANK" {
+ return (key, "BLANK");
+ }
+
+ if tmp == "DEFAULT" {
+ return (key, "DEFAULT");
}
+
// remove surrounding quotes from values by returning
// everything except first and last characters
// a string is defined as " ... " or ' ... '
-use crate::{metafile_to_string, parse_file, source, RootDirs, Source, Substitution};
+use crate::{parse_file, source, Source, Substitution};
use color_eyre::Result;
use pretty_assertions::assert_eq;
-use std::{fs, path::PathBuf};
-static SOURCE: &str = include_str!("../../tests/files/test_site/source/test_source.meta");
-static PATTERN: &str = include_str!("../../tests/files//test_site/pattern/test/pattern.meta");
+static SOURCE: &str = include_str!("../../test_site/source/test_source.meta");
+static PATTERN: &str = include_str!("../../test_site/pattern/test/pattern.meta");
#[test]
fn test_metafile_gets() -> Result<()> {
assert_eq!(source.get_var("var").unwrap(), "GOOD");
assert_eq!(source.get_var("single_quotes").unwrap(), "GOOD");
- assert_eq!(source.get_var("blank"), None);
+ assert_eq!(source.get_var("blank").unwrap(), "BLANK");
assert_eq!(source.get_var("not_defined"), None);
assert_eq!(source.get_arr("sub.array").unwrap(), ["GOOD", "GOOD"]);
assert_eq!(source.get_arr("not_defined"), None);
assert_eq!(source.get_pat("test").unwrap(), "pattern");
- assert_eq!(source.get_pat("test.sub_pat"), None);
- assert_eq!(source.get_pat("blank_pat"), None);
+ assert_eq!(source.get_pat("test.sub_pat").unwrap(), "DEFAULT");
+ assert_eq!(source.get_pat("blank_pat").unwrap(), "BLANK");
assert_eq!(source.get_pat("not_defined"), None);
Ok(())
let source = parse_file(SOURCE)?;
assert_eq!(source.variables.get("var").unwrap(), &"GOOD");
- assert_eq!(source.variables.get("blank"), None);
+ assert_eq!(source.variables.get("blank").unwrap(), &"BLANK");
assert_eq!(source.variables.get("not_here"), None);
assert_eq!(
assert_eq!(source.arrays.get("not_defined"), None);
assert_eq!(source.patterns.get("test").unwrap(), &"pattern");
- assert_eq!(source.patterns.get("test.sub_pat"), None);
- assert_eq!(source.patterns.get("blank_pat"), None);
+ assert_eq!(source.patterns.get("test.sub_pat").unwrap(), &"DEFAULT");
+ assert_eq!(source.patterns.get("blank_pat").unwrap(), &"BLANK");
assert_eq!(source.patterns.get("not_defined"), None);
Ok(())
var3 [VAL WITH SPACES]:
GOOD GOOD
-
arr1 [VALUE]:
GOOD
arr2 [BLANK]:
Pattern subs:
-test [WITH ARRAY]:
-<p>GOOD</p>
-<p>GOOD GOOD</p>
+test [WITH ARRAY]:
+<p>
+GOOD
+</p><p>
+GOOD GOOD
+</p>
test.sub_pat:
<h1>SUBPATTERN</h1>
test.default:
<h1>DEFAULT</h1>
-test.blank:
+test.blank:
-This comment should not be rendered:
+This comment should not be rendered:
use pretty_assertions::assert_eq;
use std::{fs, path::PathBuf};
-static PRE_EXPAND: &str = include_str!("./files/test_site/source/expand.meta");
+static PRE_EXPAND: &str = include_str!("../test_site/source/expand.meta");
static POST_EXPAND: &str = include_str!("./files/expanded");
#[test]
let file = metafile_to_string(&metafile, &dirs, None)?;
- assert_eq!(file, POST_EXPAND);
+ eprintln!("{}", file);
+ assert_eq!(file + "\n", POST_EXPAND);
Ok(())
}
fn build_rootdir() -> Result<RootDirs> {
- let dir = PathBuf::from("./tests/files/test_site");
+ let dir = PathBuf::from("./test_site");
let dirs = RootDirs {
source: dir.join("source"),