GitXplorerGitXplorer
g

gemoji

public
4428 stars
787 forks
19 issues

Commits

List of commits on branch master.
Verified
0eca75db9301421efc8710baf7a7576793ae452a

Merge pull request #273 from github/dependabot-c67993ba-56b8-4f4e-a911-22640b185a14

zzkoppert committed 10 months ago
Unverified
4e8e6b07eb38288988e09869f308814708d6c8fd

Create dependabot.yaml

zzkoppert committed a year ago
Verified
5476a66d2794e0d1551b1f96e449afc72e9f7bec

gemoji 4.1.0

mmislav committed 2 years ago
Verified
ee6e06c648e85d601756b573d356327d4e51031d

Merge pull request #262 from github/skin-tones-couple

mmislav committed 2 years ago
Verified
da33f740a3b434286d8e5e723289db8c73c9ff0c

Support skin tones for :people_holding_hands: emoji

mmislav committed 2 years ago
Verified
07b49d7de79e0541e7b8187d1564ddc9591855fc

Merge pull request #261 from github/unicode-15

mmislav committed 2 years ago

README

The README file for this repository.

gemoji

This library contains character information about native emojis.

Installation

Add gemoji to your Gemfile.

gem 'gemoji'

Example Rails Helper

This would allow emojifying content such as: it's raining :cat:s and :dog:s!

See the Emoji cheat sheet for more examples.

module EmojiHelper
  def emojify(content)
    h(content).to_str.gsub(/:([\w+-]+):/) do |match|
      if emoji = Emoji.find_by_alias($1)
        %(<img alt="#$1" src="https://raw.githubusercontent.com/github/gemoji/master/#{image_path("emoji/#{emoji.image_filename}")}" style="vertical-align:middle" width="20" height="20" />)
      else
        match
      end
    end.html_safe if content.present?
  end
end

Unicode mapping

Translate emoji names to unicode and vice versa.

>> Emoji.find_by_alias("cat").raw
=> "🐱"  # Don't see a cat? That's U+1F431.

>> Emoji.find_by_unicode("\u{1f431}").name
=> "cat"

Adding new emoji

You can add new emoji characters to the Emoji.all list:

emoji = Emoji.create("music") do |char|
  char.add_alias "song"
  char.add_unicode_alias "\u{266b}"
  char.add_tag "notes"
end

emoji.name #=> "music"
emoji.raw  #=> "♫"
emoji.image_filename #=> "unicode/266b.png"

# Creating custom emoji (no Unicode aliases):
emoji = Emoji.create("music") do |char|
  char.add_tag "notes"
end

emoji.custom? #=> true
emoji.image_filename #=> "music.png"

As you create new emoji, you must ensure that you also create and put the images they reference by their image_filename to your assets directory.

You can customize image_filename with:

emoji = Emoji.create("music") do |char|
  char.image_filename = "subdirectory/my_emoji.gif"
end

For existing emojis, you can edit the list of aliases or add new tags in an edit block:

emoji = Emoji.find_by_alias "musical_note"

Emoji.edit_emoji(emoji) do |char|
  char.add_alias "music"
  char.add_unicode_alias "\u{266b}"
  char.add_tag "notes"
end

Emoji.find_by_alias "music"       #=> emoji
Emoji.find_by_unicode "\u{266b}"  #=> emoji