/// <summary> /// 设置Script引用 /// </summary> /// <param name="basePath">基路径</param> /// <param name="fileName">文件名称</param> /// <param name="debugFileName">在调试状态使用的文件</param> /// <param name="renderPriority">呈现优先级</param> /// <param name="renderLocation">在页面中的呈现位置</param> /// <param name="htmlAttributes">设置的html属性</param> public void IncludeScript(string basePath, string fileName, string debugFileName = null, ResourceRenderPriority renderPriority = ResourceRenderPriority.Unspecified, ResourceRenderLocation renderLocation = ResourceRenderLocation.Head, IDictionary <string, string> htmlAttributes = null) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } ResourceEntry resource = new ResourceEntry(PageResourceType.JS, basePath, fileName, debugFileName, renderPriority, renderLocation, htmlAttributes); _includedScripts.Add(resource); }
/// <summary> /// 获取ResourceEntry呈现的html /// </summary> /// <param name="resource">资源实体</param> /// <returns>返回用于html呈现的字符串</returns> public string GetRenderingHtml(ResourceEntry resource) { TagBuilder tagBuilder; TagRenderMode tagRenderMode; string originalUrl = resource.BasePath ?? string.Empty; if (DebugEnabled && !string.IsNullOrEmpty(resource.DebugUrl)) { originalUrl += resource.DebugUrl; } else { originalUrl += resource.Url; } string url = ResolveUrlWithResourceSite(originalUrl); if (resource.ResourceType == PageResourceType.JS) { tagBuilder = new TagBuilder("script"); tagRenderMode = TagRenderMode.Normal; tagBuilder.MergeAttribute("src", url); tagBuilder.MergeAttribute("type", "text/javascript"); } else { tagBuilder = new TagBuilder("link"); tagRenderMode = TagRenderMode.SelfClosing; tagBuilder.MergeAttribute("href", url); tagBuilder.MergeAttribute("type", "text/css"); tagBuilder.MergeAttribute("rel", "stylesheet"); } if (resource.HasAttributes) { tagBuilder.MergeAttributes <string, string>(resource.Attributes); } return(tagBuilder.ToString(tagRenderMode)); }