/// <summary> /// 显示模板信息到页面 /// </summary> public static void PrintTemplatesInfo() { string templateContent = Embed.SysTemplatePage; StringBuilder sb = new StringBuilder(); sb.Append(@"<style type=""text/css""> table{width:100%;background:#eee;margin:0 auto;line-height:25px;color:#222;cursor:pointer} table td{background:white;padding:0 8px;} table th{background:#006699;color:white;} table tr.hover td{background:#222;color:white;} table tr.even td{} </style> <script type=""text/javascript""> function dynamicTable(table) { if (table && table.nodeName === 'TABLE') { var rows = table.getElementsByTagName('tr'); for (var i = 0; i < rows.length; i++) { if (i % 2 == 1) if (!rows[i].className) rows[i].className = 'even'; rows[i].onmouseover = function () { this.className = this.className.indexOf('even') != -1 ? 'hover even' : 'hover'; }; rows[i].onmouseout = function () { this.className = this.className.indexOf('even') == -1 ? '' : 'even'; }; } } }</script> <table cellspacing=""1"" id=""templates""> <tr> <th style=""width:50px;""></th><th style=""width:150px;"">模板编号</th><th style=""width:80px;"">模板类型</th><th>文件名</th><th>模板注释</th><th>文件路径</th></tr> <!-- <tr><td colspan=""6"" align=""center"" style=""background:#c20000;color:white"">扩展名为“.phtml”表示为一个部分视图;部分视图只能使用ID命名</td></tr> -->" ); Template tpl; string tplFileName, tplContent; //模板文件名,内容 int i = 0; foreach (string key in TemplateCache.templateDictionary.Keys) { tpl = TemplateCache.templateDictionary[key]; tplFileName = new Regex("templates(/|\\\\)+#*(.+?)$", RegexOptions.IgnoreCase).Match(tpl.FilePath).Groups[2].Value .Replace("\\", "/"); tplContent = tpl.Content; sb.Append("<tr><td class=\"center\">").Append((++i).ToString()).Append("</td><td class=\"center\">") .Append(key.ToLower()).Append("</td><td class=\"center\">") .Append( //RegexUtility.partialRegex.IsMatch(tplContent) && tplContent.IndexOf("<title>") != -1 !tpl.FilePath.EndsWith(".phtml") ? "<span style=\"color:#333\">模板页面</span>" : "<span style=\"color:#006699\">部分视图</span>") .Append("</td><td>/").Append(tplFileName).Append("</td><td>").Append(tpl.Comment) .Append("</td><td>").Append(tpl.FilePath).Append("</td></tr>"); } sb.Append(@"<tr><td colspan=""6"" align=""center"" style=""background:#f0f0f0;color:#333""> 部分视图扩展名为“.phtml”,可允许格式如: A:${partial:""inc/header.phtml""} B:${partial:""/tmpdir/inc/header.phtml""} C:${partial:""../../inc/header.phtml""} </td></tr>" ); sb.Append( "</table><script type=\"text/javascript\">dynamicTable(document.getElementsByTagName('table')[0]);</script>"); templateContent = TemplateRegexUtility.Replace(templateContent, match => { switch (match.Groups[1].Value) { case "title": return("模板信息"); case "content": return(sb.ToString()); case "year": return(DateTime.Now.Year.ToString()); } return(String.Empty); }); System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.Write(TemplateUtility.CompressHtml(templateContent)); response.End(); }
/// <summary> /// 压缩后的字符 /// </summary> /// <returns></returns> public string ToCompressedString() { return(TemplateUtility.CompressHtml(ToString())); }