Created
March 8, 2012 03:20
-
-
Save howarddierking/1998379 to your computer and use it in GitHub Desktop.
example of a chained bundle transform using less
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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