Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add .min support for Sass/SCSS. Bump version number to reflect change.

  • Loading branch information...
commit 0d7149f3742378ceaf2a9559517a04a4e83db157 1 parent 13f9898
@kogir kogir authored
View
4 CommonAssemblyInfo.cs
@@ -28,5 +28,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.0.0.0")]
-[assembly: AssemblyFileVersion("2.0.0.0")]
+[assembly: AssemblyVersion("2.0.1.0")]
+[assembly: AssemblyFileVersion("2.0.1.0")]
View
5 SassAndCoffee.AspNet.WebTests/Views/Test/Index.cshtml
@@ -4,9 +4,13 @@
<div>
<h2>CoffeeScript</h2>
<a href="@Url.Content("~/Scripts/class.js")">class.coffee</a>
+ <a href="@Url.Content("~/Scripts/class.min.js")">class.coffee (min)</a>
<a href="@Url.Content("~/Scripts/class.bare.js")">class.coffee (bare)</a>
+ <a href="@Url.Content("~/Scripts/class.bare.min.js")">class.coffee (min, bare)</a>
<a href="@Url.Content("~/Scripts/main.js")">main.coffee</a>
+ <a href="@Url.Content("~/Scripts/main.min.js")">main.coffee (min)</a>
<a href="@Url.Content("~/Scripts/main.bare.js")">main.coffee (bare)</a>
+ <a href="@Url.Content("~/Scripts/main.bare.min.js")">main.coffee (min, bare)</a>
</div>
<div>
<h2>Combine</h2>
@@ -16,6 +20,7 @@
<div>
<h2>SCSS</h2>
<a href="@Url.Content("~/Content/style.css")">style.scss</a>
+ <a href="@Url.Content("~/Content/style.min.css")">style.scss (min)</a>
</div>
<div>
<h2>Sass</h2>
View
2  SassAndCoffee.Core.Tests/SassFileCompilerTest.cs
@@ -49,7 +49,7 @@ public class SassFileCompilerTest {
// TODO: Fix this
// fixture.Init(TODO);
- string result = fixture.Compile(filename);
+ string result = fixture.Compile(filename, true, null);
Console.WriteLine(result);
return result;
} finally {
View
2  SassAndCoffee.Ruby/Sass/ISassCompiler.cs
@@ -3,6 +3,6 @@
using System.Collections.Generic;
public interface ISassCompiler : IDisposable {
- string Compile(string path, IList<string> dependentFileList = null);
+ string Compile(string path, bool compressed, IList<string> dependentFileList);
}
}
View
28 SassAndCoffee.Ruby/Sass/ResourceRedirectionPlatformAdaptationLayer.cs
@@ -50,12 +50,38 @@ public class ResourceRedirectionPlatformAdaptationLayer : PlatformAdaptationLaye
private string PathToResourceName(string path) {
// This is kind of a hack, but I couldn't think of anything better worth the effort.
- return path
+ return path
.Replace("1.9.1", "_1._9._1")
.Replace('\\', '.')
.Replace('/', '.')
.Replace(@"R:.{345ED29D-C275-4C64-8372-65B06E54F5A7}", "")
.TrimStart('.');
}
+
+ /* These methods are disabled for safety. We shouldn't need them. */
+
+ public override void CreateDirectory(string path) {
+ throw new NotImplementedException();
+ }
+
+ public override void DeleteDirectory(string path, bool recursive) {
+ throw new NotImplementedException();
+ }
+
+ public override void DeleteFile(string path, bool deleteReadOnly) {
+ throw new NotImplementedException();
+ }
+
+ public override void MoveFileSystemEntry(string sourcePath, string destinationPath) {
+ throw new NotImplementedException();
+ }
+
+ public override void SetEnvironmentVariable(string key, string value) {
+ throw new NotImplementedException();
+ }
+
+ public override Stream OpenOutputFileStream(string path) {
+ throw new NotImplementedException();
+ }
}
}
View
19 SassAndCoffee.Ruby/Sass/SassCompiler.cs
@@ -15,10 +15,12 @@ public class SassCompiler : ISassCompiler {
private dynamic _sassCompiler;
private dynamic _sassOption;
private dynamic _scssOption;
+ private dynamic _sassOptionCompressed;
+ private dynamic _scssOptionCompressed;
private bool _initialized = false;
private object _lock = new object();
- public string Compile(string path, IList<string> dependentFileList = null) {
+ public string Compile(string path, bool compressed, IList<string> dependentFileList) {
if (path == null)
throw new ArgumentException("source cannot be null.", "source");
@@ -30,10 +32,11 @@ public class SassCompiler : ISassCompiler {
Initialize();
dynamic compilerOptions;
- if (pathInfo.Extension.Equals(".sass", StringComparison.OrdinalIgnoreCase))
- compilerOptions = _sassOption;
- else
- compilerOptions = _scssOption;
+ if (pathInfo.Extension.Equals(".sass", StringComparison.OrdinalIgnoreCase)) {
+ compilerOptions = compressed ? _sassOptionCompressed : _sassOption;
+ } else {
+ compilerOptions = compressed ? _scssOptionCompressed : _scssOption;
+ }
var directoryPath = pathInfo.DirectoryName;
if (!directoryPath.Contains("\'")) {
@@ -98,8 +101,10 @@ public class SassCompiler : ISassCompiler {
source.Execute(_scope);
_sassCompiler = _scope.Engine.Runtime.Globals.GetVariable("Sass");
- _sassOption = _engine.Execute("{:syntax => :sass}");
- _scssOption = _engine.Execute("{:syntax => :scss}");
+ _sassOption = _engine.Execute("{:cache => false, :syntax => :sass}");
+ _scssOption = _engine.Execute("{:cache => false, :syntax => :scss}");
+ _sassOptionCompressed = _engine.Execute("{:cache => false, :syntax => :sass, :style => :compressed}");
+ _scssOptionCompressed = _engine.Execute("{:cache => false, :syntax => :scss, :style => :compressed}");
_initialized = true;
}
View
15 SassAndCoffee.Ruby/Sass/SassCompilerContentTransform.cs
@@ -1,14 +1,27 @@
namespace SassAndCoffee.Ruby.Sass {
+ using System;
using System.Collections.Generic;
using System.IO;
using SassAndCoffee.Core;
public class SassCompilerContentTransform : ContentTransformBase {
public const string MimeType = "text/css";
+ public const string CompressedStateKey = "Sass_Compressed";
private Pool<ISassCompiler, SassCompilerProxy> _compilerPool =
new Pool<ISassCompiler, SassCompilerProxy>(() => new SassCompiler());
+ public override void PreExecute(ContentTransformState state) {
+ if (state.Path.EndsWith(".min.css", StringComparison.OrdinalIgnoreCase)) {
+ state.Items.Add(CompressedStateKey, true);
+ var newPath = state.Path
+ .ToLowerInvariant()
+ .Replace(".min.css", ".css");
+ state.RemapPath(newPath);
+ }
+ base.PreExecute(state);
+ }
+
public override void Execute(ContentTransformState state) {
// Support 404, not just 500
if (state.RootPath == null)
@@ -20,7 +33,7 @@ public class SassCompilerContentTransform : ContentTransformBase {
string result = null;
var accessedFiles = new List<string>();
using (var compiler = _compilerPool.GetInstance()) {
- result = compiler.Compile(fileSource, accessedFiles);
+ result = compiler.Compile(fileSource, state.Items.ContainsKey(CompressedStateKey), accessedFiles);
}
if (result != null) {
View
4 SassAndCoffee.Ruby/Sass/SassCompilerProxy.cs
@@ -9,8 +9,8 @@ public class SassCompilerProxy : ProxyBase<ISassCompiler>, ISassCompiler {
public SassCompilerProxy(ISassCompiler compiler)
: base(compiler) { }
- public string Compile(string path, IList<string> dependentFileList = null) {
- return WrappedItem.Compile(path, dependentFileList);
+ public string Compile(string path, bool compressed, IList<string> dependentFileList) {
+ return WrappedItem.Compile(path, compressed, dependentFileList);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.