Permalink
Browse files

Add NSass/libsass as a processor for SASS:

  Remove SassProcessor from Global.asax because it makes testing the
  NSassProcessor impossible.
  AutoBundling tests for SASS are broken because the handler is no longer
  registered - will need to work this out with Alex Cuse.
  • Loading branch information...
Josh Kodroff
Josh Kodroff committed Mar 4, 2014
1 parent 0562e28 commit 6c0dc5e8b43c276771d4f09e26b9d6dc5bb0009f
Showing with 508 additions and 39 deletions.
  1. +2 −0 .gitignore
  2. BIN SquishIt.NSass/NSass.Wrapper/NSass.Wrapper.x64.dll
  3. BIN SquishIt.NSass/NSass.Wrapper/NSass.Wrapper.x86.dll
  4. +18 −0 SquishIt.NSass/NSassPreprocessor.cs
  5. +36 −0 SquishIt.NSass/Properties/AssemblyInfo.cs
  6. +69 −0 SquishIt.NSass/SquishIt.NSass.csproj
  7. +4 −0 SquishIt.NSass/packages.config
  8. +238 −0 SquishIt.Tests/NSassTests.cs
  9. +5 −0 SquishIt.Tests/SquishIt.Tests.csproj
  10. +11 −1 SquishIt.sln
  11. +6 −5 SquishItAspNetMvcTest/Controllers/PreprocessorsController.cs
  12. +0 −7 SquishItAspNetMvcTest/Global.asax.cs
  13. +13 −0 SquishItAspNetMvcTest/SquishItAspNetMvcTest.csproj
  14. +3 −2 SquishItAspNetMvcTest/Views/Home/Index.cshtml
  15. +20 −0 SquishItAspNetMvcTest/Views/Preprocessors/NSass.cshtml
  16. +2 −0 SquishItAspNetMvcTest/Views/Preprocessors/Sass.cshtml
  17. +17 −23 SquishItAspNetMvcTest/Web.config
  18. +26 −0 nuspec/squishit.nsass.nuspec
  19. +7 −1 nuspec/squishit.sass.nuspec
  20. BIN packages/NSass.Core.0.0.3.0/NSass.Core.0.0.3.0.nupkg
  21. +21 −0 packages/NSass.Core.0.0.3.0/NSass.Core.0.0.3.0.nuspec
  22. BIN packages/NSass.Core.0.0.3.0/content/NSass.Wrapper/NSass.Wrapper.x64.dll
  23. BIN packages/NSass.Core.0.0.3.0/content/NSass.Wrapper/NSass.Wrapper.x86.dll
  24. BIN packages/NSass.Core.0.0.3.0/lib/net40/NSass.Core.dll
  25. BIN packages/NSass.Core.0.0.3.0/lib/net40/NSass.Wrapper.x64.dll
  26. BIN packages/NSass.Core.0.0.3.0/lib/net40/NSass.Wrapper.x86.dll
  27. +9 −0 packages/NSass.Core.0.0.3.0/tools/Install.ps1
  28. +1 −0 packages/repositories.config
