public UssExportOptions() { comments = new UssComments(); propertyIndent = " "; withComment = true; exportDefaultValues = true; }
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); }
public static void CopySelector(StyleSheet sheet, UssComments comments, StyleComplexSelector complexSelector, StyleSheetBuilderHelper helper) { helper.BeginRule(comments.Get(complexSelector.rule)); BuildSelector(complexSelector, helper); foreach (var property in complexSelector.rule.properties) { CopyProperty(sheet, comments, property, helper); } helper.EndRule(); }
public static void CopyProperty(StyleSheet sheet, UssComments comments, StyleProperty property, StyleSheetBuilderHelper helper) { var propertyCopy = helper.builder.BeginProperty(property.name); helper.options.comments.AddComment(propertyCopy, comments.Get(property)); foreach (var value in property.values) { switch (value.valueType) { case StyleValueType.Color: helper.builder.AddValue(sheet.ReadColor(value)); break; case StyleValueType.Enum: helper.builder.AddValue(sheet.ReadEnum(value), StyleValueType.Enum); break; case StyleValueType.Float: helper.builder.AddValue(sheet.ReadFloat(value)); break; case StyleValueType.Dimension: helper.builder.AddValue(sheet.ReadDimension(value)); break; case StyleValueType.Keyword: helper.builder.AddValue(sheet.ReadKeyword(value)); break; case StyleValueType.ResourcePath: helper.builder.AddValue(sheet.ReadResourcePath(value), StyleValueType.ResourcePath); break; case StyleValueType.String: helper.builder.AddValue(sheet.ReadString(value), StyleValueType.String); break; } } helper.builder.EndProperty(); }