예제 #1
0
        public async Task CanAutoFlipAutoflippingWithNoflip()
        {
            var properties = JsonConvert.DeserializeObject <ICollection <CssValue[][]> >(await File.ReadAllTextAsync(@"Transformations/rtlfyrulesdata.json"), RawConverter.Settings);

            foreach (var test in properties)
            {
                var rules = test[0];
                await TransformationsRules.RtlifyRules(rules, 0);

                CollectionAssert.That.AreEqualRules(rules, test[1]);
            }
        }
        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));
        }