public StringBuilder Process(KraftBundle kraftBundle, Func <StringBuilder, ILogger, StringBuilder> minifyHtml, ILogger logger) { #region Check validity if (kraftBundle == null) { throw new ArgumentNullException(nameof(kraftBundle)); } #endregion Check validity TemplateKraftBundle templateKraftBundle = kraftBundle as TemplateKraftBundle; StringBuilder sb = new StringBuilder(1000); if (templateKraftBundle != null && templateKraftBundle.TemplateFiles.Count > 0) { if (templateKraftBundle.ModuleName == null) { throw new ArgumentNullException(nameof(templateKraftBundle.ModuleName)); } sb.Append($"\"{templateKraftBundle.ModuleName.ToLower()}\"").Append(":{"); /* "module1": { * "Template1": "html ....", * "Template2": "html ...." * }*/ bool appendDiv = false; foreach (TemplateFile templateFile in templateKraftBundle.TemplateFiles) { if (appendDiv) { sb.Append(","); } else { appendDiv = true; } sb.Append($"\"{templateFile.TemplateName.ToLower()}\":").Append("\"" + /*minifyHtml(*/ GetContent(templateFile.PhysicalPath) .Replace("\"", "\\\"") .Replace("'", "\\\'") .Replace("\r", "") .Replace("\n", "") .Replace("\t", "") /*, logger)*/ + "\""); } sb.Append("}"); } return(sb); }
private TemplateKraftBundle ConstructTmplResBundle(string rootPath, string tmplFolderPath) { if (Directory.Exists(tmplFolderPath)) { TemplateKraftBundle resBundle = new TemplateKraftBundle { ContentRootPath = rootPath }; IFileProvider fileProv = new PhysicalFileProvider(tmplFolderPath); IDirectoryContents dirContents = fileProv.GetDirectoryContents(""); resBundle.StartDirPath = tmplFolderPath; resBundle.ModuleName = Key; foreach (IFileInfo file in dirContents) { string fileExtension = Path.GetExtension(file.PhysicalPath); TemplateFile templateFile = new TemplateFile { TemplateName = file.Name.ToLower().Replace(fileExtension, string.Empty), PhysicalPath = file.PhysicalPath }; resBundle.TemplateFiles.Add(templateFile); } return(resBundle); } return(null); }