// 按照类型, 输出JS或CSS脚本块 string GetBlock(IncludeFile file) { string template = ""; if (this.fileType == "js") { template = " <script type=\"text/javascript\" src=\"{0}?v={1}\"></script>"; } if (this.fileType == "css") { template = " <link type=\"text/css\" href=\"{0}?v={1}\" rel=\"stylesheet\" />"; } return string.Format(template, file.Src, file.Version); }
IncludeFile outputFile; // 输出文件(压缩合并后的文件) #endregion Fields #region Constructors public BlockHelper(string content, string outputDir, string fileType, bool compress, bool merge) { this.content = content; this.outputDir = outputDir; this.fileType = fileType; this.compress = compress; this.merge = merge; this.files = GetFiles(); this.outputFile = GetOutputFile(); // 如果输出目录不存在,则创建 if (!Directory.Exists(Server.MapPath(this.outputDir))) { Directory.CreateDirectory(Server.MapPath(this.outputDir)); } }