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);
        }
Exemplo n.º 2
0
        public string[] Process(KraftBundle kraftBundle, ILogger logger)
        {
            #region Check validity
            if (kraftBundle == null)
            {
                throw new ArgumentNullException(nameof(kraftBundle));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (string.IsNullOrEmpty(kraftBundle.ContentRootPath))
            {
                throw new ArgumentNullException(nameof(kraftBundle.ContentRootPath));
            }
            if (string.IsNullOrEmpty(kraftBundle.StartDirPath))
            {
                throw new ArgumentNullException(nameof(kraftBundle.StartDirPath));
            }
            if (!(kraftBundle is KraftBundleProfiles kraftBundleProfiles))
            {
                return(null);
            }
            if (kraftBundleProfiles.ProfileFiles == null)
            {
                throw new ArgumentNullException(nameof(kraftBundleProfiles.ProfileFiles));
            }
            #endregion Check validity

            List <string> outputFilesList = new List <string>();
            DirectoryInfo scrRootDir      = new DirectoryInfo(kraftBundle.StartDirPath);

            //start parsing from the script file of the builder object
            foreach (string profile in kraftBundleProfiles.ProfileFiles)
            {
                FileInfo bootstrapFile = new FileInfo(Path.Combine(kraftBundle.StartDirPath, profile));
                if (bootstrapFile.Exists)//Check the profile files one by one and break if first found
                {
                    ParseFilesForIncludesRecursive(bootstrapFile, scrRootDir, logger, outputFilesList);
                    break;
                }
                //outputFilesList.Add(bootstrapFile.ToString());
            }
            outputFilesList = ProcessMappedFiles2VirtualPaths(outputFilesList, kraftBundle.ContentRootPath);
            return(outputFilesList.ToArray());
        }
Exemplo n.º 3
0
        public InputFile[] Process(KraftBundle kraftBundle, string modulePath, string moduleName, string rootVirtualPath, ILogger logger)
        {
            #region Check validity
            if (kraftBundle == null)
            {
                throw new ArgumentNullException(nameof(kraftBundle));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (string.IsNullOrEmpty(kraftBundle.ContentRootPath))
            {
                throw new ArgumentNullException(nameof(kraftBundle.ContentRootPath));
            }
            if (string.IsNullOrEmpty(kraftBundle.StartDirPath))
            {
                throw new ArgumentNullException(nameof(kraftBundle.StartDirPath));
            }
            if (!(kraftBundle is KraftBundleProfiles kraftBundleProfiles))
            {
                return(null);
            }
            if (kraftBundleProfiles.ProfileFiles == null)
            {
                throw new ArgumentNullException(nameof(kraftBundleProfiles.ProfileFiles));
            }
            #endregion Check validity

            List <string> outputFilesList = new List <string>();
            DirectoryInfo scrRootDir      = new DirectoryInfo(kraftBundle.StartDirPath);

            foreach (string profile in kraftBundleProfiles.ProfileFiles)
            {
                FileInfo bootstrapFile = new FileInfo(Path.Combine(kraftBundle.StartDirPath, profile));
                if (bootstrapFile.Exists)//Check the profile files one by one and break if first found
                {
                    ParseFilesForIncludesRecursive(bootstrapFile, scrRootDir, logger, outputFilesList);
                    break;
                }
            }

            InputFile[] inputFiles = ProcessMappedFiles2VirtualPaths(outputFilesList, modulePath, moduleName);
            return(inputFiles);
        }