Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hlaueriksson committed Apr 10, 2022
1 parent 99920c6 commit 1955858
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nuget-local.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nuget init .\src\GEmojiSharp\bin\Release\ .\packages
nuget init .\src\GEmojiSharp.AspNetCore\bin\Release\ .\packages
nuget init .\src\GEmojiSharp.Blazor\bin\Release\ .\packages
nuget init .\src\GEmojiSharp.TagHelpers\bin\Release\ .\packages
5 changes: 4 additions & 1 deletion samples/GEmojiSharp.Sample.Web/GEmojiSharp.Sample.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GEmojiSharp.TagHelpers" Version="1.5.0" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.6.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.161" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\GEmojiSharp.AspNetCore\GEmojiSharp.AspNetCore.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion samples/GEmojiSharp.Sample.Web/Pages/Component.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page
@using GEmojiSharp.TagHelpers
@using GEmojiSharp.AspNetCore
@using Microsoft.AspNetCore.Mvc.Razor.TagHelpers
@inject ITagHelperComponentManager manager;
@model GEmojiSharp.Sample.Web.Pages.ComponentModel
Expand Down
5 changes: 5 additions & 0 deletions samples/GEmojiSharp.Sample.Web/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@
<div><emoji>@Model.Text</emoji></div>
<div><span emoji="@Model.Emoji" /></div>

<hr />

<div>@Html.Emoji(":octopus: :heavy_plus_sign: :cat2: ⩵ :heart:")</div>
<div>@Html.Emoji(x => x.Text)</div>

</div>
3 changes: 2 additions & 1 deletion samples/GEmojiSharp.Sample.Web/Pages/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using GEmojiSharp.Sample.Web
@namespace GEmojiSharp.Sample.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, GEmojiSharp.TagHelpers
@addTagHelper *, GEmojiSharp.AspNetCore
@using GEmojiSharp.AspNetCore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using System.Text.RegularExpressions;

namespace GEmojiSharp.AspNetCore.TagHelpers
namespace GEmojiSharp.AspNetCore
{
/// <summary>
/// Extension methods for working with emoji markup.
Expand Down
5 changes: 3 additions & 2 deletions src/GEmojiSharp.AspNetCore/GEmojiSharp.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
❤️ :heart:
</Description>
<PackageId>GEmojiSharp.TagHelpers</PackageId>
<PackageId>GEmojiSharp.AspNetCore</PackageId>
<PackageProjectUrl>https://github.com/hlaueriksson/GEmojiSharp</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>emoji;gemoji;aspnetcore;aspnetcoremvc;taghelper;taghelpers</PackageTags>
<PackageTags>emoji;gemoji;aspnetcore;aspnetcoremvc;taghelper;taghelpers;htmlhelper;htmlhelpers</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand All @@ -30,6 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.2.0" />
</ItemGroup>

Expand Down
46 changes: 46 additions & 0 deletions src/GEmojiSharp.AspNetCore/HtmlHelpers/HtmlHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Linq.Expressions;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace GEmojiSharp.AspNetCore
{
/// <summary>
/// Emoji extensions for <see cref="IHtmlHelper"/> and <see cref="IHtmlHelper{TModel}"/>.
/// </summary>
public static class HtmlHelperExtensions
{
/// <summary>
/// Returns emojified HTML markup for the content.
/// </summary>
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <param name="content">The content.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the created HTML.</returns>
public static IHtmlContent Emoji(this IHtmlHelper htmlHelper, string content) =>
new HtmlString(content.MarkupContent());

/// <summary>
/// Returns emojified HTML markup for the <paramref name="expression"/>.
/// </summary>
/// <typeparam name="TModel">The type of the model.</typeparam>
/// <param name="htmlHelper">The <see cref="IHtmlHelper{TModel}"/> instance this method extends.</param>
/// <param name="expression">An expression to be evaluated against the current model.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the created HTML.</returns>
public static IHtmlContent Emoji<TModel>(this IHtmlHelper<TModel> htmlHelper, Expression<Func<TModel, string>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}

if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}

Func<TModel, string> func = expression.Compile();

return new HtmlString(func(htmlHelper.ViewData.Model).MarkupContent());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace GEmojiSharp.AspNetCore.TagHelpers
namespace GEmojiSharp.AspNetCore
{
/// <summary>
/// <see cref="ITagHelper"/> implementation targeting <![CDATA[<body>]]> elements.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace GEmojiSharp.AspNetCore.TagHelpers
namespace GEmojiSharp.AspNetCore
{
/// <summary>
/// <see cref="ITagHelper"/> implementation targeting elements with an <c>emoji</c> attribute.
Expand Down
2 changes: 1 addition & 1 deletion src/GEmojiSharp.AspNetCore/TagHelpers/EmojiTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace GEmojiSharp.AspNetCore.TagHelpers
namespace GEmojiSharp.AspNetCore
{
/// <summary>
/// <see cref="ITagHelper"/> implementation targeting <![CDATA[<emoji>]]> elements.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using FluentAssertions;
using GEmojiSharp.AspNetCore.TagHelpers;
using GEmojiSharp.AspNetCore;
using NUnit.Framework;

namespace GEmojiSharp.Tests.AspNetCore.TagHelpers
namespace GEmojiSharp.Tests.AspNetCore
{
public class EmojiExtensionsTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using FluentAssertions;
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Mvc.Rendering;
using NSubstitute;
using NUnit.Framework;

namespace GEmojiSharp.Tests.AspNetCore.HtmlHelpers
{
public class HtmlHelperExtensionsTests
{
[Test]
public void Emoji()
{
var subject = Substitute.For<IHtmlHelper>();

subject.Emoji("<p>Hello, :earth_africa:</p>").ToString().Should().Be(@"<p>Hello, <g-emoji class=""g-emoji"" alias=""earth_africa"" fallback-src=""https://github.githubassets.com/images/icons/emoji/unicode/1f30d.png"">🌍</g-emoji></p>");
subject.Emoji("<p>Hello, :fail:</p>").ToString().Should().Be(@"<p>Hello, :fail:</p>");

subject.Emoji("<textarea>Hello, :earth_africa:</textarea>").ToString().Should().Be(@"<textarea>Hello, 🌍</textarea>");
subject.Emoji(@"<input type=""text"" value=""Hello, :earth_africa:"">").ToString().Should().Be(@"<input type=""text"" value=""Hello, 🌍"">");

subject.Emoji("<body><form><div>:book: :pencil2:<br /><textarea>:heart: :+1:</textarea></div></form></body>").ToString().Should().Be(@"<body><form><div><g-emoji class=""g-emoji"" alias=""book"" fallback-src=""https://github.githubassets.com/images/icons/emoji/unicode/1f4d6.png"">📖</g-emoji> <g-emoji class=""g-emoji"" alias=""pencil2"" fallback-src=""https://github.githubassets.com/images/icons/emoji/unicode/270f.png"">✏️</g-emoji><br /><textarea>❤️ 👍</textarea></div></form></body>");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using FluentAssertions;
using GEmojiSharp.AspNetCore.TagHelpers;
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Razor.TagHelpers;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using FluentAssertions;
using GEmojiSharp.AspNetCore.TagHelpers;
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Razor.TagHelpers;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;
using FluentAssertions;
using GEmojiSharp.AspNetCore.TagHelpers;
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Razor.TagHelpers;
using NUnit.Framework;

Expand Down
1 change: 1 addition & 0 deletions tests/GEmojiSharp.Tests/GEmojiSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.5.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NSubstitute" Version="4.3.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 1955858

Please sign in to comment.