Skip to content

Commit

Permalink
Background colors
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfay committed Apr 25, 2022
1 parent a37b449 commit f52fa68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
12 changes: 10 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,18 @@
},
"instructions": [
{
"description": "Generate Text Colors",
"description": "Text Colors",
"method": "fromVariableMap",
"mapName": "colors",
"cssSelector": ".text-{{ VAR_KEY }}",
"cssSelector": ".{{ VAR_KEY }}",
"cssProperty": "color",
"cssValue": "{{ VAR_VAL }}"
},
{
"description": "Background Colors",
"method": "fromVariableMap",
"mapName": "colors",
"cssSelector": ".bg-{{ VAR_KEY }}",
"cssProperty": "color",
"cssValue": "{{ VAR_VAL }}"
}
Expand Down
24 changes: 10 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ struct Config {
}

#[derive(Default)]
struct Rule {
struct CSSRule {
selector: String,
declarations: Vec<(String, String)>,
}


fn generate_rules(config: Config) -> Vec<Rule> {
fn generate_rules(config: Config) -> Vec<CSSRule> {
let mut rules = Vec::new();

for instruction in config.instructions {
Expand All @@ -56,24 +56,20 @@ fn generate_rules(config: Config) -> Vec<Rule> {
.get(&inst.map_name)
.expect(&err_msg_for_missing_map);


for (key, val) in variable_map {
let mut rule = Rule::default();

let inject_variables = |string: &String| {
string
.replace("{{ VAR_KEY }}", key)
.replace("{{ VAR_VAL }}", val)
};

rule.selector = inject_variables(&inst.css_selector);

rule.declarations = vec![(
inject_variables(&inst.css_property),
inject_variables(&inst.css_value),
)];

rules.push(rule);
rules.push(CSSRule {
selector: inject_variables(&inst.css_selector),
declarations: vec![(
inject_variables(&inst.css_property),
inject_variables(&inst.css_value),
)],
});
}
}
}
Expand All @@ -82,7 +78,7 @@ fn generate_rules(config: Config) -> Vec<Rule> {
rules
}

fn stringify_rules(rules: Vec<Rule>) -> String {
fn stringify_rules(rules: Vec<CSSRule>) -> String {
let mut css = String::new();

for rule in rules {
Expand Down

0 comments on commit f52fa68

Please sign in to comment.