Rebel.Cms.Web.StylesheetHelper.ParseRules C# (CSharp) Method

ParseRules() public static method

public static ParseRules ( File input ) : IEnumerable
input Rebel.Framework.Persistence.Model.IO.File
return IEnumerable
        public static IEnumerable<StylesheetRule> ParseRules(File input)
        {
            var rules = new List<StylesheetRule>();
            var ruleRegex = new Regex(string.Format(_ruleRegexFormat, @"[^\*\r\n]*"), RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
            
            var contents = Encoding.UTF8.GetString(input.ContentBytes);
            var ruleMatches = ruleRegex.Matches(contents);

            foreach (Match match in ruleMatches)
            {
                rules.Add(new StylesheetRule
                {
                    RuleId = new HiveId(new Uri("storage://stylesheets"), string.Empty, new HiveIdValue(input.Id.Value + "/" + match.Groups["Name"].Value)),
                    StylesheetId = input.Id,
                    Name = match.Groups["Name"].Value,
                    Selector = match.Groups["Selector"].Value,
                    // Only match first selector when chained together
                    Styles = string.Join(Environment.NewLine, match.Groups["Styles"].Value.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).Select(x => x.Trim()).ToArray())
                });
            }

            return rules;
        }