private PreProcessPipeline GetDefault(WebFileType fileType) { if (_default.TryGetValue(fileType, out PreProcessPipeline pipeline)) { return(pipeline); } switch (fileType) { case WebFileType.Js: _default[fileType] = new PreProcessPipeline(new IPreProcessor[] { _allProcessors.Value.OfType <JsMinifier>().First() }); break; case WebFileType.Css: default: _default[fileType] = new PreProcessPipeline(new IPreProcessor[] { _allProcessors.Value.OfType <CssImportProcessor>().First(), _allProcessors.Value.OfType <CssUrlProcessor>().First(), _allProcessors.Value.OfType <CssMinifier>().First() }); break; } return(_default[fileType]); }
public void Create(string bundleName, PreProcessPipeline pipeline, WebFileType type, params string[] paths) { _bundles.TryAdd( bundleName, type == WebFileType.Css ? paths.Select(x => (IWebFile)new CssFile(x) { Pipeline = pipeline }) : paths.Select(x => (IWebFile)new JavaScriptFile(x) { Pipeline = pipeline })); }
public BundleFileCollection Create(string bundleName, PreProcessPipeline pipeline, WebFileType type, params string[] paths) { var collection = type == WebFileType.Css ? new BundleFileCollection(paths.Select(x => (IWebFile)new CssFile(x) { Pipeline = pipeline }).ToList()) : new BundleFileCollection(paths.Select(x => (IWebFile)new JavaScriptFile(x) { Pipeline = pipeline }).ToList()); _bundles.TryAdd(bundleName, collection); return collection; }
public OrderedFileSet(IEnumerable<IWebFile> files, FileSystemHelper fileSystemHelper, HttpRequest request, PreProcessPipeline defaultPipeline) { _files = files; _defaultPipeline = defaultPipeline; _fileSystemHelper = fileSystemHelper; _request = request; }
public void Create(string bundleName, PreProcessPipeline pipeline, params CssFile[] cssFiles) { foreach (var file in cssFiles) { if (file.Pipeline == null) { file.Pipeline = pipeline; } } _bundles.TryAdd(bundleName, cssFiles); }
public void Create(string bundleName, PreProcessPipeline pipeline, params JavaScriptFile[] jsFiles) { foreach (var file in jsFiles) { if (file.Pipeline == null) { file.Pipeline = pipeline; } } _bundles.TryAdd(bundleName, new List<IWebFile>(jsFiles)); }
public BundleFileCollection Create(string bundleName, PreProcessPipeline pipeline, params CssFile[] cssFiles) { foreach (var file in cssFiles) { if (file.Pipeline == null) { file.Pipeline = pipeline; } } var collection = new BundleFileCollection(new List<IWebFile>(cssFiles)); _bundles.TryAdd(bundleName, collection); return collection; }
/// <summary> /// Replaces a pre processor type with another at the same index /// </summary> /// <typeparam name="TRemove"></typeparam> /// <typeparam name="TAdd"></typeparam> /// <param name="pipeline"></param> /// <param name="pipelineFactory"></param> /// <returns></returns> public static PreProcessPipeline Replace <TRemove, TAdd>(this PreProcessPipeline pipeline, PreProcessPipelineFactory pipelineFactory) where TRemove : IPreProcessor where TAdd : IPreProcessor { for (int i = 0; i < pipeline.Processors.Count; i++) { if (pipeline.Processors[i].GetType() == typeof(TRemove)) { pipeline.Processors.RemoveAt(i); pipeline.Processors.Insert(i, pipelineFactory.Resolve <TAdd>()); } } return(pipeline); }
/// <summary> /// Renders the JS tags /// </summary> /// <returns></returns> /// <remarks> /// TODO: Once the tags are rendered the collection on the context is cleared. Therefore if this method is called multiple times it will /// render anything that has been registered as 'pending' but has not been rendered. /// </remarks> public async Task<HtmlString> JsHereAsync(PreProcessPipeline pipeline = null, bool debug = false) { var result = new StringBuilder(); var urls = await GenerateJsUrlsAsync(pipeline, debug); foreach (var url in urls) { result.AppendFormat("<script src='{0}' type='text/javascript'></script>", url); } return new HtmlString(result.ToString()); }
/// <summary> /// Minifies (and performs any other operation defined in the pipeline) for each file /// </summary> /// <param name="files"></param> /// <param name="pipeline"></param> /// <returns></returns> private async Task ProcessWebFilesAsync(IEnumerable<IWebFile> files, PreProcessPipeline pipeline) { //we need to do the minify on the original files foreach (var file in files) { //if the pipeline on the file is null, assign the default one passed in if (file.Pipeline == null) { file.Pipeline = pipeline; } //We need to check if this path is a folder, then iterate the files if (_fileSystemHelper.IsFolder(file.FilePath)) { var filePaths = _fileSystemHelper.GetPathsForFilesInFolder(file.FilePath); foreach (var f in filePaths) { await _fileManager.ProcessAndCacheFileAsync(new WebFile { FilePath = _fileSystemHelper.NormalizeWebPath(f, _request), DependencyType = file.DependencyType, Pipeline = file.Pipeline }); } } else { await _fileManager.ProcessAndCacheFileAsync(file); } } }
private async Task<IEnumerable<string>> GenerateUrlsAsync( IEnumerable<IWebFile> files, WebFileType fileType, PreProcessPipeline pipeline = null, bool debug = false) { var result = new List<string>(); if (debug) { return GenerateUrlsDebug(files); } else { if (pipeline == null) { pipeline = _processorFactory.GetDefault(fileType); } var compression = _request.GetClientCompression(); //Get the file collection used to create the composite URLs and the external requests var fileBatches = _fileBatcher.GetCompositeFileCollectionForUrlGeneration(files); foreach (var batch in fileBatches) { //if it's external, the rule is that a WebFileBatch can only contain a single external file // it's path will be normalized as an external url so we just use it if (batch.IsExternal) { result.Add(batch.Single().Original.FilePath); } else { //Get the URLs for the batch, this could be more than one resulting URL depending on how many // files are in the batch and the max url length var compositeUrls = _context.UrlCreator.GetUrls(batch.Select(x => x.Hashed), fileType == WebFileType.Css ? ".css" : ".js"); foreach (var u in compositeUrls) { //now we need to determine if these files have already been minified var compositeFilePath = _fileSystemHelper.GetCurrentCompositeFilePath(compression, u.Key); if (!File.Exists(compositeFilePath)) { //need to process/minify these files - need to use their original paths of course await ProcessWebFilesAsync(batch.Select(x => x.Original), pipeline); } result.Add(u.Url); } } } } return result; }
/// <summary> /// Generates the list of URLs to render based on what is registered /// </summary> /// <returns></returns> public async Task<IEnumerable<string>> GenerateCssUrlsAsync(PreProcessPipeline pipeline = null, bool debug = false) { return await GenerateUrlsAsync(_context.CssFiles, WebFileType.Css, pipeline, debug); }
/// <summary> /// Renders the CSS tags /// </summary> /// <returns></returns> /// <remarks> /// TODO: Once the tags are rendered the collection on the context is cleared. Therefore if this method is called multiple times it will /// render anything that has been registered as 'pending' but has not been rendered. /// </remarks> public async Task<HtmlString> CssHereAsync(PreProcessPipeline pipeline = null, bool debug = false) { var result = new StringBuilder(); var urls = await GenerateCssUrlsAsync(pipeline, debug); foreach (var url in urls) { result.AppendFormat("<link href='{0}' rel='stylesheet' type='text/css'/>", url); } return new HtmlString(result.ToString()); }
/// <summary> /// Generates the list of URLs to render based on what is registered /// </summary> /// <returns></returns> public async Task<IEnumerable<string>> GenerateJsUrlsAsync(PreProcessPipeline pipeline = null) { return await GenerateUrlsAsync(_context.JavaScriptFiles, WebFileType.Js, pipeline); }