/// <summary> /// Creates a style sheet from CSS and style rules /// </summary> /// <param name="data">The style sheet data</param> /// <returns>The style sheet combined from the CSS and the rules</returns> /// <remarks> /// Any "umbraco style rules" in the CSS will be removed and replaced with the rules passed in <see cref="data"/> /// </remarks> public string PostInterpolateStylesheetRules(StylesheetData data) { // first remove all existing rules var existingRules = data.Content.IsNullOrWhiteSpace() ? new Core.Strings.Css.StylesheetRule[0] : StylesheetHelper.ParseRules(data.Content).ToArray(); foreach (var rule in existingRules) { data.Content = StylesheetHelper.ReplaceRule(data.Content, rule.Name, null); } data.Content = data.Content.TrimEnd(CharArrays.LineFeedCarriageReturn); // now add all the posted rules if (data.Rules != null && data.Rules.Any()) { foreach (var rule in data.Rules) { data.Content = StylesheetHelper.AppendRule(data.Content, new Core.Strings.Css.StylesheetRule { Name = rule.Name, Selector = rule.Selector, Styles = rule.Styles }); } data.Content += Environment.NewLine; } return(data.Content); }
/// <summary> /// Extracts "umbraco style rules" from a style sheet /// </summary> /// <param name="data">The style sheet data</param> /// <returns>The style rules</returns> public StylesheetRule[] PostExtractStylesheetRules(StylesheetData data) { if (data.Content.IsNullOrWhiteSpace()) { return(new StylesheetRule[0]); } return(StylesheetHelper.ParseRules(data.Content)?.Select(rule => new StylesheetRule { Name = rule.Name, Selector = rule.Selector, Styles = rule.Styles }).ToArray()); }
private AngularSpaResponseViewModel GetDevelopmentReponseViewModel() { var result = new AngularSpaResponseViewModel(); StylesheetData defaultThemeData = null; var vendorCss = new StylesheetData { StylesheetUrl = this.GetDevelopmentAssetUrl("vendor.css") }; var mainCss = new StylesheetData { StylesheetUrl = this.GetDevelopmentAssetUrl("main.css") }; var manifestScript = this.GetDevelopmentAssetUrl("manifest.js"); var polyfillsScript = this.GetDevelopmentAssetUrl("polyfills.js"); var vendorScript = this.GetDevelopmentAssetUrl("vendor.js"); var mainScript = this.GetDevelopmentAssetUrl("main.js"); var themes = this.GetDeserializedThemes(); var themeDatas = new List <ThemeData>(); foreach (var theme in themes) { var themeData = new ThemeData { ThemeId = theme.id, IsDefault = theme.is_default, StylesheetUrl = this.GetDevelopmentAssetUrl(theme.filename + ".css"), UIMainColor = theme.ui_main_color, UIDescription = theme.ui_description }; themeDatas.Add(themeData); if (themeData.IsDefault) { defaultThemeData = new StylesheetData { IsTheme = true, StylesheetUrl = themeData.StylesheetUrl }; } } result.Themes = themeDatas; result.Stylesheets = new StylesheetData[3] { defaultThemeData, vendorCss, mainCss }; result.Scripts = new string[4] { manifestScript, polyfillsScript, vendorScript, mainScript }; return(result); }