X Tutup
The Wayback Machine - https://web.archive.org/web/20190326041548/https://github.com/github/gemoji
Skip to content
Emoji images and names.
Branch: master
Clone or download
Latest commit b04991b Feb 16, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Replace `rake emoji` task with a new `gemoji` executable Sep 29, 2016
db Add "sassy" alias to information desk people May 21, 2017
images `images/emoji/*.png` → `images/*.png` Sep 29, 2016
lib Allow specifying image size to extract Dec 21, 2016
script Tweak `script/bootstrap` Feb 5, 2016
test Update integrity test Dec 20, 2016
.gitignore Improve dump script for new emoji Dec 20, 2016
.travis.yml
CONTRIBUTING.md CONTRIBUTING: note license. Feb 16, 2018
Gemfile Remove Gemfile.lock from version control Dec 20, 2016
LICENSE
README.md
Rakefile
gemoji.gemspec

README.md

gemoji

This library contains character information about native emoji, as well as image files for a few custom emoji.

Installation

Add gemoji to your Gemfile.

gem 'gemoji'

Extract images

To obtain image files as fallbacks for browsers and OS's that don't support emoji, run the gemoji extract command on macOS Sierra or later:

bundle exec gemoji extract public/images/emoji

This will extract images into filenames such as:

  • public/images/emoji/octocat.png
  • public/images/emoji/unicode/1f9c0.png (the :cheese: emoji)

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="#{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
You can’t perform that action at this time.
X Tutup