Permalink
Browse files

Fix up extension bugs so UglifyJS works

  • Loading branch information...
1 parent 261315b commit 56be87d9fa65dd4e30eb0b9f26a923b0f0df38d6 @paulcbetts committed May 18, 2011
@@ -77,7 +77,7 @@
<Compile Include="CoffeeScriptCompilerTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SassFileCompilerTest.cs" />
- <Compile Include="Scratch.cs" />
+ <Compile Include="MinifyingCompilerTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@@ -35,7 +35,7 @@ public void ProcessRequest(HttpContext context)
// extensions we're interested in
foreach (var ext in _compiler.InputFileExtensions) {
fi = new FileInfo(Path.Combine(fi.DirectoryName,
- Path.GetFileNameWithoutExtension(fi.FullName) + ext));
+ fi.FullName.ToLowerInvariant().Replace(_compiler.OutputFileExtension, "") + ext));
if (fi.Exists) {
break;
@@ -9,29 +9,32 @@ namespace SassAndCoffee
{
public class CompilableFileModule : IHttpModule
{
- Dictionary<string, IHttpHandler> _handlers;
+ Dictionary<ISimpleFileCompiler, IHttpHandler> _handlers;
public void Init(HttpApplication context)
{
var compilers = new ISimpleFileCompiler[] {
+ new MinifyingFileCompiler(),
new CoffeeScriptFileCompiler(),
new SassFileCompiler(),
};
- _handlers = new Dictionary<string, IHttpHandler>();
+ _handlers = new Dictionary<ISimpleFileCompiler, IHttpHandler>();
foreach (var compiler in compilers) {
compiler.Init(context);
- _handlers[compiler.OutputFileExtension] = new CompilableFileHandler(compiler);
+ _handlers[compiler] = new CompilableFileHandler(compiler);
}
context.PostResolveRequestCache += (o, e) => {
var app = o as HttpApplication;
- string ext = Path.GetExtension(app.Request.PhysicalPath.ToLowerInvariant());
- if (!_handlers.ContainsKey(ext)) {
+ string path = app.Request.PhysicalPath.ToLowerInvariant();
+ var compiler = _handlers.Keys.FirstOrDefault(x => path.EndsWith(x.OutputFileExtension));
+
+ if (compiler == null) {
return;
}
- app.Context.RemapHandler(_handlers[ext]);
+ app.Context.RemapHandler(_handlers[compiler]);
};
}
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
+using System.Web;
using Jurassic;
namespace SassAndCoffee
@@ -39,4 +41,36 @@ ScriptEngine initializeMinificationEngine()
return se;
}
}
+
+ public class MinifyingFileCompiler : ISimpleFileCompiler
+ {
+ MinifyingCompiler _engine;
+
+ public string[] InputFileExtensions {
+ get { return new[] {".js"}; }
+ }
+
+ public string OutputFileExtension {
+ get { return ".min.js"; }
+ }
+
+ public string OutputMimeType {
+ get { return "text/javascript"; }
+ }
+
+ public void Init(HttpApplication context)
+ {
+ _engine = new MinifyingCompiler();
+ }
+
+ public string ProcessFileContent(string inputFileContent)
+ {
+ try {
+ var ret = _engine.Compile(File.ReadAllText(inputFileContent));
+ return ret;
+ } catch (Exception ex) {
+ return ex.Message;
+ }
+ }
+ }
}
View
@@ -128,14 +128,14 @@
<Content Include="Global.asax" />
<Content Include="Scripts\jquery-1.5.1-vsdoc.js" />
<Content Include="Scripts\jquery-1.5.1.js" />
- <Content Include="Scripts\jquery-1.5.1.min.js" />
+ <Content Include="Scripts\jquery-1.5.1.minorig.js" />
<Content Include="Scripts\jquery-ui-1.8.11.js" />
<Content Include="Scripts\jquery-ui-1.8.11.min.js" />
<Content Include="Scripts\jquery.validate-vsdoc.js" />
<Content Include="Scripts\jquery.validate.js" />
<Content Include="Scripts\jquery.validate.min.js" />
<Content Include="Scripts\modernizr-1.7.js" />
- <Content Include="Scripts\modernizr-1.7.min.js" />
+ <Content Include="Scripts\modernizr-1.7.minorig.js" />
<Content Include="Web.config" />
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>

0 comments on commit 56be87d

Please sign in to comment.