mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 15:31:19 +02:00
Handle enabled/disabled variables and render multi
This commit is contained in:
@@ -13,12 +13,18 @@ fn render_with_environment(template: &str, environment: &Environment) -> String
|
|||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
let variables = &environment.variables.0;
|
let variables = &environment.variables.0;
|
||||||
for variable in variables {
|
for variable in variables {
|
||||||
map.insert(variable.name.as_str(), variable.value.as_str());
|
if !variable.enabled {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
map.insert(
|
||||||
|
variable.name.as_str(),
|
||||||
|
variable.value.as_str(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Regex::new(r"\$\{\[\s*([^]\s]+)\s*]}")
|
Regex::new(r"\$\{\[\s*([^]\s]+)\s*]}")
|
||||||
.expect("Failed to create regex")
|
.expect("Failed to create regex")
|
||||||
.replace(template, |caps: &tauri::regex::Captures| {
|
.replace_all(template, |caps: &tauri::regex::Captures| {
|
||||||
let key = caps.get(1).unwrap().as_str();
|
let key = caps.get(1).unwrap().as_str();
|
||||||
map.get(key).unwrap_or(&"")
|
map.get(key).unwrap_or(&"")
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export function twig(
|
|||||||
environment: Environment | null,
|
environment: Environment | null,
|
||||||
autocomplete?: GenericCompletionConfig,
|
autocomplete?: GenericCompletionConfig,
|
||||||
) {
|
) {
|
||||||
const variables = environment?.variables ?? [];
|
const variables = environment?.variables.filter(v => v.enabled) ?? [];
|
||||||
const completions = twigCompletion({ options: variables });
|
const completions = twigCompletion({ options: variables });
|
||||||
|
|
||||||
const language = mixLanguage(base);
|
const language = mixLanguage(base);
|
||||||
|
|||||||
Reference in New Issue
Block a user