-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99920c6
commit 1955858
Showing
17 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/GEmojiSharp.AspNetCore/HtmlHelpers/HtmlHelperExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/GEmojiSharp.AspNetCore/TagHelpers/EmojiAttributeTagHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...etCore/TagHelpers/EmojiExtensionsTests.cs → ....Tests/AspNetCore/EmojiExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/GEmojiSharp.Tests/AspNetCore/HtmlHelpers/EmojiExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/GEmojiSharp.Tests/AspNetCore/TagHelpers/BodyTagHelperComponentTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/GEmojiSharp.Tests/AspNetCore/TagHelpers/EmojiAttributeTagHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/GEmojiSharp.Tests/AspNetCore/TagHelpers/EmojiTagHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters