public static void PopulateSheet(StyleSheet sheet, IEnumerable <Rule> rules, ResolvingOptions options = null) { options = options ?? new ResolvingOptions(); var helper = new StyleSheetBuilderHelper(); if (options.SortRules) { rules = rules.OrderBy(rule => rule.SelectorName); } foreach (var rule in rules) { helper.BeginRule(string.Empty, rule.LineNumber); StyleSheetBuilderHelper.BuildSelector(rule.Selector, helper); var propertyValues = rule.Properties.Values.ToList(); if (options.SortProperties) { propertyValues.Sort((p1, p2) => p1.Name.CompareTo(p2.Name)); } foreach (var property in propertyValues) { helper.builder.BeginProperty(property.Name); AddValues(helper, property.Values); helper.builder.EndProperty(); } helper.EndRule(); } helper.PopulateSheet(sheet); }
public static StyleSheet ConvertToStyleSheet(IEnumerable <Rule> rules, Dictionary <string, Property> variables = null, ResolvingOptions options = null) { options = options ?? new ResolvingOptions(); variables = variables ?? new Dictionary <string, Property>(); var helper = new StyleSheetBuilderHelper(); if (options.SortRules) { rules = rules.OrderBy(rule => rule.SelectorName); } foreach (var rule in rules) { helper.BeginRule(); StyleSheetBuilderHelper.BuildSelector(rule.Selector, helper); var propertyValues = rule.Properties.Values.ToList(); if (options.SortProperties) { propertyValues.Sort((p1, p2) => p1.Name.CompareTo(p2.Name)); } foreach (var property in propertyValues) { helper.builder.BeginProperty(property.Name); // Try to resolve variable var values = ResolveValues(property, variables, options); AddValues(helper, values); helper.builder.EndProperty(); } helper.EndRule(); } helper.PopulateSheet(); return(helper.sheet); }
public static StyleSheet ToStyleSheet(GUISkin skin, UssExportOptions options = null) { var builder = new StyleSheetBuilderHelper(options); AddSkin(builder, skin); builder.PopulateSheet(); return(builder.sheet); }
public static StyleSheet ToStyleSheet(GUIStyle style, string name, UssExportOptions options = null) { var builder = new StyleSheetBuilderHelper(options); AddStyle(builder, name, style); builder.PopulateSheet(); return(builder.sheet); }
public SplitSheetData Split(StyleSheet s1, StyleSheet s2, UssComments s1SrcComments = null, UssComments s2SrcComments = null) { s1Cache = new StyleSheetCache(s1); s1Comments = s1SrcComments ?? new UssComments(); s2Cache = new StyleSheetCache(s2); s2Comments = s2SrcComments ?? new UssComments(); s1Builder = new StyleSheetBuilderHelper(); s2Builder = new StyleSheetBuilderHelper(); commonBuilder = new StyleSheetBuilderHelper(); var allSelectors = new HashSet <string>(s1Cache.selectors.Keys); allSelectors.UnionWith(s2Cache.selectors.Keys); foreach (var selectorStr in allSelectors) { StyleComplexSelector complexSelector1; s1Cache.selectors.TryGetValue(selectorStr, out complexSelector1); StyleComplexSelector complexSelector2; s2Cache.selectors.TryGetValue(selectorStr, out complexSelector2); if (complexSelector1 != null) { if (complexSelector2 != null) { // Common rules, write common properties Split(complexSelector1, complexSelector2); } else { // Rules only existing in S1: copy it straight StyleSheetBuilderHelper.CopySelector(s1, s1Comments, complexSelector1, s1Builder); } } else { // Rules only existing in S2: copy it straight StyleSheetBuilderHelper.CopySelector(s2, s2Comments, complexSelector2, s2Builder); } } commonBuilder.PopulateSheet(); s1Builder.PopulateSheet(); s2Builder.PopulateSheet(); var result = new SplitSheetData { common = commonBuilder.sheet, s1 = s1Builder.sheet, s2 = s2Builder.sheet }; return(result); }