mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 18:01:21 +01:00
Environments in URL and better rendering
This commit is contained in:
25
src-tauri/src/render.rs
Normal file
25
src-tauri/src/render.rs
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user