Permalink
Browse files

Standardize checks for preprocessor population

  • Loading branch information...
1 parent 2e30b91 commit d818ca806e32992004d8d427339eb9c44b56524a @AlexCuse AlexCuse committed Jul 10, 2012
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@@ -108,11 +109,11 @@ protected string PreprocessArbitrary(Asset asset)
protected string PreprocessContent(string file, IEnumerable<IPreprocessor> preprocessors, string content)
{
- if(preprocessors == null)
+ if(preprocessors.NullSafeAny())
{
- return content;
+ return preprocessors.Aggregate(content, (cntnt, pp) => pp.Process(file, cntnt));
}
- return preprocessors.Aggregate(content, (cntnt, pp) => pp.Process(file, cntnt));
+ return content;
}
IPreprocessor FindPreprocessor(string extension)
@@ -421,7 +422,7 @@ protected string MinifyIfNeeded(string content, bool minify)
string PreprocessForDebugging(string filename)
{
var preprocessors = FindPreprocessors(filename).ToList();
- if(preprocessors.Any())
+ if(preprocessors.NullSafeAny())
{
string content;
lock(typeof(T))
@@ -130,7 +130,7 @@ string ProcessCssFile(string file, string outputFile, bool asImport = false)
var preprocessors = FindPreprocessors(file);
- if(preprocessors != null && preprocessors.Count() > 0)
+ if(preprocessors.NullSafeAny())
{
css = PreprocessFile(file, preprocessors);
}
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@@ -46,5 +47,10 @@ internal static string MakeRelativePathTo (this Uri from, Uri to)
}
return relativePath;
}
+
+ internal static bool NullSafeAny<T>(this IEnumerable<T> values)
+ {
+ return values != null && values.Any();
+ }
}
}
@@ -68,7 +68,7 @@ protected override string CachePrefix
protected override string ProcessFile(string file, string outputFile, bool minify)
{
var preprocessors = FindPreprocessors(file);
- if(preprocessors != null && preprocessors.Count() > 0)
+ if(preprocessors.NullSafeAny())
{
return MinifyIfNeeded(PreprocessFile(file, preprocessors), minify);
}

0 comments on commit d818ca8

Please sign in to comment.