Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Initial version.
Browse files Browse the repository at this point in the history
  • Loading branch information
RealGecko committed Apr 16, 2020
0 parents commit 238a9a4
Show file tree
Hide file tree
Showing 20 changed files with 887 additions and 0 deletions.
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.svclog
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml
*.azurePubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
packages/
## TODO: If the tool you use requires repositories.config, also uncomment the next line
!packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
![Ss]tyle[Cc]op.targets
~$*
*~
*.dbmdl
*.[Pp]ublish.xml

*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

_NCrunch*
.vs/
25 changes: 25 additions & 0 deletions Gecko.EPiServer.IconSelectionEditor.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gecko.EPiServer.IconSelectionEditor.Core", "src\Gecko.EPiServer.IconSelectionEditor.Core\Gecko.EPiServer.IconSelectionEditor.Core.csproj", "{C990C3B1-B41D-41D7-8636-5E5B90802B65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C990C3B1-B41D-41D7-8636-5E5B90802B65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C990C3B1-B41D-41D7-8636-5E5B90802B65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C990C3B1-B41D-41D7-8636-5E5B90802B65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C990C3B1-B41D-41D7-8636-5E5B90802B65}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08FA6DFC-7A98-4B5D-BD51-D1543F6A8BC4}
EndGlobalSection
EndGlobal
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[![Platform](https://img.shields.io/badge/Episerver-11.1.0-orange.svg?style=flat)](https://nuget.episerver.com/package/?id=EPiServer.CMS.UI.Core&v=11.1.0)

# Icon Selection Editor for EPiServer.

Module which extends EPiServer edit mode by adding possibility to select icons (i.e. [Font Awesome](https://fontawesome.com/), [Materialize](https://materializecss.com/), [CSS.gg](https://css.gg/) etc.) using dropdown.

![](docs/fa.gif)

## How to create and use IconSelectionEditor.

1. Create model class which will represent icon:
```csharp
public class CustomIconSelectItem : IconSelectItem
{
public override string ToHtmlString()
{
(...)
}
}
```

2. Create IconSelectionFactory which will return all available icons:
```csharp
public class CustomIconSelectionFactory : IconSelectionFactory
{
public override IEnumerable<IconSelectItem> GetIcons(ExtendedMetadata metadata)
{
(...)
}
}
```

3. Create property attribute:
```csharp
public class SelectCustomIconAttribute : SelectIconAttribute
{
public SelectCustomIconAttribute()
{
this.SelectionFactoryType = typeof(CustomIconSelectionFactory);
this.SelectionGridWidth = "580px";
}
}
```

4. Decorate EPiServer content model property using created custom attribute:
```csharp
[ContentType(DisplayName = "Custom Content Block", GUID = "d1216b39-21ce-4873-a8c1-c3d5db2b9285")]
public class CustomContentBlock : BlockData
{
[SelectCustomIcon]
public virtual string Icon { get; set; }
}
```
108 changes: 108 additions & 0 deletions build/nuget.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">
<UsingTask TaskName="ZipDirectory" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputPath ParameterType="System.String" Required="true" />
<OutputFileName ParameterType="System.String" Required="true" />
<OverwriteExistingFile ParameterType="System.Boolean" Required="false" />
</ParameterGroup>
<Task>
<Reference Include=" System.IO.Compression.FileSystem" />
<Using Namespace="System.IO" />
<Using Namespace="System.IO.Compression" />
<Code Type="Fragment" Language="cs">
<![CDATA[
if(this.OverwriteExistingFile) {
File.Delete(this.OutputFileName);
}
ZipFile.CreateFromDirectory(this.InputPath, this.OutputFileName);
]]>
</Code>
</Task>
</UsingTask>

<UsingTask TaskName="GetVersion"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">

<ParameterGroup>
<AssemblyPath ParameterType="System.String" Required="true" />
<Version ParameterType="System.String" Output="true" />
</ParameterGroup>

<Task>
<Using Namespace="System" />
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Getting version details of assembly at: " + this.AssemblyPath, MessageImportance.High);
this.Version = FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion;
]]>
</Code>
</Task>
</UsingTask>

<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == ''">$(MSBuildProjectDirectory)\..\</SolutionDir>
<NuGetExe>$(SolutionDir)\packages\NuGet.CommandLine.5.4.0\tools\NuGet.exe</NuGetExe>
<TmpOutDir>$(ProjectDir)\tmp</TmpOutDir>
<NuspecFile>$(ProjectDir)\$(ProjectName).nuspec</NuspecFile>
</PropertyGroup>

<Target Name="CreateNugetPackage" AfterTargets="Build">
<PropertyGroup>
<Version></Version>
</PropertyGroup>

<GetVersion AssemblyPath="$(ProjectDir)\bin\$(Configuration)\$(ProjectName).dll">
<Output TaskParameter="Version" PropertyName="Version" />
</GetVersion>

<ItemGroup>
<ClientResources Include="$(ProjectDir)\ClientResources\**\*" />
</ItemGroup>

<!-- Create the Versioned out dir for the client resources-->
<MakeDir Directories="$(TmpOutDir)\content\$(Version)" />

<Copy SourceFiles="$(ProjectDir)\module.config"
DestinationFolder="$(TmpOutDir)\content"
Condition="Exists('$(ProjectDir)\module.config')"/>

<Copy SourceFiles="@(ClientResources)"
DestinationFiles="@(ClientResources -> '$(TmpOutDir)\content\$(Version)\ClientResources\%(RecursiveDir)%(Filename)%(Extension)')"/>

<!-- Update the module config with the version information -->
<XmlPoke XmlInputPath="$(TmpOutDir)\content\module.config"
Query="/module/@clientResourceRelativePath"
Value="$(Version)"
Condition="Exists('$(TmpOutDir)\content\module.config')"/>

<!-- Create the Zip file -->
<ZipDirectory
InputPath="$(TmpOutDir)\content"
OutputFileName="$(OutDir)\$(ProjectName).zip"
OverwriteExistingFile="true" />

<!-- Create the package -->
<PropertyGroup>
<NugetCommand>
"$(NuGetExe)" pack "$(NuspecFile)" -OutputDirectory "$(OutDir.TrimEnd('\\'))" -Version "$(Version)" -Properties Configuration=$(Configuration)
</NugetCommand>

</PropertyGroup>
<Exec Command="$(NugetCommand)"/>

<!-- Cleanup -->
<RemoveDir Directories="$(TmpOutDir)" />

<!-- Copy to local nuget - change DestinationFolder below -->
<ItemGroup>
<_CopyItems Include="$(OutDir)\*.nupkg" />
</ItemGroup>
<Copy SourceFiles="@(_CopyItems)" DestinationFolder="C:\LocalNuget" />

</Target>

</Project>
Binary file added docs/fa.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using EPiServer.Shell.ObjectEditing;
using System.Collections.Generic;

namespace Gecko.EPiServer.IconSelectionEditor.Core.Business
{
public interface IIconSelectionFactory : ISelectionFactory
{
IEnumerable<IconSelectItem> GetIcons(ExtendedMetadata metadata);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using EPiServer.Shell.ObjectEditing;

namespace Gecko.EPiServer.IconSelectionEditor.Core.Business
{
public abstract class IconSelectionFactory : IIconSelectionFactory
{
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
return GetIcons(metadata).Select(x => new SelectItem { Text = x.Name, Value = x });
}

public abstract IEnumerable<IconSelectItem> GetIcons(ExtendedMetadata metadata);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using EPiServer.Shell.ObjectEditing;
using System;
using System.Web.Mvc;

namespace Gecko.EPiServer.IconSelectionEditor.Core.Business
{
public class SelectIconAttribute : Attribute, IMetadataAware
{
public void OnMetadataCreated(ModelMetadata metadata)
{
if (!(metadata is ExtendedMetadata extendedMetadata))
{
return;
}

extendedMetadata.ClientEditingClass = "gecko/IconSelectionEditor";
extendedMetadata.EditorConfiguration.Add("SelectionGridWidth", SelectionGridWidth);
extendedMetadata.SelectionFactoryType = SelectionFactoryType;
}

public virtual Type SelectionFactoryType { get; set; }

public virtual string SelectionGridWidth { get; set; }
}
}
Loading

0 comments on commit 238a9a4

Please sign in to comment.