gemoji

Emoji images and names.

Github星跟蹤圖

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="#{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

主要指標

概覽
名稱與所有者github/gemoji
主編程語言Ruby
編程語言Ruby (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2011-12-14 17:04:35
推送於2024-07-22 14:47:03
最后一次提交2024-04-02 10:52:47
發布數31
最新版本名稱v4.1.0 (發布於 )
第一版名稱v0.3.0 (發布於 )
用户参与
星數4.4k
關注者數485
派生數786
提交數453
已啟用問題?
問題數81
打開的問題數6
拉請求數70
打開的拉請求數9
關閉的拉請求數71
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?