Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'origin/master' into preprocessor-pipeline

Conflicts:
	SquishIt.Framework/Bundle.cs
	SquishIt.Tests/SquishIt.Tests.csproj
	SquishIt.Tests/packages.config
	nuspec/squishit.mvc.nuspec
	packages/repositories.config
	releases/squishit.nuspec
  • Loading branch information...
commit ba26514ba3b530867e003d502c5cdcef55db7ddb 2 parents feb614c + 10db2f1
@AlexCuse AlexCuse authored
Showing with 16,231 additions and 38 deletions.
  1. +15 −3 SquishIt.Framework/Base/BundleBase.cs
  2. +1 −1  SquishIt.Framework/Bundle.cs
  3. +42 −11 SquishIt.Framework/Configuration.cs
  4. +1 −1  SquishIt.Framework/Css/CssBundle.cs
  5. +15 −15 SquishIt.Framework/Css/CssPathRewriter.cs
  6. +1 −1  SquishIt.Framework/JavaScript/JavaScriptBundle.cs
  7. +2 −2 SquishIt.Framework/Properties/AssemblyInfo.cs
  8. +2 −2 SquishIt.Mvc/Properties/AssemblyInfo.cs
  9. +40 −2 SquishIt.Tests/CssBundleTests.cs
  10. +47 −0 SquishIt.Tests/CssPathRewriterTests.cs
  11. +33 −0 SquishIt.Tests/JavaScriptBundleTests.cs
  12. +3 −0  SquishIt.Tests/SquishIt.Tests.csproj
  13. +1 −0  SquishIt.Tests/packages.config
  14. +39 −0 packages/Moq.4.0.10827/License.txt
  15. BIN  packages/Moq.4.0.10827/Moq.4.0.10827.nupkg
  16. BIN  packages/Moq.4.0.10827/Moq.chm
  17. BIN  packages/Moq.4.0.10827/lib/NET35/Moq.dll
  18. BIN  packages/Moq.4.0.10827/lib/NET35/Moq.pdb
  19. +5,768 −0 packages/Moq.4.0.10827/lib/NET35/Moq.xml
  20. BIN  packages/Moq.4.0.10827/lib/NET40/Moq.dll
  21. BIN  packages/Moq.4.0.10827/lib/NET40/Moq.pdb
  22. +5,120 −0 packages/Moq.4.0.10827/lib/NET40/Moq.xml
  23. BIN  packages/Moq.4.0.10827/lib/Silverlight4/Castle.Core.dll
  24. BIN  packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.dll
  25. BIN  packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.pdb
  26. +5,101 −0 packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.xml
  27. BIN  releases/SquishIt.0.8.6.nupkg
  28. BIN  releases/SquishIt.Mvc.0.8.6.nupkg
