public static StyleRule ParseTree(BaseTree tree) { var rule = new StyleRule(); foreach (BaseTree child in tree.Children) { switch(child.Text) { case "PROPERTY": rule.Properties.Add(StyleProperty.ParseTree(child)); break; case "RULE": rule.Rules.Add(StyleRule.ParseTree(child)); break; case "SELECTORGROUP": foreach (BaseTree selectorChild in child.Children) { rule.Selectors.Add(StyleSelector.ParseTree(selectorChild)); } break; case "MIXIN": rule.Mixins.AddRange(ParseMixins(child)); break; } } return rule; }
public StyleDocument Merge() { var doc = MemberwiseClone() as StyleDocument; var newRules = new List<StyleRule>(); foreach (var selectorGroup in doc.Rules.GroupBy(r => r.GetSelector())) { var rule = new StyleRule(); rule.Selectors.Add(new StyleSelector { Name = selectorGroup.Key }); rule.Properties.AddRange(selectorGroup.SelectMany(r => r.Properties).Distinct()); if(rule.Properties.Count > 0) newRules.Add(rule); } doc.Rules = GroupRules(newRules).ToList(); return doc; }
public bool Equals(StyleRule obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.Selectors.SequenceEqual(Selectors) && obj.Properties.SequenceEqual(Properties) && obj.Rules.SequenceEqual(Rules); }
private IEnumerable<StyleRule> GroupRules(IEnumerable<StyleRule> input) { var list = input.ToList(); while (list.Count > 0) { var rule = list.First(); var rules = list.FindAll(r => rule.Properties.SequenceEqual(r.Properties)); list.RemoveAll(r => rule.Properties.SequenceEqual(r.Properties)); var newrule = new StyleRule { Properties = rule.Properties, Selectors = rules.Select(r => r.Selectors.First()).ToList() }; yield return newrule; } }
public void AddRule(StyleRule rule) { Rules.Add(rule); }
private void AddRule(StyleRule rule) { Rules.Add(rule); }