public void CanKebanNames() { var rules = new CssValue[] { "backgroundColor", "#cAcAcA" }; TransformationsRules.KebabRules(rules, 0); CollectionAssert.AreEqual(rules, new CssValue[] { "background-color", "#cAcAcA" }); }
public void CanKebebWebkitPrefix() { var rules = new CssValue[] { "WebkitFontSmoothing", "antialiased" }; TransformationsRules.KebabRules(rules, 0); CollectionAssert.AreEqual(rules, new CssValue[] { "-webkit-font-smoothing", "antialiased" }); }
public static async Task <string> SerializeRuleEntries(IDictionary <string, object> ruleEntries) { if (ruleEntries?.Any() != true) { return(""); } var allEntries = new List <CssValue>(); foreach (var entry in ruleEntries.Keys) { object rule; if (entry is string str && str != DISPLAY_NAME && ruleEntries.TryGetValue(entry, out rule) && rule != null) { allEntries.Add(str); var entryValue = ruleEntries[entry]; CssValue value = new CssValue(); switch (entryValue) { case CssValue css: value = css; break; case bool bo: value = bo; break; case int @int: value = @int; break; case string strg: value = strg; break; default: value = JsonConvert.SerializeObject(entryValue, Formatting.None, RawConverter.Settings); break; } allEntries.Add(value); } } var arrayRules = allEntries.ToArray(); // Apply transforms. for (var i = 0; i < arrayRules.Length; i += 2) { TransformationsRules.KebabRules(arrayRules, i); TransformationsRules.ProvideUnits(arrayRules, i); await TransformationsRules.RtlifyRules(arrayRules, i); await TransformationsRules.PrefixRules(arrayRules, i); } var rules = arrayRules.ToList(); // Apply punctuation. for (var i = 1; i < rules.Count; i += 4) { rules.Splice(i, 1, ":", rules[i], ";"); } return(string.Join("", rules)); }