Environments in URL and better rendering

This commit is contained in:
Gregory Schier
2023-10-25 11:13:00 -07:00
parent 3b660ddbd0
commit 33c406ce49
44 changed files with 226 additions and 160 deletions

25
src-tauri/src/render.rs Normal file
View File

@@ -0,0 +1,25 @@
use tauri::regex::Regex;
use crate::models::Environment;
pub fn render(template: &str, environment: Environment) -> String {
let variables = environment.data;
let re = Regex::new(r"\$\{\[\s*([^]\s]+)\s*]}").expect("Failed to create regex");
let rendered = re
.replace(template, |caps: &tauri::regex::Captures| {
let key = caps.get(1).unwrap().as_str();
match variables.get(key) {
Some(v) => {
if v.is_string() {
v.as_str().expect("Should be string").to_string()
} else {
v.to_string()
}
}
None => "".to_string(),
}
})
.to_string();
rendered
}