Base environments fully working

This commit is contained in:
Gregory Schier
2023-11-02 18:43:39 -07:00
parent 1cd6e0af06
commit 68ea718c77
9 changed files with 57 additions and 33 deletions

View File

@@ -1,24 +1,27 @@
use crate::models::Environment;
use crate::models::{Environment, Workspace};
use std::collections::HashMap;
use tauri::regex::Regex;
pub fn render(template: &str, environment: Option<&Environment>) -> String {
match environment {
Some(environment) => render_with_environment(template, environment),
None => template.to_string(),
}
}
fn render_with_environment(template: &str, environment: &Environment) -> String {
pub fn render(template: &str, workspace: &Workspace, environment: Option<&Environment>) -> String {
let mut map = HashMap::new();
let variables = &environment.variables.0;
for variable in variables {
if !variable.enabled {
let workspace_variables = &workspace.variables.0;
for variable in workspace_variables {
if !variable.enabled || variable.value.is_empty() {
continue;
}
map.insert(variable.name.as_str(), variable.value.as_str());
}
if let Some(e) = environment {
let environment_variables = &e.variables.0;
for variable in environment_variables {
if !variable.enabled || variable.value.is_empty() {
continue;
}
map.insert(variable.name.as_str(), variable.value.as_str());
}
}
Regex::new(r"\$\{\[\s*([^]\s]+)\s*]}")
.expect("Failed to create regex")
.replace_all(template, |caps: &tauri::regex::Captures| {