Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn set_variables(variables: &HashMap<String, String>, component: &mut Component) {
- let colors = &mut component.data.constant.colors;
- let mut resolved_vars = HashMap::<String, String>::new();
- for (var_key, var_value) in colors.iter_mut() {
- if var_key.starts_with('$') {
- // Find in local scope
- let var_key = &var_key[1..];
- let local_value = resolved_vars.iter().find_map(|(k, v)| {
- if var_key == *k {
- Some(v.to_owned())
- } else {
- None
- }
- });
- if let Some(value) = local_value {
- resolved_vars.insert(var_key.to_owned(), value);
- } else {
- let global_value = variables.iter().find_map(|(k, v)| {
- if var_key == *k {
- Some(v.to_owned())
- } else {
- None
- }
- });
- if let Some(value) = global_value {
- resolved_vars.insert(var_key.to_owned(), value);
- } else {
- error!("Variable {} not found!", var_key);
- }
- }
- } else {
- resolved_vars.insert(var_key.to_owned(), var_value.to_owned());
- }
- }
- component.data.constant.colors = resolved_vars;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement