Skip to content

Commit

Permalink
Revert "Fix get_namespace tag problems (#141)"
Browse files Browse the repository at this point in the history
This reverts commit d8802aa.
PR #141 didn't actually fix the problem it said it did.
  • Loading branch information
MysteryBlokHed committed Sep 17, 2021
1 parent d8802aa commit 4a762fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/lib/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Compiler {
if target_filename.starts_with('!') {
let ret = self.compile(
tokens,
Some(&files::get_namespace(&functions_dir).unwrap()),
Some(files::get_namespace(&functions_dir).unwrap()),
&files::get_subfolder_prefix(&functions_dir),
&global_macros,
true,
Expand All @@ -118,7 +118,7 @@ impl Compiler {
} else {
self.compile(
tokens,
Some(&files::get_namespace(&functions_dir).unwrap()),
Some(files::get_namespace(&functions_dir).unwrap()),
&files::get_subfolder_prefix(&functions_dir),
&global_macros,
false,
Expand Down
30 changes: 12 additions & 18 deletions src/lib/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,24 @@ pub fn get_subfolder_prefix<P: AsRef<Path>>(functions_path: &P) -> String {
}

/// Get namespace (name of folder containing the main /functions)
pub fn get_namespace<P: AsRef<Path>>(functions_path: &P) -> Result<String, &str> {
let namespace_str = {
let mut namespace_buf = functions_path.as_ref().to_path_buf();
while namespace_buf.is_file()
&& namespace_buf.file_name().unwrap().to_str().unwrap() != "functions"
{
namespace_buf.pop();
}
namespace_buf.pop();

namespace_buf.to_str().unwrap().to_string()
};
pub fn get_namespace<P: AsRef<Path>>(functions_path: &P) -> Result<&str, &str> {
let namespace_folder = functions_path
.as_ref()
.to_str()
.unwrap()
.split("functions")
.next()
.unwrap();

let namespace_folder =
if let Some(new) = namespace_str.strip_suffix(|x: char| ['\\', '/'].contains(&x)) {
new.to_string()
if let Some(new) = namespace_folder.strip_suffix(|x: char| ['\\', '/'].contains(&x)) {
new
} else {
namespace_str
namespace_folder
};

let folders = namespace_folder.split(|x: char| ['\\', '/'].contains(&x));
let last = folders.last().unwrap().to_string();

Ok(last)
Ok(folders.last().unwrap())
}

/// Convert multiple globs into a `Vec<PathBuf>`
Expand Down

0 comments on commit 4a762fd

Please sign in to comment.