Skip to content

Commit

Permalink
move BeforeMinify to BundleBase
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCuse committed May 26, 2012
1 parent 681e7e2 commit 6860e91
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
19 changes: 12 additions & 7 deletions SquishIt.Framework/Base/BundleBase.cs
Expand Up @@ -148,6 +148,8 @@ protected IEnumerable<IPreprocessor> FindPreprocessors(string file)
.Where(p => p != null);
}

protected abstract string ProcessFile(string file, string outputFile);

protected string PreprocessFile(string file, IEnumerable<IPreprocessor> preprocessors)
{
try
Expand Down Expand Up @@ -685,15 +687,18 @@ public T WithPreprocessor(IPreprocessor instance)
return (T)this;
}

protected virtual string BeforeMinify(string outputFile, List<string> files, IEnumerable<ArbitraryContent> arbitraryContent)
protected string BeforeMinify(string outputFile, List<string> files, IEnumerable<ArbitraryContent> arbitraryContent)
{
var sb = new StringBuilder();
//TODO: deal w/ arbitrary extensions
var allContent = files.Select(ReadFile).Union(arbitraryContent.Select(ac => ac.Content));
foreach(var content in allContent)
{
sb.Append(ReadFile(content) + "\n");
}

files.Select(f => ProcessFile(f, outputFile))
.Concat(arbitraryContent.Select(ac =>
{
var filename = "dummy." + ac.Extension;
var preprocessors = FindPreprocessors(filename);
return PreprocessContent(filename, preprocessors, ac.Content);
}))
.Aggregate(sb, (builder, val) => builder.Append(val + "\n"));

return sb.ToString();
}
Expand Down
15 changes: 2 additions & 13 deletions SquishIt.Framework/Css/CssBundle.cs
Expand Up @@ -105,20 +105,9 @@ public CSSBundle AppendHashForAssets()
return this;
}

protected override string BeforeMinify(string outputFile, List<string> filePaths, IEnumerable<ArbitraryContent> arbitraryContent)
protected override string ProcessFile(string file, string outputFile)
{
//TODO: refactor so that this is common code and ProcessCSSFile/ProcessJavascriptFile are a single abstract method called here
var outputCss = new StringBuilder();

filePaths.Select(file => ProcessCssFile(file, outputFile))
.Concat(arbitraryContent.Select(ac => {
var filename = "dummy." + ac.Extension;
var preprocessors = FindPreprocessors(filename);
return PreprocessContent(filename, preprocessors, ac.Content);
}))
.Aggregate(outputCss, (builder, val) => builder.Append(val + "\n"));

return outputCss.ToString();
return ProcessCssFile(file, outputFile);
}

string ProcessCssFile(string file, string outputFile, bool asImport = false)
Expand Down
18 changes: 1 addition & 17 deletions SquishIt.Framework/JavaScript/JavaScriptBundle.cs
Expand Up @@ -65,23 +65,7 @@ protected override string Template
get { return CACHE_PREFIX; }
}

protected override string BeforeMinify(string outputFile, List<string> files, IEnumerable<ArbitraryContent> arbitraryContent)
{
//TODO: refactor so that this is common code and ProcessCSSFile/ProcessJavascriptFile are a single abstract method called here
var sb = new StringBuilder();

files.Select(ProcessJavaScriptFile)
.Concat(arbitraryContent.Select(ac => {
var filename = "dummy." + ac.Extension;
var preprocessors = FindPreprocessors(filename);
return PreprocessContent(filename, preprocessors, ac.Content);
}))
.Aggregate(sb, (builder, val) => builder.Append(val + "\n"));

return sb.ToString();
}

string ProcessJavaScriptFile(string file)
protected override string ProcessFile(string file, string outputFile)
{
var preprocessors = FindPreprocessors(file);
if (preprocessors != null)
Expand Down

0 comments on commit 6860e91

Please sign in to comment.