View
18 SquishIt.Framework/Base/BundleBase.cs
@@ -17,7 +17,7 @@ public abstract class BundleBase<T> where T : BundleBase<T>
private static readonly Dictionary<string, string> renderPathCache = new Dictionary<string, string>();
private const string DEFAULT_GROUP = "default";
- protected string BaseOutputHref = String.Empty;
+ protected string BaseOutputHref = Configuration.Instance.DefaultOutputBaseHref() ?? String.Empty;
protected IFileWriterFactory fileWriterFactory;
protected IFileReaderFactory fileReaderFactory;
protected IDebugStatusReader debugStatusReader;
@@ -55,6 +55,7 @@ protected IMinifier<T> Minifier
private static Dictionary<string, BundleState> bundleStateCache = new Dictionary<string, BundleState>();
private IBundleCache bundleCache;
+ private IRenderer releaseRenderer;
protected BundleBase(IFileWriterFactory fileWriterFactory, IFileReaderFactory fileReaderFactory, IDebugStatusReader debugStatusReader, ICurrentDirectoryWrapper currentDirectoryWrapper, IHasher hasher, IBundleCache bundleCache)
{
@@ -68,6 +69,11 @@ protected BundleBase(IFileWriterFactory fileWriterFactory, IFileReaderFactory fi
this.bundleCache = bundleCache;
}
+ protected IRenderer GetReleaseFileRenderer()
+ {
+ return releaseRenderer ?? Configuration.Instance.DefaultReleaseRenderer() ?? new FileRenderer(fileWriterFactory);
+ }
+
private List<string> GetFiles(List<Asset> assets)
{
var inputFiles = GetInputFiles(assets);
@@ -318,10 +324,16 @@ public T WithOutputBaseHref(string href)
return (T)this;
}
+ public T WithReleaseRenderer(IRenderer renderer)
+ {
+ this.releaseRenderer = renderer;
+ return (T) this;
+ }
+
public string Render(string renderTo)
{
string key = renderTo;
- return Render(renderTo, key, new FileRenderer(fileWriterFactory));
+ return Render(renderTo, key, GetReleaseFileRenderer());
}
private string Render(string renderTo, string key, IRenderer renderer)
@@ -371,7 +383,7 @@ public string RenderCachedAssetTag(string name)
public void AsNamed(string name, string renderTo)
{
- Render(renderTo, name, new FileRenderer(fileWriterFactory));
+ Render(renderTo, name, GetReleaseFileRenderer());
bundleState.Path = renderTo;
bundleStateCache[CachePrefix + name] = bundleState;
}
View
2  SquishIt.Framework/Bundle.cs
@@ -91,7 +91,7 @@ public static CSSBundle Css(Utilities.IDebugStatusReader debugStatusReader)
public static Configuration ConfigureDefaults()
{
- return new Configuration();
+ return Configuration.Instance;
}
}
}
View
53 SquishIt.Framework/Configuration.cs
@@ -4,11 +4,23 @@
using SquishIt.Framework.Minifiers;
using SquishIt.Framework.Minifiers.CSS;
using SquishIt.Framework.Minifiers.JavaScript;
+using SquishIt.Framework.Renderers;
namespace SquishIt.Framework
{
public class Configuration
{
+ static Configuration instance;
+ Type _defaultCssMinifier = typeof (MsCompressor);
+ Type _defaultJsMinifier = typeof (MsMinifier);
+ string _defaultOutputBaseHref;
+ IRenderer _defaultReleaseRenderer;
+
+ public static Configuration Instance
+ {
+ get { return (instance = instance ?? new Configuration()); }
+ }
+
public Configuration UseMinifierForCss<TMinifier>()
where TMinifier : IMinifier<CSSBundle>
{
@@ -17,10 +29,10 @@ public Configuration UseMinifierForCss<TMinifier>()
public Configuration UseMinifierForCss(Type minifierType)
{
- if (!typeof(IMinifier<CSSBundle>).IsAssignableFrom(minifierType))
+ if (!typeof (IMinifier<CSSBundle>).IsAssignableFrom(minifierType))
throw new InvalidCastException(
- String.Format("Type '{0}' must implement '{1}' to be used for Css minification.",
- minifierType, typeof (IMinifier<CSSBundle>)));
+ String.Format("Type '{0}' must implement '{1}' to be used for Css minification.",
+ minifierType, typeof (IMinifier<CSSBundle>)));
_defaultCssMinifier = minifierType;
return this;
}
@@ -33,7 +45,7 @@ public Configuration UseMinifierForJs<TMinifier>()
public Configuration UseMinifierForJs(Type minifierType)
{
- if (!typeof(IMinifier<JavaScriptBundle>).IsAssignableFrom(minifierType))
+ if (!typeof (IMinifier<JavaScriptBundle>).IsAssignableFrom(minifierType))
throw new InvalidCastException(
String.Format("Type '{0}' must implement '{1}' to be used for Javascript minification.",
minifierType, typeof (IMinifier<JavaScriptBundle>)));
@@ -105,17 +117,36 @@ public Configuration UseJsMinForJsMinification()
return UseMinifierForJs<JsMinMinifier>();
}
- static Type _defaultCssMinifier = typeof (MsCompressor);
- static Type _defaultJsMinifier = typeof (MsMinifier);
+ internal IMinifier<CSSBundle> DefaultCssMinifier()
+ {
+ return (IMinifier<CSSBundle>) Activator.CreateInstance(_defaultCssMinifier, true);
+ }
+
+ internal IMinifier<JavaScriptBundle> DefaultJsMinifier()
+ {
+ return (IMinifier<JavaScriptBundle>) Activator.CreateInstance(_defaultJsMinifier, true);
+ }
- internal static IMinifier<CSSBundle> DefaultCssMinifier()
+ public Configuration UseReleaseRenderer(IRenderer releaseRenderer)
{
- return (IMinifier<CSSBundle>)Activator.CreateInstance(_defaultCssMinifier);
+ _defaultReleaseRenderer = releaseRenderer;
+ return this;
+ }
+
+ internal IRenderer DefaultReleaseRenderer()
+ {
+ return _defaultReleaseRenderer;
+ }
+
+ public Configuration UseOutputBaseHref(string url)
+ {
+ _defaultOutputBaseHref = url;
+ return this;
}
- public static IMinifier<JavaScriptBundle> DefaultJsMinifier()
+ internal string DefaultOutputBaseHref()
{
- return (IMinifier<JavaScriptBundle>)Activator.CreateInstance(_defaultJsMinifier);
+ return _defaultOutputBaseHref;
}
}
-}
+}
View
2  SquishIt.Framework/Css/CssBundle.cs
@@ -34,7 +34,7 @@ protected override string CachePrefix
protected override IMinifier<CSSBundle> DefaultMinifier
{
- get { return Configuration.DefaultCssMinifier(); }
+ get { return Configuration.Instance.DefaultCssMinifier(); }
}
protected override IEnumerable<string> allowedExtensions
View
30 SquishIt.Framework/Css/CssPathRewriter.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Text.RegularExpressions;
using SquishIt.Framework.Utilities;
@@ -64,26 +65,25 @@ private static string ReplaceRelativePathsIn (string css, string oldPath, string
});
}
- private static IEnumerable<string> FindDistinctRelativePathsIn (string css)
+ static readonly Regex pathsRegex = new Regex(@"(?<!.*behavior\s*:\s*)url\([""']?(.*?)[""']?\)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
+ private static IEnumerable<string> FindDistinctRelativePathsIn (string css)
{
- var matches = Regex.Matches (css, @"url\([""']{0,1}(.+?)[""']{0,1}\)", RegexOptions.IgnoreCase);
- var matchesHash = new HashSet<string> ();
- foreach (Match match in matches)
- {
- var path = match.Groups[1].Captures[0].Value;
- if (!path.StartsWith ("/") && !path.StartsWith ("http://") && !path.StartsWith ("https://") && !path.StartsWith ("data:") && !path.StartsWith ("squishit://"))
- {
- if (matchesHash.Add (path))
- {
- yield return path;
- }
- }
- }
+ var matches = pathsRegex.Matches(css);
+ return matches.Cast<Match>()
+ .Select(match => match.Groups[1].Captures[0].Value)
+ .Where(path => !path.StartsWith ("/")
+ && !path.StartsWith ("http://")
+ && !path.StartsWith ("https://")
+ && !path.StartsWith ("data:")
+ && !path.StartsWith ("squishit://")
+ && path != "\"\""
+ && path != "''"
+ && !string.IsNullOrEmpty(path)).Distinct();
}
private static IEnumerable<string> FindDistinctLocalRelativePathsThatExist (string css)
{
- var matches = Regex.Matches (css, @"url\([""']{0,1}(.+?)[""']{0,1}\)", RegexOptions.IgnoreCase);
+ var matches = pathsRegex.Matches(css);
var matchesHash = new HashSet<string> ();
foreach (Match match in matches)
{
View
2  SquishIt.Framework/JavaScript/JavaScriptBundle.cs
@@ -20,7 +20,7 @@ public class JavaScriptBundle : BundleBase<JavaScriptBundle>
protected override IMinifier<JavaScriptBundle> DefaultMinifier
{
- get { return Configuration.DefaultJsMinifier(); }
+ get { return Configuration.Instance.DefaultJsMinifier(); }
}
protected override IEnumerable<string> allowedExtensions
View
4 SquishIt.Framework/Properties/AssemblyInfo.cs
@@ -36,7 +36,7 @@
// 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("0.8.6.0")]
-[assembly: AssemblyFileVersion("0.8.6.0")]
+[assembly: AssemblyVersion("0.8.7.0")]
+[assembly: AssemblyFileVersion("0.8.7.0")]
[assembly: InternalsVisibleTo("SquishIt.Tests")]
[assembly: AllowPartiallyTrustedCallers]
View
4 SquishIt.Mvc/Properties/AssemblyInfo.cs
@@ -32,5 +32,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("0.8.6.0")]
-[assembly: AssemblyFileVersion("0.8.6.0")]
+[assembly: AssemblyVersion("0.8.7.0")]
+[assembly: AssemblyFileVersion("0.8.7.0")]
View
42 SquishIt.Tests/CssBundleTests.cs
@@ -1,9 +1,11 @@
using System;
using System.IO;
+using Moq;
using NUnit.Framework;
using SquishIt.Framework.Css;
using SquishIt.Framework.Minifiers.CSS;
using SquishIt.Framework.Files;
+using SquishIt.Framework.Renderers;
using SquishIt.Framework.Utilities;
using SquishIt.Tests.Helpers;
using SquishIt.Tests.Stubs;
@@ -1004,7 +1006,7 @@ public void CanBundleArbitraryContentsInRelease()
public void PathRewritingDoesNotAffectClassesNamedUrl()
{
string css =
- @"
+ @"
a.url {
color: #4D926F;
}
@@ -1019,9 +1021,45 @@ public void PathRewritingDoesNotAffectClassesNamedUrl()
.Add("~/css/something/test.css")
.Render("~/css/output_rewriting_url.css");
- string contents = cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output_rewriting_url.css")];
+ string contents =
+ cssBundleFactory.FileWriterFactory.Files[
+ TestUtilities.PrepareRelativePath(@"css\output_rewriting_url.css")];
Assert.AreEqual("a.url{color:#4d926f}", contents);
}
+
+ [Test]
+ public void CanUseArbitraryReleaseRenderer()
+ {
+ var renderer = new Mock<IRenderer>();
+
+ var content = "content";
+
+ var tag = cssBundleFactory
+ .WithDebuggingEnabled(false)
+ .Create()
+ .WithReleaseRenderer(renderer.Object)
+ .AddString(content)
+ .Render("test.css");
+
+ renderer.Verify(r => r.Render(content, TestUtilities.PrepareRelativePath("test.css")));
+ }
+
+ [Test]
+ public void CanIgnoreArbitraryReleaseRendererInDebug()
+ {
+ var renderer = new Mock<IRenderer>();
+
+ var content = "content";
+
+ var tag = cssBundleFactory
+ .WithDebuggingEnabled(true)
+ .Create()
+ .WithReleaseRenderer(renderer.Object)
+ .AddString(content)
+ .Render("test.css");
+
+ renderer.VerifyAll();
+ }
}
}
View
47 SquishIt.Tests/CssPathRewriterTests.cs
@@ -338,6 +338,30 @@ public void DontThrowIfPathContainsRegexMetacharacters()
}
[Test]
+ public void DontThrowIfPathIsEmpty()
+ {
+ ICssAssetsFileHasher cssAssetsFileHasher = null;
+ string css =
+ @"
+ .header {
+ background-image: URL("""");
+ background-image: url();
+ }
+
+ .footer {
+ background-image: uRL("""");
+ background-image: UrL('');
+ }
+ ";
+ string sourceFile = TestUtilities.PreparePath(@"C:\somepath\somesubpath\myfile.css");
+ string targetFile = TestUtilities.PreparePath(@"C:\somepath\output.css");
+
+ //concrete result doesn't matter here (since input isn't valid)
+ //the only important thing is that it shouldn't throw exceptions
+ Assert.DoesNotThrow(() => CSSPathRewriter.RewriteCssPaths(targetFile, sourceFile, css, cssAssetsFileHasher));
+ }
+
+ [Test]
public void WontRewriteAbsolutePaths()
{
ICssAssetsFileHasher cssAssetsFileHasher = null;
@@ -392,5 +416,28 @@ public void WontRewriteDataUrls()
";
Assert.AreEqual(expected, result);
}
+
+ [Test]
+ public void WontRewriteBehaviorUrls()
+ {
+ ICssAssetsFileHasher cssAssetsFileHasher = null;
+ string css =
+ @"
+ .header {
+ behavior: url('somethingorother') no-repeat 0 0;
+ }
+ ";
+ string sourceFile = TestUtilities.PreparePath(@"C:\somepath\somesubpath\myfile.css");
+ string targetFile = TestUtilities.PreparePath(@"C:\somepath\someothersubpath\evendeeper\output.css");
+ string result = CSSPathRewriter.RewriteCssPaths(targetFile, sourceFile, css, cssAssetsFileHasher);
+
+ string expected =
+ @"
+ .header {
+ behavior: url('somethingorother') no-repeat 0 0;
+ }
+ ";
+ Assert.AreEqual(expected, result);
+ }
}
}
View
33 SquishIt.Tests/JavaScriptBundleTests.cs
@@ -1,8 +1,10 @@
using System;
+using Moq;
using NUnit.Framework;
using SquishIt.Framework.Files;
using SquishIt.Framework.JavaScript;
using SquishIt.Framework.Minifiers.JavaScript;
+using SquishIt.Framework.Renderers;
using SquishIt.Framework.Tests.Mocks;
using SquishIt.Framework.Utilities;
using SquishIt.Tests.Stubs;
@@ -708,5 +710,36 @@ public void CanBundleJavaScriptWithDeferredLoad()
Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output_1.js?r=36286D0CEA57C5ED24B868EB0D2898E9\" defer></script>", tag);
Assert.AreEqual("function product(n,t){return n*t}function sum(n,t){return n+t}", fileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output_1.js")]);
}
+
+ [Test]
+ public void CanUseArbitraryReleaseRenderer()
+ {
+ var renderer = new Mock<IRenderer>();
+
+ var content = "content";
+
+ var tag = javaScriptBundle
+ .WithReleaseRenderer(renderer.Object)
+ .AddString(content)
+ .ForceRelease()
+ .Render("test.js");
+
+ renderer.Verify(r => r.Render(content, TestUtilities.PrepareRelativePath("test.js")));
+ }
+
+ [Test]
+ public void CanIgnoreArbitraryReleaseRendererInDebug()
+ {
+ var renderer = new Mock<IRenderer>();
+
+ var content = "content";
+
+ var tag = javaScriptBundle
+ .WithReleaseRenderer(renderer.Object)
+ .AddString(content)
+ .Render("test.js");
+
+ renderer.VerifyAll();
+ }
}
}
View
3  SquishIt.Tests/SquishIt.Tests.csproj
@@ -56,6 +56,9 @@
<Reference Include="IronRuby, Version=1.1.3.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\IronRuby.1.1.3\Lib\IronRuby.dll</HintPath>
</Reference>
+ <Reference Include="Moq">
+ <HintPath>..\packages\Moq.4.0.10827\lib\NET35\Moq.dll</HintPath>
+ </Reference>
<Reference Include="IronRuby.Libraries">
<HintPath>..\packages\IronRuby.1.1.3\Lib\IronRuby.Libraries.dll</HintPath>
</Reference>
View
1  SquishIt.Tests/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IronRuby" version="1.1.3" />
+ <package id="Moq" version="4.0.10827" />
</packages>
View
39 packages/Moq.4.0.10827/License.txt
@@ -0,0 +1,39 @@
+Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD
+http://code.google.com/p/moq/
+All rights reserved.
+
+Redistribution and use in source and binary forms,
+with or without modification, are permitted provided
+that the following conditions are met:
+
+ * Redistributions of source code must retain the
+ above copyright notice, this list of conditions and
+ the following disclaimer.
+
+ * Redistributions in binary form must reproduce
+ the above copyright notice, this list of conditions
+ and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the
+ names of its contributors may be used to endorse
+ or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+[This is the BSD license, see
+ http://www.opensource.org/licenses/bsd-license.php]
View
BIN  packages/Moq.4.0.10827/Moq.4.0.10827.nupkg
Binary file not shown
View
BIN  packages/Moq.4.0.10827/Moq.chm
Binary file not shown
View
BIN  packages/Moq.4.0.10827/lib/NET35/Moq.dll
Binary file not shown
View
BIN  packages/Moq.4.0.10827/lib/NET35/Moq.pdb
Binary file not shown
View
5,768 packages/Moq.4.0.10827/lib/NET35/Moq.xml
5,768 additions, 0 deletions not shown
View
BIN  packages/Moq.4.0.10827/lib/NET40/Moq.dll
Binary file not shown
View
BIN  packages/Moq.4.0.10827/lib/NET40/Moq.pdb
Binary file not shown
View
5,120 packages/Moq.4.0.10827/lib/NET40/Moq.xml
5,120 additions, 0 deletions not shown
View
BIN  packages/Moq.4.0.10827/lib/Silverlight4/Castle.Core.dll
Binary file not shown
View
BIN  packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.dll
Binary file not shown
View
BIN  packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.pdb
Binary file not shown
View
5,101 packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.xml
5,101 additions, 0 deletions not shown
View
BIN  releases/SquishIt.0.8.6.nupkg
Binary file not shown
View
BIN  releases/SquishIt.Mvc.0.8.6.nupkg
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.