Allow for a callback to execute to modify the pre-processing pipeline at runtime for a web file #59

Closed
Shazwazza opened this Issue Dec 30, 2016 · 0 comments

Projects

None yet

1 participant

@Shazwazza
Owner

in Smidge 2.0 you can specify a callback in options to modify the default pipeline, for example:

services.AddSmidge(_config)
    .Configure<SmidgeOptions>(options =>
    {
        options.PipelineFactory.OnGetDefault = GetDefaultPipelineFactory;
    });

The GetDefaultPipeline method could do something like:

/// <summary>
/// A callback used to modify the default pipeline to use Nuglify for JS processing
/// </summary>
/// <param name="fileType"></param>
/// <param name="processors"></param>
/// <returns></returns>
private static PreProcessPipeline GetDefaultPipelineFactory(WebFileType fileType, IReadOnlyCollection<IPreProcessor> processors)
{
    switch (fileType)
    {
        case WebFileType.Js:
            return new PreProcessPipeline(new IPreProcessor[]
            {
                processors.OfType<NuglifyJs>().Single()
            });                
    }
    //returning null will fallback to the logic defined in the registered PreProcessPipelineFactory
    return null;
}
@Shazwazza Shazwazza added this to the 2.0 milestone Dec 30, 2016
@Shazwazza Shazwazza closed this Dec 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment