Skip to content

Commit

Permalink
Merge pull request #10 from johanbenschop/feature/tree-icons
Browse files Browse the repository at this point in the history
Add tree icons and icon rotation features with miscellaneous changes
  • Loading branch information
degborta committed Sep 3, 2019
2 parents b2a4457 + 96bdd2d commit a229e79
Show file tree
Hide file tree
Showing 73 changed files with 12,658 additions and 203 deletions.
4 changes: 2 additions & 2 deletions Geta.Epi.FontThumbnail.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28016.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.29021.104
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Geta.Epi.FontThumbnail", "src\Geta.Epi.FontThumbnail\Geta.Epi.FontThumbnail.csproj", "{4A904CA7-12CE-451B-BFE4-F135EA9FA04B}"
EndProject
Expand Down
29 changes: 15 additions & 14 deletions src/Geta.Epi.FontThumbnail.EnumGenerator/Program.cs
@@ -1,9 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security;
using System.Threading.Tasks;
using Geta.Epi.FontThumbnail.EnumGenerator.Models;
using Newtonsoft.Json;
Expand Down Expand Up @@ -100,51 +101,51 @@ private static void WriteEnumToFile(string path, string enumName, IEnumerable<Me

writer.WriteLine("namespace Geta.Epi.FontThumbnail\n{");

writer.WriteLine("\t/// <summary>");
writer.WriteLine($"\t/// Font Awesome. Version {latestVersionChange}.");
writer.WriteLine("\t/// </summary>");
writer.WriteLine(" /// <summary>");
writer.WriteLine($" /// Font Awesome. Version {latestVersionChange}.");
writer.WriteLine(" /// </summary>");

writer.WriteLine($"\tpublic enum {enumName}");
writer.WriteLine("\t{");
writer.WriteLine($" public enum {enumName}");
writer.WriteLine(" {");

foreach (var icon in icons)
{
writer.WriteLine("\t\t/// <summary>");
writer.WriteLine($"\t\t/// {icon.Label.ToTitleCase()} ({icon.Name})");
writer.WriteLine(" /// <summary>");
writer.WriteLine($" /// {SecurityElement.Escape(icon.Label.ToTitleCase())} ({SecurityElement.Escape(icon.Name)})");
WriteStyles(writer, icon);
WriteSearchTerms(writer, icon);
WriteChanges(writer, icon);
writer.WriteLine("\t\t/// </summary>");
writer.WriteLine(" /// </summary>");

var name = GetEnumSafeName(icon);
writer.WriteLine($"\t\t{name} = 0x{icon.Unicode},\n");
writer.WriteLine($" {name} = 0x{icon.Unicode},\n");
}

writer.WriteLine("\t}\n}");
writer.WriteLine(" }\n}");
}
}

private static void WriteStyles(StreamWriter writer, MetadataIcon icon)
{
if (icon.Styles?.Count > 1)
{
writer.WriteLine($"\t\t/// <para>Styles: {string.Join(", ", icon.Styles)}</para>");
writer.WriteLine($" /// <para>Styles: {SecurityElement.Escape(string.Join(", ", icon.Styles))}</para>");
}
}

private static void WriteSearchTerms(StreamWriter writer, MetadataIcon icon)
{
if (icon.Search?.Terms?.Count > 0)
{
writer.WriteLine($"\t\t/// <para>Terms: {string.Join(", ", icon.Search.Terms)}</para>");
writer.WriteLine($" /// <para>Terms: {SecurityElement.Escape(string.Join(", ", icon.Search.Terms))}</para>");
}
}

private static void WriteChanges(StreamWriter writer, MetadataIcon icon)
{
var changes = icon.Changes.Select(x => x.FormatSemver()).OrderBy(x => x);

writer.Write($"\t\t/// <para>Added in {changes.First()}");
writer.Write($" /// <para>Added in {changes.First()}");
if (changes.Count() > 1)
{
var otherChanges = changes.Skip(1);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
126 changes: 126 additions & 0 deletions src/Geta.Epi.FontThumbnail.Tests/AssemblyResourceProviderTests.cs
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.IO;
using EPiServer.ServiceLocation;
using EPiServer.Web;
using EPiServer.Web.Internal;
using Geta.Epi.FontThumbnail.ResourceProvider;
using Moq;
using Xunit;

namespace Geta.Epi.FontThumbnail.Tests
{
public class AssemblyResourceProviderFixture
{
public AssemblyResourceProviderFixture()
{
var virtualPathResolver = new DefaultVirtualPathResolver(WebHostingEnvironment.Instance);
var mockServiceLocator = new Mock<IServiceLocator>();
mockServiceLocator.Setup(i => i.GetInstance<IVirtualPathResolver>()).Returns(virtualPathResolver);

ServiceLocator.SetLocator(mockServiceLocator.Object);

EPiServer.Shell.Configuration.EPiServerShellSection.GetSection().ProtectedModules.RootPath = "~/EPiServer/";
}
}

public class AssemblyResourceProviderTests : IClassFixture<AssemblyResourceProviderFixture>
{
[Fact]
public void GetCacheKey_ShouldReturnNull()
{
// Arrange
var provider = new AssemblyResourceProvider();
const string virtualPath = "~/EPiServer/Geta.Epi.FontThumbnail/ClientResources/css/all.min.css";

// Act
var result = provider.GetCacheKey(virtualPath);

// Assert
Assert.Null(result);
}

[Fact]
public void GetCacheDependency_ShouldNeverExpire()
{
// Arrange
var provider = new AssemblyResourceProvider();
const string virtualPath = "~/EPiServer/Geta.Epi.FontThumbnail/ClientResources/fa5/css/all.min.css";

// Act
var result = provider.GetCacheDependency(virtualPath, new string[0], DateTime.Now);

// Assert
Assert.IsType<NeverExpiresCacheCacheDependency>(result);
Assert.False(result.HasChanged);
Assert.Equal(new DateTime(), result.UtcLastModified);
}

[Fact]
public void GetFileHash_ShouldWork()
{
// Arrange
var provider = new AssemblyResourceProvider();

// Act
var result = provider.GetFileHash("~/EPiServer/Geta.Epi.FontThumbnail/ClientResources/fa5/css/all.min.css", new string[0]);

// Assert
Assert.NotNull(result);
Assert.Equal("b03f3a2c".Length, result.Length);
}

[Theory]
[MemberData(nameof(GetFilesInClientResourcesFolder))]
public void FilesInClientResourcesFolder_ShouldExist(string path)
{
// Arrange
var provider = new AssemblyResourceProvider();

// Act
var result = provider.FileExists("~/EPiServer/Geta.Epi.FontThumbnail/ClientResources" + path);

// Assert
Assert.True(result);
}

[Theory]
[MemberData(nameof(GetFilesInClientResourcesFolder))]
public void FilesInClientResourcesFolder_ShouldLoad(string path)
{
// Arrange
var provider = new AssemblyResourceProvider();

// Act
var result = provider.GetFile("~/EPiServer/Geta.Epi.FontThumbnail/ClientResources" + path);

// Assert
Assert.NotNull(result);
}

[Theory]
[InlineData("~/this-file-should-not-exist.ttf")]
[InlineData("~/EPiServer/Geta.Epi.FontThumbnail/ClientResources/nor-this-file.woff2")]
[InlineData("~/EPiServer/Geta.Epi.FontThumbnail/ClientResources/webfonts/and-not-this-file-too.woff2")]
public void FilesNotInClientResourcesFolder_ShouldNotExist(string path)
{
// Arrange
var provider = new AssemblyResourceProvider();

// Act
var result = provider.FileExists(path);

// Assert
Assert.False(result);
}

public static IEnumerable<object[]> GetFilesInClientResourcesFolder()
{
const string basePath = "../../../../Geta.Epi.FontThumbnail/ClientResources";
var allFiles = Directory.GetFiles(basePath, "*.*", SearchOption.AllDirectories);

foreach (var file in allFiles)
yield return new[] {file.Substring(basePath.Length).Replace("\\", "/")};
}
}
}
Expand Up @@ -2,11 +2,13 @@

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EPiServer.CMS.UI.Core" Version="11.1.0" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
<PackageReference Include="Moq" Version="4.11.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
Expand Down
@@ -0,0 +1,9 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Image)]
public class ImageDataWithOnlyThumbnailIcon : ImageData
{
}
}
@@ -0,0 +1,9 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Images)]
public class MediaDataWithOnlyThumbnailIcon : MediaData
{
}
}
@@ -0,0 +1,9 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Road)]
public class PageWithOnlyThumbnailIcon : PageData
{
}
}
@@ -0,0 +1,9 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[TreeIcon(FontAwesome5Solid.Road)]
public class PageWithOnlyTreeIcon : PageData
{
}
}
@@ -0,0 +1,9 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[TreeIcon]
public class PageWithOnlyTreeIconWithoutIcon : PageData
{
}
}
@@ -0,0 +1,10 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Clock)]
[TreeIcon(FontAwesome5Regular.Clock)]
public class PageWithThumbnailIconAndDifferentTreeIcon : PageData
{
}
}
@@ -0,0 +1,10 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Wind, Rotations.Rotate180)]
[TreeIcon(FontAwesome5Regular.Flag, Rotations.Rotate90)]
public class PageWithThumbnailIconAndDifferentTreeIconRotation : PageData
{
}
}
@@ -0,0 +1,7 @@
namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.BoxOpen)]
public class PageWithThumbnailIconAndInheritedTreeIcon : PageWithThumbnailIconAndDifferentTreeIcon
{
}
}
@@ -0,0 +1,9 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Cookie, Rotations.Rotate180)]
public class PageWithThumbnailIconAndRotation : PageData
{
}
}
@@ -0,0 +1,10 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Anchor)]
[TreeIcon]
public class PageWithThumbnailIconAndTreeIcon : PageData
{
}
}
@@ -0,0 +1,10 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[ThumbnailIcon(FontAwesome5Solid.Anchor)]
[TreeIcon(Ignore = true)]
public class PageWithThumbnailIconAndTreeIconOnIgnore : PageData
{
}
}
@@ -0,0 +1,9 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
[TreeIcon(FontAwesome5Solid.Water, Rotations.Rotate90)]
public class PageWithTreeIconAmdRotation : PageData
{
}
}
@@ -0,0 +1,8 @@
using EPiServer.Core;

