public Tuple<string, string> Process(StyleClass styleClass) { string value; if (styleClass.Attributes.TryGetValue(key, out value)) { return new Tuple<string, string>(property, value); } return null; }
public Tuple<string, string> Process(StyleClass styleClass) { string value; if (styleClass.Attributes.TryGetValue("background-color", out value)) { var result = rgbRegex.Match(value); if (result.Success) { var numbers = digitRegex.Matches(value); var first = numbers[0].Value; var second = numbers[1].Value; var third = numbers[2].Value; var opacityRegex = digitWithDecimalRegex.Match(value); if (opacityRegex.Success) { var opacity = opacityRegex.Value; var opacityHex = opacity.MapDoubleToHexValue(); var outputValue = string.Format("#{3}{0}{1}{2}", first.AsHexValue(), second.AsHexValue(), third.AsHexValue(), opacityHex); return new Tuple<string, string>(BackgroundKey, outputValue); } else { var outputValue = string.Format("#FF{0}{1}{2}", first.AsHexValue(), second.AsHexValue(), third.AsHexValue()); return new Tuple<string, string>(BackgroundKey, outputValue); } } } styleClass.Attributes.TryGetValue("background", out value); if (hexRegex.IsMatch(value)) { var outputValue = value.ToUpper().Replace("#", "#FF"); return new Tuple<string, string>(BackgroundKey, outputValue); } return new Tuple<string, string>(BackgroundKey, value.ToTitleCase()); }
private static StyleClass Map(string s) { var parts = s.Split('{'); var styleName = CleanUp(parts[0]).Trim().ToLower(); var sc = new StyleClass { Name = styleName }; var atrs = CleanUp(parts[1]).Replace("}", "").Split(';'); foreach (var a in atrs) { if (!a.Contains(":")) continue; var key = a.Split(':')[0].Trim().ToLower(); if (sc.Attributes.ContainsKey(key)) { sc.Attributes.Remove(key); } sc.Attributes.Add(key, a.Split(':')[1].Trim()); } return sc; }
public Tuple<string, string> Process(StyleClass styleClass) { var template = "{0},{1},{2},{3}"; var topValue = "0"; var leftValue = "0"; var rightValue = "0"; var bottomValue = "0"; string value; if (styleClass.Attributes.TryGetValue("margin", out value)) { var providedValues = new Regex("[0-9]{1,}px"); var results = providedValues.Matches(value); if (results.Count == 4) { topValue = results[0].Value.StripPixelValue(); rightValue = results[1].Value.StripPixelValue(); bottomValue = results[2].Value.StripPixelValue(); leftValue = results[3].Value.StripPixelValue(); } if (results.Count == 3) { var first = results[0].Value.StripPixelValue(); var second = results[1].Value.StripPixelValue(); var third = results[2].Value.StripPixelValue(); topValue = first; rightValue = second; bottomValue = third; leftValue = second; } if (results.Count == 2) { var first = results[0].Value.StripPixelValue(); var second = results[1].Value.StripPixelValue(); topValue = first; rightValue = second; bottomValue = first; leftValue = second; } if (results.Count == 1) { var first = results[0].Value.StripPixelValue(); topValue = first; rightValue = first; bottomValue = first; leftValue = first; } } if (styleClass.Attributes.TryGetValue("margin-left", out value)) { leftValue = value.StripPixelValue(); } if (styleClass.Attributes.TryGetValue("margin-top", out value)) { topValue = value.StripPixelValue(); } if (styleClass.Attributes.TryGetValue("margin-bottom", out value)) { bottomValue = value.StripPixelValue(); } if (styleClass.Attributes.TryGetValue("margin-right", out value)) { rightValue = value.StripPixelValue(); } var result = string.Format(template, leftValue, topValue, rightValue, bottomValue); return new Tuple<string, string>("Margin", result); }
public bool IsMatch(StyleClass styleClass) { return styleClass.Attributes.Any(c => c.Key.StartsWith("margin")); }
public bool IsMatch(StyleClass styleClass) { return styleClass.Attributes.ContainsKey(key); }
public bool IsMatch(StyleClass styleClass) { return styleClass.Attributes.Any(t => t.Key.StartsWith("background")); }