Skip to content

Commit

Permalink
Updated to include files in the root
Browse files Browse the repository at this point in the history
Updated README file
  • Loading branch information
Dean committed Oct 21, 2014
1 parent 1b92c5e commit c07ee80
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
4 changes: 3 additions & 1 deletion HtmlMinifier.Tests/HtmlMinifier.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
<Name>HtmlMinifier</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Data\Subdirectory\" />
</ItemGroup>
<ItemGroup>
<Content Include="Data\CommentsResult.txt" />
<Content Include="Data\Comments.txt" />
Expand Down
30 changes: 29 additions & 1 deletion HtmlMinifier.Tests/MinificationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace HtmlMinifier.Tests
using System.Collections.Generic;
using System.Linq;

namespace HtmlMinifier.Tests
{
using System;
using System.IO;
Expand Down Expand Up @@ -55,6 +58,31 @@ public void MinifyContents_WithModelList_ShouldReturnCorrectly()
Assert.That(minifiedHtml, Is.EqualTo(expectedResult));
}

[Test]
public void GetDirectories_WithFolderPath_ReturnsRootAndSubdirectories()
{
// Arrange

// Act
IEnumerable<string> rootAndSubdirectories = Program.GetDirectories(_testDataFolder);

// Assert
Assert.That(rootAndSubdirectories.Count(), Is.EqualTo(2));
}

[Test]
public void GetDirectories_WithFolderPath_ReturnsRoot()
{
// Arrange
string rootFolderPath = Path.Combine(_testDataFolder, @"Subdirectory");

// Act
IEnumerable<string> rootAndSubdirectories = Program.GetDirectories(rootFolderPath);

// Assert
Assert.That(rootAndSubdirectories.Count(), Is.EqualTo(1));
}

#region Helpers

public string ReadFileContents(string filePath)
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ HTML Minifier
A simple command line tool to minify your HTML, Razor views & Web Forms views. By minifying your HTML on bigger web pages,
you will save on bytes that your users need to donwload. Less bytes equal faster web pages & faster web pages equal happy users!

## Getting Started

Go from HTML that looks like this:

<h2>
Expand All @@ -18,7 +20,19 @@ To HTML that looks like this:

<h2> Admin Menu</h2><ul><li>@Html.ActionLink("Edit blog entries", "List", "Admin")</li><li>@Html.ActionLink("View Comments", "CommentList", "Admin")</li><li>@Html.ActionLink("Clear Cache", "ClearCache", "Admin")</li></ul>

## Usage Examples

In order to use from the command line, you simply pass through a folder path that contains all your images. The minifier will process all images in the root and subfolders.

C:\>HtmlMinifier.exe "C:\ImagesFolder"

If you'd like to find out how to use this with MSBUILD and your next publish, please follow this [link.](http://deanhume.com/Home/BlogPost/a-simple-html-minifier-for-asp-net/2097)

## Maintainers

* [@deanohume](http://github.com/deanhume)

For more information, check out the blog post [on my site.](http://deanhume.com/Home/BlogPost/a-simple-html-minifier-for-asp-net/2097)
## License

(C) Dean Hume 2014, released under the MIT license

13 changes: 6 additions & 7 deletions ViewMinifier/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void Main(string[] args)
{
string folderPath = GetFolderpath(args);

IEnumerable<string> allDirectories = GetSubdirectoriesContainingOnlyFiles(folderPath);
IEnumerable<string> allDirectories = GetDirectories(folderPath);

// Loop through the files in the folder and look for *.cshtml & *.aspx
foreach (string folder in allDirectories)
Expand All @@ -40,17 +40,16 @@ static void Main(string[] args)
Console.WriteLine("Minification Complete");
}

static IEnumerable<string> GetSubdirectoriesContainingOnlyFiles(string path)
public static IEnumerable<string> GetDirectories(string path)
{
// Get all subdirectories
IEnumerable<string> directories = from subdirectory in Directory.GetDirectories(path, "*", SearchOption.AllDirectories) select subdirectory;

// If there are no subdirectories, use the root folder
// Add the subdirectories
IList<string> allDirectories = directories as IList<string> ?? directories.ToList();
if (!allDirectories.Any())
{
allDirectories.Add(path);
}

// Add the root folder
allDirectories.Add(path);

return allDirectories;
}
Expand Down

0 comments on commit c07ee80

Please sign in to comment.