Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/github/gemoji
Emoji images and names.
https://github.com/github/gemoji
emoji ruby rubygem unicode
Last synced: about 7 hours ago
JSON representation
Emoji images and names.
- Host: GitHub
- URL: https://github.com/github/gemoji
- Owner: github
- License: mit
- Created: 2011-12-14T17:04:35.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2024-07-22T14:47:03.000Z (5 months ago)
- Last Synced: 2024-12-09T19:27:59.705Z (3 days ago)
- Topics: emoji, ruby, rubygem, unicode
- Language: Ruby
- Homepage:
- Size: 24.7 MB
- Stars: 4,419
- Watchers: 453
- Forks: 784
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fonts - gemoji - Emoji images and names (Emojis)
- awesome-github-star - gemoji
- awesome-starred - github/gemoji - Emoji images and names. (ruby)
- awesome-list - gemoji
README
gemoji
======This library contains character information about native emojis.
Installation
------------Add `gemoji` to your Gemfile.
``` ruby
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](http://www.emoji-cheat-sheet.com) for more examples.
```ruby
module EmojiHelper
def emojify(content)
h(content).to_str.gsub(/:([\w+-]+):/) do |match|
if emoji = Emoji.find_by_alias($1)
%()
else
match
end
end.html_safe if content.present?
end
end
```Unicode mapping
---------------Translate emoji names to unicode and vice versa.
```ruby
>> 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:
```ruby
emoji = Emoji.create("music") do |char|
char.add_alias "song"
char.add_unicode_alias "\u{266b}"
char.add_tag "notes"
endemoji.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"
endemoji.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:
```ruby
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:
```ruby
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"
endEmoji.find_by_alias "music" #=> emoji
Emoji.find_by_unicode "\u{266b}" #=> emoji
```