--- /dev/null
+@{ test.list.item = ['a','b','c','d'] }
+
+&{test.list}
// make a hash map of [keys in source] -> [defined arrays]
.map(|key| {
// concat array to pattern name to get key in HashMap
+ let class = self.class().unwrap_or_default();
+ let class_key = Scope::Local(class + "." + key);
let name = self.name().unwrap_or_default();
- let long_key = name + "." + key;
+ let name_key = Scope::Local(name + "." + key);
- let value = if let Some(val) = self.arrays.get(&Scope::into_global(&long_key)) {
+ let value = if let Some(val) = self.arrays.get(&name_key) {
&val[..]
- } else if let Some(val) = self.arrays.get(&Scope::into_local(&long_key)) {
+ } else if let Some(val) = self.arrays.get(&name_key.to_global()) {
+ &val[..]
+ } else if let Some(val) = self.arrays.get(&class_key) {
+ &val[..]
+ } else if let Some(val) = self.arrays.get(&class_key.to_global()) {
&val[..]
} else if let Some(val) = self.arrays.get(&Scope::into_global(key)) {
&val[..]
Ok(path)
}
+ pub fn class(&self) -> Result<String> {
+ // only care about classes in the pattern dir
+ self.path
+ .strip_prefix(&self.opts.pattern)?
+ .parent()
+ .map(|s| s.to_string_lossy().to_string().replace('/', "."))
+ .ok_or(
+ MetaError::Name {
+ file: self.path.to_string_lossy().to_string(),
+ }
+ .into(),
+ )
+ }
+
pub fn name(&self) -> Result<String> {
- if self.path.starts_with(&self.opts.source) {
- // in source dir, we want the file name without the '.meta' extension
- let name: String = self
- .path
- .strip_prefix(&self.opts.source)?
- .components()
- .map(|x| {
- x.as_os_str()
- .to_string_lossy()
- .to_string()
- .replace(".meta", "")
- })
- .collect::<Vec<String>>()
- .join(".");
- Ok(name)
- } else if self.path.starts_with(&self.opts.pattern) {
- // in pattern dir, we want the parent dir
- let name = self.path.strip_prefix(&self.opts.pattern)?;
- let name = name
- .parent()
- .map(|s| s.to_string_lossy().to_string().replace('/', "."))
- .unwrap_or_default();
- Ok(name)
+ let path = if self.path.starts_with(&self.opts.pattern) {
+ self.path.strip_prefix(&self.opts.pattern)?
+ } else if self.path.starts_with(&self.opts.source) {
+ self.path.strip_prefix(&self.opts.source)?
} else {
- Err(MetaError::Name {
+ return Err(MetaError::Name {
file: self.path.to_string_lossy().to_string(),
}
- .into())
- }
+ .into());
+ };
+
+ Ok(path
+ .components()
+ .map(|x| {
+ x.as_os_str()
+ .to_string_lossy()
+ .to_string()
+ .replace(".meta", "")
+ })
+ .collect::<Vec<String>>()
+ .join("."))
}
}
pat2.path = pat2_path;
assert_eq!(src.name()?, "test.file");
- assert_eq!(pat1.name()?, "base");
- assert_eq!(pat2.name()?, "test.class");
+ assert_eq!(pat1.name()?, "base.test");
+ assert_eq!(pat2.name()?, "test.class.file");
+ assert_eq!(pat1.class()?, "base");
+ assert_eq!(pat2.class()?, "test.class");
Ok(())
}
"<html>\n<p>GOOD</p>\n</html>\n"
);
+unit_test!(
+ direct_call,
+ "expand/direct_call",
+ "<html>\n<p>abcd</p>\n</html>\n"
+);
+
panic_test!(ignore, "ignore.meta", "");
#[test]