namespace Geta.Epi.FontThumbnail.Tests.Models
{
public class PageWithoutThumbnailIcon : PageData
{
}
}
Expand Up @@ -9,21 +9,21 @@ namespace Geta.Epi.FontThumbnail.Tests
{
public class ThumbnailIconControllerFixture : IDisposable
{
public readonly ThumbnailIconController controller;
public readonly ThumbnailSettings settings;
internal readonly ThumbnailIconController Controller;
internal readonly ThumbnailSettings Settings;
private readonly string _temporaryDirectory;

public ThumbnailIconControllerFixture()
{
var partialDirectpry = $"[appDataPath]\\thumb_cache\\{Guid.NewGuid()}\\";
ConfigurationManager.AppSettings["FontThumbnail.CachePath"] = partialDirectpry;
_temporaryDirectory = VirtualPathUtilityEx.RebasePhysicalPath(partialDirectpry);
var partialDirectory = $"[appDataPath]\\thumb_cache\\{Guid.NewGuid()}\\";
ConfigurationManager.AppSettings["FontThumbnail.CachePath"] = partialDirectory;
_temporaryDirectory = VirtualPathUtilityEx.RebasePhysicalPath(partialDirectory);

Directory.CreateDirectory(_temporaryDirectory);

var service = new FontThumbnailService();
controller = new ThumbnailIconController(service);
settings = new ThumbnailSettings
Controller = new ThumbnailIconController(service);
Settings = new ThumbnailSettings
{
FontSize = Constants.DefaultFontSize,
BackgroundColor = Constants.DefaultBackgroundColor,
Expand Down

0 comments on commit a229e79

Please sign in to comment.