From f638a95a9c4d6680be05de0d400b5e46142eed1f Mon Sep 17 00:00:00 2001 From: craigfay Date: Thu, 26 May 2022 18:36:16 -0500 Subject: [PATCH] Rename sugar -> template_syntax, cleanup warnings --- distill/src/main.rs | 13 ++++---- distill/src/{sugar.rs => template_syntax.rs} | 33 ++------------------ distill/tachyons-flex.yml | 1 + 3 files changed, 10 insertions(+), 37 deletions(-) rename distill/src/{sugar.rs => template_syntax.rs} (89%) diff --git a/distill/src/main.rs b/distill/src/main.rs index bf0ddd2..7a4f54d 100644 --- a/distill/src/main.rs +++ b/distill/src/main.rs @@ -1,14 +1,13 @@ mod lib; -mod sugar; +mod template_syntax; -use lib::{Transformations, TokenGroups, Intermediate}; -use sugar::{SugarRuleSet, transformations_from_sugar_rules}; +use lib::{TokenGroups, Intermediate}; +use template_syntax::{CSSTemplate, transformations_from_templates}; use serde::{Deserialize}; use std::io::BufReader; use std::path::Path; use std::fs; -use serde_json as json; use serde_yaml as yaml; #[derive(Deserialize, Debug)] @@ -44,7 +43,7 @@ fn main() { let config = RCFile::load_from_json(&path_to_config); let mut all_token_groups = TokenGroups::new(); - let mut ruleset = SugarRuleSet::new(); + let mut ruleset = CSSTemplate::new(); for path in config.design_tokens { let file = fs::File::open(path).unwrap(); @@ -58,13 +57,13 @@ fn main() { for path in config.templates { let file = fs::File::open(path).unwrap(); let reader = BufReader::new(file); - let partial_ruleset: SugarRuleSet = yaml::from_reader(reader).unwrap(); + let partial_ruleset: CSSTemplate = yaml::from_reader(reader).unwrap(); for (atom_name_template, block) in partial_ruleset { ruleset.insert(atom_name_template, block); } } - let transformations = transformations_from_sugar_rules(&ruleset); + let transformations = transformations_from_templates(&ruleset); let intermediate = Intermediate::build(all_token_groups, transformations); let css = intermediate.stringify(); diff --git a/distill/src/sugar.rs b/distill/src/template_syntax.rs similarity index 89% rename from distill/src/sugar.rs rename to distill/src/template_syntax.rs index b4c7478..eebbe91 100644 --- a/distill/src/sugar.rs +++ b/distill/src/template_syntax.rs @@ -1,6 +1,4 @@ -use serde_yaml as yaml; -use serde::Deserialize; use regex::Regex; use super::lib::{ @@ -11,35 +9,18 @@ use super::lib::{ CSSRule, }; -use std::collections::{HashMap, BTreeMap}; +use std::collections::{BTreeMap}; use indexmap::IndexMap; - -const _SRC: &str = r#" - -bg-[$colors.key]: - background-color: var(--$colors.key) - -bg-[$colors.key]: - background-color: var(--$colors.key) - -mt-[$sizes.key]: - margin-top: $sizes.value - -m-[$sizes.key]: - margin: $sizes.value - -"#; - type AtomName = String; type CSSProperty = String; type CSSValue = String; type VariableMaps = IndexMap>; -pub type SugarRuleSet = IndexMap; +pub type CSSTemplate = IndexMap; pub type SugarBlock = IndexMap; -pub fn transformations_from_sugar_rules(ruleset: &SugarRuleSet) -> Transformations { +pub fn transformations_from_templates(ruleset: &CSSTemplate) -> Transformations { let mut list = Vec::new(); let mut variable_maps: VariableMaps = IndexMap::new(); @@ -212,11 +193,3 @@ fn detect_token_loop(atom_name_template: &str, block: &SugarBlock) -> Option String { format!(".{}", atom_name) } - -#[test] -fn detect_loop() { - let ruleset: SugarRuleSet = yaml::from_str(_SRC).unwrap(); - - let transforms = transformations_from_sugar_rules(&ruleset); - println!("{}", yaml::to_string(&transforms).unwrap()); -} diff --git a/distill/tachyons-flex.yml b/distill/tachyons-flex.yml index 8c3c9e3..0aae2c0 100644 --- a/distill/tachyons-flex.yml +++ b/distill/tachyons-flex.yml @@ -58,6 +58,7 @@ justify-[$alignments.key]: content-[$alignments.key]: align-content: $alignments.value +# Ordering $orderings: 1: 1 2: 2