View
@@ -23,3 +23,5 @@ SquishItAspNetMvcTest/output/
#crap for generating html docs
*SquishIt.shfbproj_*
+
+.sass-cache
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
+using NSass;
+using SquishIt.Framework;
+using SquishIt.Framework.Base;
+
+namespace SquishIt.NSass
+{
+ public class NSassPreprocessor : Preprocessor
+ {
+ public override IProcessResult Process(string filePath, string content)
+ {
+ return new ProcessResult(new SassCompiler().Compile(content));
+ }
+ public override string[] Extensions
+ {
+ get { return new[] { ".scss" }; }
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("SquishIt.NSass")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("SquishIt.NSass")]
+[assembly: AssemblyCopyright("Copyright © 2014")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a910b261-e806-488c-b313-42a3455926cc")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// 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("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{8D1EE11A-C71D-453D-B0BC-0A76C20B010E}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SquishIt.NSass</RootNamespace>
+ <AssemblyName>SquishIt.NSass</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="NSass.Core">
+ <HintPath>..\packages\NSass.Core.0.0.3.0\lib\net40\NSass.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="NSassPreprocessor.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\SquishIt.Framework\SquishIt.Framework.csproj">
+ <Project>{50C3BC24-E534-4B78-8E8E-CB2C4053321D}</Project>
+ <Name>SquishIt.Framework</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="NSass.Wrapper\NSass.Wrapper.x64.dll">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="NSass.Wrapper\NSass.Wrapper.x86.dll">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NSass.Core" version="0.0.3.0" targetFramework="net40" />
+</packages>
@@ -0,0 +1,238 @@
+using System;
+using NUnit.Framework;
+using SquishIt.Framework.Files;
+using SquishIt.Framework.Utilities;
+using SquishIt.NSass;
+using SquishIt.Tests.Helpers;
+using SquishIt.Tests.Stubs;
+
+namespace SquishIt.Tests
+{
+ [TestFixture]
+ public class NSassTests
+ {
+ CSSBundleFactory cssBundleFactory;
+ IHasher hasher;
+ string scss = @"$blue: #3bbfce;
+ $margin: 16px;
+
+ .content-navigation {
+ border-color: $blue;
+ color:
+ darken($blue, 9%);
+ }
+
+ .border {
+ padding: $margin / 2;
+ margin: $margin / 2;
+ border-color: $blue;
+ }";
+
+ string renderedCss = @".content-navigation{border-color:#3bbfce;color:#2ca2af}.border{padding:8px;margin:8px;border-color:#3bbfce}";
+
+
+ [SetUp]
+ public void Setup()
+ {
+ cssBundleFactory = new CSSBundleFactory();
+ var retryableFileOpener = new RetryableFileOpener();
+ hasher = new Hasher(retryableFileOpener);
+ }
+
+ [Test]
+ public void CanBundleCssWithScss()
+ {
+ using (new StylePreprocessorScope<NSassPreprocessor>())
+ {
+ var cssBundle = cssBundleFactory
+ .WithHasher(hasher)
+ .WithDebuggingEnabled(false)
+ .WithContents(scss)
+ .Create();
+
+ string tag = cssBundle
+ .Add("~/css/test.scss")
+ .Render("~/css/output.css");
+
+ string contents =
+ cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")];
+
+ Assert.AreEqual(
+ @"<link rel=""stylesheet"" type=""text/css"" href=""css/output.css?r=5C851B7837C923C399A44B1F5BF9F14A"" />",
+ tag);
+ Assert.AreEqual(renderedCss, contents);
+ }
+ }
+
+
+ [Test]
+ public void CanBundleCssWithArbitraryScss()
+ {
+ using (new StylePreprocessorScope<NSassPreprocessor>())
+ {
+ var cssBundle = cssBundleFactory
+ .WithHasher(hasher)
+ .WithDebuggingEnabled(false)
+ .Create();
+
+ string tag = cssBundle
+ .AddString(scss, ".scss")
+ .Render("~/css/output.css");
+
+ string contents = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")];
+
+ Assert.AreEqual(@"<link rel=""stylesheet"" type=""text/css"" href=""css/output.css?r=5C851B7837C923C399A44B1F5BF9F14A"" />", tag);
+ Assert.AreEqual(renderedCss, contents);
+ }
+ }
+
+ [Test]
+ public void CanBundleCssInDebugWithArbitraryScss()
+ {
+ using (new StylePreprocessorScope<NSassPreprocessor>())
+ {
+ var cssBundle = cssBundleFactory
+ .WithHasher(hasher)
+ .WithDebuggingEnabled(true)
+ .Create();
+
+ var tag = cssBundle
+ .AddString(scss, ".scss")
+ .Render("~/css/output.css");
+
+ var expected = TestUtilities.NormalizeLineEndings(
+@"<style type=""text/css"">/* line 4, source string */
+.content-navigation {
+ border-color: #3bbfce;
+ color: #2ca2af; }
+
+/* line 10, source string */
+.border {
+ padding: 8px;
+ margin: 8px;
+ border-color: #3bbfce; }
+</style>") + Environment.NewLine;//account for stringbuilder
+
+ Assert.AreEqual(expected, tag);
+ }
+ }
+
+ [Test]
+ public void CanUseNesting()
+ {
+ using (new StylePreprocessorScope<NSassPreprocessor>())
+ {
+ var original =
+ @"table.hl {
+ margin: 2em 0;
+ td.ln {
+ text-align: right;
+ }
+ }
+
+ li {
+ font: {
+ family: serif;
+ weight: bold;
+ size: 1.2em;
+ }
+ }";
+
+ var expected =
+ @"table.hl{margin:2em 0}table.hl td.ln{text-align:right}li{font-family:serif;font-weight:bold;font-size:1.2em}";
+
+ var cssBundle = cssBundleFactory
+ .WithHasher(hasher)
+ .WithDebuggingEnabled(false)
+ .WithContents(original)
+ .Create();
+
+ cssBundle
+ .Add("~/css/test.scss")
+ .Render("~/css/output.css");
+
+ string contents =
+ cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")];
+ Assert.AreEqual(expected, contents);
+ }
+ }
+
+ [Test]
+ public void CanUseMixins()
+ {
+ using (new StylePreprocessorScope<NSassPreprocessor>())
+ {
+ var original =
+ @"@mixin table-base {
+ th {
+ text-align: center;
+ font-weight: bold;
+ }
+ td, th {padding: 2px}
+ }
+
+ @mixin left($dist) {
+ float: left;
+ margin-left: $dist;
+ }
+
+ #data {
+ @include left(10px);
+ @include table-base;
+ }";
+
+ var expected =
+ @"#data{float:left;margin-left:10px}#data th{text-align:center;font-weight:bold}#data td,#data th{padding:2px}";
+
+ var cssBundle = cssBundleFactory
+ .WithHasher(hasher)
+ .WithDebuggingEnabled(false)
+ .WithContents(original)
+ .Create();
+
+ cssBundle
+ .Add("~/css/test.scss")
+ .Render("~/css/output.css");
+
+ string contents =
+ cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")];
+ Assert.AreEqual(expected, contents);
+ }
+ }
+
+ [Test]
+ public void CanUseSelectorInheritance()
+ {
+ using (new StylePreprocessorScope<NSassPreprocessor>())
+ {
+ var original =
+ @".error {
+ margin-right: 1px;
+ }
+ .error.intrusion {
+ margin-left: 1px;
+ }
+ .badError {
+ @extend .error;
+ margin-top: 1px;
+ }";
+
+ var expected = @".error,.badError{margin-right:1px}.error.intrusion{margin-left:1px}.badError{margin-top:1px}";
+
+ var cssBundle = cssBundleFactory
+ .WithHasher(hasher)
+ .WithDebuggingEnabled(false)
+ .WithContents(original)
+ .Create();
+
+ cssBundle
+ .Add("~/css/test.scss")
+ .Render("~/css/output.css");
+
+ var contents = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output.css")];
+
+ Assert.AreEqual(expected, contents);
+ }
+ }
+ }
+}
@@ -97,6 +97,7 @@
<Compile Include="HasherTests.cs" />
<Compile Include="HoganTests.cs" />
<Compile Include="RelativePathAdapterTest.cs" />
+ <Compile Include="NSassTests.cs" />
<Compile Include="ScriptPreprocessorPipelineTests.cs" />
<Compile Include="CriticalRenderingSectionTest.cs" />
<Compile Include="CSSBundleTests.cs" />
@@ -158,6 +159,10 @@
<Project>{1776A1BF-5096-4833-9E28-59D9627A6700}</Project>
<Name>SquishIt.MsIeHogan</Name>
</ProjectReference>
+ <ProjectReference Include="..\SquishIt.NSass\SquishIt.NSass.csproj">
+ <Project>{8D1EE11A-C71D-453D-B0BC-0A76C20B010E}</Project>
+ <Name>SquishIt.NSass</Name>
+ </ProjectReference>
<ProjectReference Include="..\SquishIt.Sass\SquishIt.Sass.csproj">
<Project>{EC304F39-5916-45ED-A289-ABEFF1EDD070}</Project>
<Name>SquishIt.Sass</Name>
Oops, something went wrong.

0 comments on commit 6c0dc5e

Please sign in to comment.