Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Created March 8, 2012 03:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howarddierking/1998379 to your computer and use it in GitHub Desktop.
Save howarddierking/1998379 to your computer and use it in GitHub Desktop.
example of a chained bundle transform using less
protected void Application_Start()
{
//...
Bundle cssBundle = new Bundle("~/Content/css", new LessTransform().Then(new CssMinify()));
cssBundle.AddFile("~/Content/site.css", throwIfNotExist: false);
cssBundle.AddDirectory("~/Content/", "jquery.mobile*", searchSubdirectories: false, throwIfNotExist: false);
BundleTable.Bundles.Add(cssBundle);
//...
}
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
response.Content = Less.Parse(response.Content);
response.ContentType = "text/css";
}
}
public static class BundleTransformExtensions {
public static IBundleTransform Then(this IBundleTransform source, IBundleTransform add)
{
return new ChainedBundle(source, add);
}
}
public class ChainedBundle : IBundleTransform
{
IBundleTransform _source;
IBundleTransform _add;
public ChainedBundle(IBundleTransform source, IBundleTransform add)
{
_source = source;
_add = add;
}
public void Process(BundleContext context, BundleResponse response)
{
_source.Process(context, response);
_add.Process(context, response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment