public ICollection <string> GetScriptsToBeMerged(string skinName) { var scripts = new List <string>(); SkinTemplate skinTemplate = Templates.ItemOrNull(skinName); if (skinTemplate != null && skinTemplate.Scripts != null) { if (CanScriptsBeMerged(skinTemplate)) { string skinPath = CreateStylePath(skinTemplate.TemplateFolder); foreach (Script script in skinTemplate.Scripts) { if (script.Src.StartsWith("~")) { scripts.Add(HttpHelper.ExpandTildePath(script.Src)); } else { scripts.Add(skinPath + script.Src); } } } } return(scripts); }
public SkinViewModel(SkinTemplate skinTemplate, Func<SkinTemplate, string> getIconUrl, bool mobileOnly) { this.name = System.Web.HttpUtility.HtmlEncode(skinTemplate.Name); this.icon = System.Web.HttpUtility.HtmlEncode(getIconUrl(skinTemplate)); this.skinKey = System.Web.HttpUtility.HtmlEncode(skinTemplate.SkinKey); this.mobile = mobileOnly; }
public static bool CanScriptsBeMerged(SkinTemplate template) { if(!template.MergeScripts) return false; else { if (template.Scripts==null) return false; else { foreach (Script script in template.Scripts) { if (script.Src.Contains("?")) return false; if (IsScriptRemote(script)) return false; } return true; } } }
/// <summary> /// Renders the script element collection for thes kin key. /// </summary> /// <param name="skinKey">The skin key.</param> /// <returns></returns> public string RenderScriptElementCollection(string skinKey) { var result = new StringBuilder(); SkinTemplate skinTemplate = Templates.ItemOrNull(skinKey); if (skinTemplate != null && skinTemplate.Scripts != null) { string skinPath = GetSkinPath(skinTemplate.TemplateFolder); if (CanScriptsBeMerged(skinTemplate)) { result.Append(RenderScriptElement(string.Format("{0}js.axd?name={1}", skinPath, skinKey))); } else { foreach (Script script in skinTemplate.Scripts) { result.Append(RenderScriptElement(skinPath, script)); } } } return(result.ToString()); }
public static bool CanScriptsBeMerged(SkinTemplate template) { if (!template.MergeScripts) { return(false); } if (template.Scripts == null) { return(false); } foreach (Script script in template.Scripts) { if (script.Src.Contains("?")) { return(false); } if (IsScriptRemote(script)) { return(false); } } return(true); }
public string RenderStyleElementCollection(string skinName, SkinTemplate skinTemplate) { var templateDefinedStyles = new StringBuilder(); string finalStyleDefinition = string.Empty; var addedStyle = new List<string>(); if(skinTemplate != null) { string skinPath = CreateStylePath(skinTemplate.TemplateFolder); // If skin doesn't want to be merged, just write plain css if(skinTemplate.StyleMergeMode == StyleMergeMode.None) { if(skinTemplate.Styles != null) { foreach(Style style in skinTemplate.Styles) { templateDefinedStyles.Append(RenderStyleElement(skinPath, style)); } } if(!skinTemplate.ExcludeDefaultStyle) { templateDefinedStyles.Append(RenderStyleElement(skinPath, "style.css")); } if(skinTemplate.HasSkinStylesheet) { templateDefinedStyles.Append(RenderStyleElement(skinPath, skinTemplate.StyleSheet)); } finalStyleDefinition = templateDefinedStyles.ToString(); } else if(skinTemplate.StyleMergeMode == StyleMergeMode.MergedAfter || skinTemplate.StyleMergeMode == StyleMergeMode.MergedFirst) { foreach(Style style in skinTemplate.Styles) { if(!CanStyleBeMerged(style)) { string styleKey = BuildStyleKey(style); if(!addedStyle.Contains(styleKey) || IsStyleRemote(style)) { templateDefinedStyles.Append(RenderStyleElement(skinPath, style, skinName, styleKey)); addedStyle.Add(styleKey); } } } string mergedStyleLink = RenderStyleElement(skinPath, string.Format("css.axd?name={0}", skinName)); if(skinTemplate.StyleMergeMode == StyleMergeMode.MergedAfter) { finalStyleDefinition = templateDefinedStyles + mergedStyleLink; } else if(skinTemplate.StyleMergeMode == StyleMergeMode.MergedFirst) { finalStyleDefinition = mergedStyleLink + templateDefinedStyles; } } } return Environment.NewLine + finalStyleDefinition; }
public ScriptMergeMode GetScriptMergeMode(string skinName) { SkinTemplate skinTemplate = Templates.ItemOrNull(skinName); return(skinTemplate.ScriptMergeMode); }
public void RenderStyleElementCollection_WithNoStyles_RendersDefaultStyle() { // arrange UnitTestHelper.SetHttpContextWithBlogRequest("localhost", string.Empty, "/"); var pathProvider = new Mock<VirtualPathProvider>(); var skinEngine = new SkinEngine(pathProvider.Object); var renderer = new StyleSheetElementCollectionRenderer(skinEngine); var skinTemplate = new SkinTemplate {ExcludeDefaultStyle = false, Styles = null, TemplateFolder = "TestSkin"}; // act string styleElements = renderer.RenderStyleElementCollection("TestSkin", skinTemplate); // assert const string defaultStyle = @"<link type=""text/css"" rel=""stylesheet"" href=""/Skins/TestSkin/style.css"" />"; Assert.AreEqual(defaultStyle, styleElements.Trim()); }
public ICollection <StyleDefinition> GetStylesToBeMerged(string skinName, string media, string title, string conditional) { bool normalCss = false; var styles = new List <StyleDefinition>(); SkinTemplate skinTemplate = Templates.GetValueOrDefault(skinName); if ((string.IsNullOrEmpty(media)) && string.IsNullOrEmpty(title) && string.IsNullOrEmpty(conditional)) { normalCss = true; } if (skinTemplate != null) { string skinPath = CreateStylePath(skinTemplate.TemplateFolder); if (skinTemplate.Styles != null) { foreach (Style style in skinTemplate.Styles) { if (normalCss) { if (CanStyleBeMerged(style)) { string tmpHref; if (style.Href.StartsWith("~")) { tmpHref = HttpHelper.ExpandTildePath(style.Href); } else { tmpHref = skinPath + style.Href; } styles.Add(new StyleDefinition(tmpHref, style.Media)); } } else { string tmpMedia = style.Media; if (tmpMedia != null && tmpMedia.Equals("all")) { tmpMedia = null; } if (string.Compare(media, tmpMedia, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(title, style.Title, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(conditional, style.Conditional, StringComparison.OrdinalIgnoreCase) == 0) { string tmpHref; if (style.Href.StartsWith("~")) { tmpHref = HttpHelper.ExpandTildePath(style.Href); } else { tmpHref = skinPath + style.Href; } styles.Add(new StyleDefinition(tmpHref, style.Media)); } } } } if (normalCss) { //Main style if (!skinTemplate.ExcludeDefaultStyle) { styles.Add(new StyleDefinition(skinPath + "style.css")); } //Secondary Style if (skinTemplate.HasSkinStylesheet) { styles.Add(new StyleDefinition(skinPath + skinTemplate.StyleSheet)); } } } return(styles); }
public string RenderStyleElementCollection(string skinName, SkinTemplate skinTemplate) { var templateDefinedStyles = new StringBuilder(); string finalStyleDefinition = string.Empty; var addedStyle = new List <string>(); if (skinTemplate != null) { string skinPath = CreateStylePath(skinTemplate.TemplateFolder); // If skin doesn't want to be merged, just write plain css if (skinTemplate.StyleMergeMode == StyleMergeMode.None) { if (skinTemplate.Styles != null) { foreach (Style style in skinTemplate.Styles) { templateDefinedStyles.Append(RenderStyleElement(skinPath, style)); } } if (!skinTemplate.ExcludeDefaultStyle) { templateDefinedStyles.Append(RenderStyleElement(skinPath, "style.css")); } if (skinTemplate.HasSkinStylesheet) { templateDefinedStyles.Append(RenderStyleElement(skinPath, skinTemplate.StyleSheet)); } finalStyleDefinition = templateDefinedStyles.ToString(); } else if (skinTemplate.StyleMergeMode == StyleMergeMode.MergedAfter || skinTemplate.StyleMergeMode == StyleMergeMode.MergedFirst) { foreach (Style style in skinTemplate.Styles) { if (!CanStyleBeMerged(style)) { string styleKey = BuildStyleKey(style); if (!addedStyle.Contains(styleKey) || IsStyleRemote(style)) { templateDefinedStyles.Append(RenderStyleElement(skinPath, style, skinName, styleKey)); addedStyle.Add(styleKey); } } } string mergedStyleLink = RenderStyleElement(skinPath, string.Format("css.axd?name={0}", skinName)); if (skinTemplate.StyleMergeMode == StyleMergeMode.MergedAfter) { finalStyleDefinition = templateDefinedStyles + mergedStyleLink; } else if (skinTemplate.StyleMergeMode == StyleMergeMode.MergedFirst) { finalStyleDefinition = mergedStyleLink + templateDefinedStyles; } } } return(Environment.NewLine + finalStyleDefinition); }
public string RenderStyleElementCollection(string skinName) { SkinTemplate skinTemplate = Templates.GetValueOrDefault(skinName); return(RenderStyleElementCollection(skinName, skinTemplate)); }
protected string GetSkinIconImage(SkinTemplate skin) { var imageUrls = new[] { string.Format(CultureInfo.InvariantCulture, "~/skins/{0}/SkinIcon.png", skin.TemplateFolder), string.Format(CultureInfo.InvariantCulture, "~/skins/{0}/{1}-SkinIcon.png", skin.TemplateFolder, skin.Name), "~/skins/_System/SkinIcon.png" }; string imageUrl = imageUrls.First(path => System.IO.File.Exists(Server.MapPath(path))); return HttpHelper.ExpandTildePath(imageUrl); }
public string RenderStyleElementCollection(string skinName) { SkinTemplate skinTemplate = Templates.ItemOrNull(skinName); return(RenderStyleElementCollection(skinName, skinTemplate)); }
public ScriptMergeMode GetScriptMergeMode(string skinName) { SkinTemplate skinTemplate = Templates.GetValueOrDefault(skinName); return(skinTemplate.ScriptMergeMode); }