Skip to content

Commit

Permalink
📝
Browse files Browse the repository at this point in the history
  • Loading branch information
hlaueriksson committed Apr 11, 2022
1 parent f51aa31 commit d0f8ece
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 87 deletions.
Binary file modified GEmojiSharp.Sample.BlazorWebAssembly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed GEmojiSharp.Sample.Web.png
Binary file not shown.
206 changes: 121 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# GEmojiSharp
# GEmojiSharp<!-- omit in toc -->

[![Build status](https://github.com/hlaueriksson/GEmojiSharp/workflows/build/badge.svg)](https://github.com/hlaueriksson/GEmojiSharp/actions?query=workflow%3Abuild)
[![CodeFactor](https://www.codefactor.io/repository/github/hlaueriksson/gemojisharp/badge)](https://www.codefactor.io/repository/github/hlaueriksson/gemojisharp)

[![GEmojiSharp](https://img.shields.io/nuget/v/GEmojiSharp.svg?label=GEmojiSharp)](https://www.nuget.org/packages/GEmojiSharp)
[![GEmojiSharp.AspNetCore](https://img.shields.io/nuget/v/GEmojiSharp.AspNetCore.svg?label=GEmojiSharp.AspNetCore)](https://www.nuget.org/packages/GEmojiSharp.AspNetCore)
[![GEmojiSharp.Blazor](https://img.shields.io/nuget/v/GEmojiSharp.Blazor.svg?label=GEmojiSharp.Blazor)](https://www.nuget.org/packages/GEmojiSharp.Blazor)
[![GEmojiSharp.TagHelpers](https://img.shields.io/nuget/v/GEmojiSharp.TagHelpers.svg?label=GEmojiSharp.TagHelpers)](https://www.nuget.org/packages/GEmojiSharp.TagHelpers)

> GitHub Emoji for C# and ASP.NET Core
> GitHub Emoji for C#, ASP.NET Core and Blazor
```
```txt
🐙 :octopus:
➕ :heavy_plus_sign:
🐈 :cat2:
❤️ :heart:
```

# Content
## Content<!-- omit in toc -->

- [GEmojiSharp](#gemojisharp)
- [Content](#content)
- [Introduction](#introduction)
- [`GEmojiSharp` 📦](#gemojisharp-)
- [`GEmojiSharp.AspNetCore` 📦](#gemojisharpaspnetcore-)
- [TagHelpers](#taghelpers)
- [HtmlHelpers](#htmlhelpers)
- [`GEmojiSharp.Blazor` 📦](#gemojisharpblazor-)
- [`GEmojiSharp.TagHelpers` 📦](#gemojisharptaghelpers-)
- [Samples](#samples)
- [Attribution](#attribution)

# Introduction
## Introduction

[Using emoji](https://help.github.com/en/articles/basic-writing-and-formatting-syntax#using-emoji) on GitHub is done with colons and emoji aliases:
[Using emoji](https://help.github.com/en/articles/basic-writing-and-formatting-syntax#using-emoji) on GitHub is accomplish with emoji aliases enclosed by colons:

`:+1: This PR looks great - it's ready to merge! :shipit:`

:+1: This PR looks great - it's ready to merge! :shipit:

`GEmojiSharp`, `GEmojiSharp.Blazor` and `GEmojiSharp.TagHelpers` are three libraries to make this possible in C#, Blazor and ASP.NET Core.
`GEmojiSharp`, `GEmojiSharp.AspNetCore` and `GEmojiSharp.Blazor` are three libraries to make this possible in C#, Blazor and ASP.NET Core.

A list of all GitHub Emojis:

* https://github.com/hlaueriksson/github-emoji
- https://github.com/hlaueriksson/github-emoji

# `GEmojiSharp` 📦
## `GEmojiSharp` 📦

[![NuGet](https://buildstats.info/nuget/GEmojiSharp)](https://www.nuget.org/packages/GEmojiSharp/)

Expand All @@ -52,73 +52,54 @@ Static methods:

```csharp
Emoji.Get(":tada:").Raw; // 🎉
Emoji.Get("🎉").Alias(); // :tada:
Emoji.Raw(":tada:"); // 🎉
Emoji.Alias("🎉"); // :tada:
Emoji.Emojify(":tada: initial commit"); // 🎉 initial commit
Emoji.Demojify("🎉 initial commit"); // :tada: initial commit
Emoji.Find("party popper").First().Raw; // 🎉
```

Extension methods:

```csharp
":tada:".GetEmoji().Raw; // 🎉
"🎉".GetEmoji().Alias(); // :tada:
":tada:".RawEmoji(); // 🎉
"🎉".EmojiAlias(); // :tada:
":tada: initial commit".Emojify(); // 🎉 initial commit
"🎉 initial commit".Demojify(); // :tada: initial commit
"party popper".FindEmojis().First().Raw; // 🎉
```

# `GEmojiSharp.Blazor` 📦

[![NuGet](https://buildstats.info/nuget/GEmojiSharp.Blazor)](https://www.nuget.org/packages/GEmojiSharp.Blazor/)

> GitHub Emoji for Blazor
Update `Pages/_Host.cshtml` (Blazor Server), or `wwwroot/index.html` (Blazor WebAssembly):
Regular expression pattern to match all emojis:

```html
<link href="_content/GEmojiSharp.Blazor/style.css" rel="stylesheet" />
```

```html
<script src="_content/GEmojiSharp.Blazor/script.js"></script>
```
```csharp
var text = "Lorem 😂😂 ipsum";

Import the `GEmojiSharp.Blazor` namespace in `razor` files:
var matches = Regex.Matches(text, Emoji.RegexPattern);
string.Join(string.Empty, matches.Select(x => x.Value)); // 😂😂
```cshtml
@using GEmojiSharp.Blazor
Regex.Replace(text, Emoji.RegexPattern, string.Empty); // Lorem ipsum
```

Use the `<Emoji>` component to render emojis:

```html
<Emoji>:tada: initial commit</Emoji>
```
## `GEmojiSharp.AspNetCore` 📦

Standard emoji characters are rendered like this:
[![NuGet](https://buildstats.info/nuget/GEmojiSharp.AspNetCore)](https://www.nuget.org/packages/GEmojiSharp.AspNetCore/)

```html
<g-emoji class="g-emoji" alias="tada" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f389.png">🎉</g-emoji>
```

Custom GitHub emojis are rendered as images:
> GitHub Emoji for ASP.NET Core
```html
<img class="emoji" title=":octocat:" alt=":octocat:" src="https://github.githubassets.com/images/icons/emoji/octocat.png" height="20" width="20" align="absmiddle">
```
The package includes:

# `GEmojiSharp.TagHelpers` 📦
- TagHelpers
- HtmlHelpers

[![NuGet](https://buildstats.info/nuget/GEmojiSharp.TagHelpers)](https://www.nuget.org/packages/GEmojiSharp.TagHelpers/)

> GitHub Emoji for ASP.NET Core
### TagHelpers

Update the `_ViewImports.cshtml` file, to enable tag helpers in all Razor views:

```cshtml
@using GEmojiSharp.Sample.Web
@namespace GEmojiSharp.Sample.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, GEmojiSharp.TagHelpers
@addTagHelper *, GEmojiSharp.AspNetCore
```

Use the `<emoji>` tag or `emoji` attribute to render emojis:
Expand All @@ -140,7 +121,7 @@ Custom GitHub emojis are rendered as images:
<img class="emoji" title=":octocat:" alt=":octocat:" src="https://github.githubassets.com/images/icons/emoji/octocat.png" height="20" width="20" align="absmiddle">
```

Use this CSS to properly position the custom GitHub emojis images:
Use CSS to properly position the custom GitHub emojis images:

```css
.emoji {
Expand All @@ -154,7 +135,7 @@ Use the JavaScript from [`g-emoji-element`](https://github.com/github/g-emoji-el

> Backports native emoji characters to browsers that don't support them by replacing the characters with fallback images.
Add a [`libman.json`](https://docs.microsoft.com/en-us/aspnet/core/client-side/libman/libman-vs?view=aspnetcore-2.2) file:
Add a [`libman.json`](https://docs.microsoft.com/en-us/aspnet/core/client-side/libman/libman-vs?view=aspnetcore-6.0) file:

```json
{
Expand All @@ -163,7 +144,7 @@ Add a [`libman.json`](https://docs.microsoft.com/en-us/aspnet/core/client-side/l
"libraries": [
{
"provider": "unpkg",
"library": "@github/g-emoji-element@1.0.0",
"library": "@github/g-emoji-element@1.1.5",
"destination": "wwwroot/lib/g-emoji-element/"
}
]
Expand All @@ -173,7 +154,7 @@ Add a [`libman.json`](https://docs.microsoft.com/en-us/aspnet/core/client-side/l
And add the script to the `_Layout.cshtml` file:

```html
<script src="~/lib/g-emoji-element/dist/index.umd.js"></script>
<script src="~/lib/g-emoji-element/dist/index.js"></script>
```

Do you want to use emoji anywhere, on any tag, in the `body`? Then you can use the `BodyTagHelperComponent`.
Expand All @@ -184,68 +165,123 @@ Use any tag to render emojis:
<h1>Hello, :earth_africa:</h1>
```

[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-2.2#registration-via-services-container) via services container:
[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-6.0#registration-via-services-container) via services container:

```cs
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Razor.TagHelpers;

services.AddTransient<ITagHelperComponent, BodyTagHelperComponent>();
}
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddTransient<ITagHelperComponent, BodyTagHelperComponent>();
```

[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-2.2#registration-via-razor-file) via Razor file:
[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-6.0#registration-via-razor-file) via Razor file:

```cshtml
@page
@using GEmojiSharp.TagHelpers
@model GEmojiSharp.Sample.Web.Pages.ComponentModel
@using Microsoft.AspNetCore.Mvc.Razor.TagHelpers
@using GEmojiSharp.AspNetCore
@inject ITagHelperComponentManager manager;
@model IndexModel
@{
ViewData["Title"] = "Home page";
ViewData["Title"] = "Component";
manager.Components.Add(new BodyTagHelperComponent());
}
```

[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-2.2#registration-via-page-model-or-controller) via Page Model or controller:
[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-6.0#registration-via-page-model-or-controller) via Page Model or controller:

```cs
public class IndexModel : PageModel
{
private readonly ITagHelperComponentManager _tagHelperComponentManager;
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Mvc.Razor.TagHelpers;
using Microsoft.AspNetCore.Mvc.RazorPages;

public IndexModel(ITagHelperComponentManager tagHelperComponentManager)
namespace GEmojiSharp.Sample.Web.Pages
{
public class ComponentModel : PageModel
{
_tagHelperComponentManager = tagHelperComponentManager;
}
private readonly ITagHelperComponentManager _tagHelperComponentManager;

public void OnGet()
{
_tagHelperComponentManager.Components.Add(new BodyTagHelperComponent());
public IndexModel(ITagHelperComponentManager tagHelperComponentManager)
{
_tagHelperComponentManager = tagHelperComponentManager;
}

public void OnGet()
{
_tagHelperComponentManager.Components.Add(new BodyTagHelperComponent());
}
}
}
```

# Samples
### HtmlHelpers

Update the `_ViewImports.cshtml` file, to enable HTML helpers in all Razor views:

```cshtml
@using GEmojiSharp.AspNetCore
```

Use the `Emoji` extension methods to render emojis:

```cshtml
@Html.Emoji(":tada: initial commit")
@Html.Emoji(x => x.Text)
```

## `GEmojiSharp.Blazor` 📦

[![NuGet](https://buildstats.info/nuget/GEmojiSharp.Blazor)](https://www.nuget.org/packages/GEmojiSharp.Blazor/)

> GitHub Emoji for Blazor
The package is a Razor class library (RCL) with a Razor component.

Update the `_Imports.razor` file, to enable the component in all Razor views:

```cshtml
@using GEmojiSharp.Blazor
```

Use the `<Emoji>` component to render emojis:

```html
<Emoji>:tada: initial commit</Emoji>
```

Standard emoji characters are rendered like this:

```html
<g-emoji class="g-emoji" alias="tada" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f389.png">🎉</g-emoji>
```

Custom GitHub emojis are rendered as images:

```html
<img class="emoji" title=":octocat:" alt=":octocat:" src="https://github.githubassets.com/images/icons/emoji/octocat.png" height="20" width="20" align="absmiddle">
```

## Samples

The [`samples`](/samples) folder contains...

* `GEmojiSharp.Sample.BlazorServer`, a Blazor Server app
* `GEmojiSharp.Sample.BlazorWebAssembly`, a Blazor WebAssembly app
* `GEmojiSharp.Sample.Web`, a ASP.NET Core web site
- `GEmojiSharp.Sample.BlazorServer`, a Blazor Server app
- `GEmojiSharp.Sample.BlazorWebAssembly`, a Blazor WebAssembly app
- `GEmojiSharp.Sample.Web`, a ASP.NET Core web site

The Blazor WebAssembly app is showcased here:

* https://hlaueriksson.github.io/GEmojiSharp/ (GitHub Pages)
* https://purple-mushroom-05c6bad10.azurestaticapps.net (Azure Static Web Apps)
- https://hlaueriksson.github.io/GEmojiSharp/ (GitHub Pages)
- https://purple-mushroom-05c6bad10.azurestaticapps.net (Azure Static Web Apps)

[![GEmojiSharp.Sample.BlazorWebAssembly](GEmojiSharp.Sample.BlazorWebAssembly.png)](https://hlaueriksson.github.io/GEmojiSharp/)

# Attribution
## Attribution

Repositories consulted when building this:

* https://github.com/github/gemoji
* https://github.com/github/g-emoji-element
- https://github.com/github/gemoji
- https://github.com/github/g-emoji-element
4 changes: 2 additions & 2 deletions samples/GEmojiSharp.Sample.Web/Pages/Component.cshtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@page
@using GEmojiSharp.AspNetCore
@model GEmojiSharp.Sample.Web.Pages.ComponentModel
@using Microsoft.AspNetCore.Mvc.Razor.TagHelpers
@using GEmojiSharp.AspNetCore
@inject ITagHelperComponentManager manager;
@model GEmojiSharp.Sample.Web.Pages.ComponentModel
@{
ViewData["Title"] = "Component";
manager.Components.Add(new BodyTagHelperComponent());
Expand Down
1 change: 1 addition & 0 deletions tests/GEmojiSharp.Tests/Documentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public void Emoji_()
WriteLine(Emoji.Get(":tada:").Raw); // 🎉
WriteLine(Emoji.Get("🎉").Alias()); // :tada:
WriteLine(Emoji.Raw(":tada:")); // 🎉
WriteLine(Emoji.Alias("🎉")); // :tada:
WriteLine(Emoji.Emojify(":tada: initial commit")); // 🎉 initial commit
WriteLine(Emoji.Demojify("🎉 initial commit")); // :tada: initial commit
WriteLine(Emoji.Find("party popper").First().Raw); // 🎉
Expand Down

0 comments on commit d0f8ece

Please sign in to comment.