From e62267ae7a16b4fba8333424d6421217b1d8d3e3 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Fri, 2 Jun 2023 18:27:49 -0500 Subject: [PATCH] added: include and expand files from source dir --- files/test_site/pattern/test/expand_source.meta | 1 + .../source/unit_tests/expand/source.meta | 3 +++ .../source/unit_tests/expand/source_expand.meta | 2 ++ src/metafile/file/patterns.rs | 15 ++++++++++++--- src/tests.rs | 6 ++++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 files/test_site/pattern/test/expand_source.meta create mode 100644 files/test_site/source/unit_tests/expand/source.meta create mode 100644 files/test_site/source/unit_tests/expand/source_expand.meta diff --git a/files/test_site/pattern/test/expand_source.meta b/files/test_site/pattern/test/expand_source.meta new file mode 100644 index 0000000..c2d0d56 --- /dev/null +++ b/files/test_site/pattern/test/expand_source.meta @@ -0,0 +1 @@ +&{SOURCE.unit_tests.expand.source_expand} diff --git a/files/test_site/source/unit_tests/expand/source.meta b/files/test_site/source/unit_tests/expand/source.meta new file mode 100644 index 0000000..c97e3bc --- /dev/null +++ b/files/test_site/source/unit_tests/expand/source.meta @@ -0,0 +1,3 @@ +${ var = 'GOOD' } + +&{ test = 'expand_source' } diff --git a/files/test_site/source/unit_tests/expand/source_expand.meta b/files/test_site/source/unit_tests/expand/source_expand.meta new file mode 100644 index 0000000..c290b5a --- /dev/null +++ b/files/test_site/source/unit_tests/expand/source_expand.meta @@ -0,0 +1,2 @@ +GOOD +${var} diff --git a/src/metafile/file/patterns.rs b/src/metafile/file/patterns.rs index f50fd6f..304254f 100644 --- a/src/metafile/file/patterns.rs +++ b/src/metafile/file/patterns.rs @@ -12,6 +12,8 @@ impl<'a> MetaFile<'a> { } } + let is_source = key.split('.').next().unwrap_or("") == "SOURCE"; + let mut filename = if let Some(name) = self.patterns.get(&Scope::create_local(key)) { Ok(name.to_string()) } else if let Some(name) = self.patterns.get(&Scope::create_global(key)) { @@ -21,6 +23,7 @@ impl<'a> MetaFile<'a> { .pattern .join(key.replace(".", "/") + ".meta") .exists() + || is_source { Ok(String::new()) } else if self.header.panic_default { @@ -61,15 +64,21 @@ impl<'a> MetaFile<'a> { } let pattern_path = key.replace('.', "/") + "/" + &filename; - let mut path = self.opts.pattern.join(pattern_path); - path.set_extension("meta"); + let mut path = if is_source { + let pattern_path = pattern_path.replace("SOURCE/", ""); + self.opts.source.join(pattern_path) + } else { + self.opts.pattern.join(pattern_path) + }; + + path.set_extension("meta"); let mut pattern = MetaFile::build(path, self.opts)?; // copy over maps for expanding contained variables pattern.merge(self); - if pattern.header.pandoc.unwrap_or(false) { + if pattern.header.pandoc.unwrap_or(false) || is_source { pattern.pandoc() } else { pattern.get_source() diff --git a/src/tests.rs b/src/tests.rs index 8e69a06..8564ce7 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -147,6 +147,12 @@ unit_test!( "\n

GOOD

\n\n\n\n" ); +unit_test!( + include_source, + "expand/source", + "\n

GOOD GOOD

\n\n\n\n\n" +); + panic_test!(ignore, "ignore.meta", ""); #[test] -- 2.45.2