Example #1
0
		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;
		}
Example #2
0
		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;
		}
Example #3
0
		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);
		}
Example #4
0
		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;
			}			
		}
Example #5
0
		public void AddRule(StyleRule rule)
		{
			Rules.Add(rule);
		}
Example #6
0
		private void AddRule(StyleRule rule)
		{
			Rules.Add(rule);
		}