Git Product home page Git Product logo

gemoji's Introduction

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

gemoji's People

Contributors

aroben avatar ashmaroli avatar asianmack avatar bkeepers avatar cobyism avatar danthompson avatar javan avatar jeffmcneill avatar jeremy avatar jobveldhuis avatar josh avatar julia7662 avatar koddsson avatar lautis avatar mikeastock avatar mikemcquaid avatar mislav avatar nicolasleger avatar perlun avatar phoet avatar purplebooth avatar rick avatar robrix avatar rsenk330 avatar shayfrendt avatar skalnik avatar skunkmb avatar spraints avatar trevorturk avatar zkoppert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gemoji's Issues

Split out maintained emoji.json file?

I wrote an emoji picker for rofi, and so I also maintain a list of emojis. Since there are no official aliases, rofimoji also doesn't have any, which is not ideal.

I'd like to use your emojis.json file for this, and I think the license allows this. However, I'd rather not depend on some file in some folder, but would much rather have a separate project. Have you thought about splitting the db folder off as a separate project for others to use?
This way, it would be much cleaner and maintenance of the aliases (and the other data) could be comunity-driven and concentrated on one repo.

wrong codepoints for 🏎, 🏍 and maybe more

I believe correct racing car emoji lives here
But in your json, it has different codepoints
here is comparison

The first car is from unicode.org and the second one is from the latest db/emoji.json
In the earlier version of db/emoji.json the racing car symbol was correct, but then something changed.
The same issue with a motorcycle - it also has \uFE0F excessive postfix
I think you need to check all the symbols if they have such distortion.

How should users apply skin tone modifiers?

I've searched through issues and examined the DB and from what I can tell, the library currently reports what emojis can accept a skin tone modifier but doesn't actually provide the modified variants, but rather, only/always the base emoji. That's fine, it seems like it should be easy to produce the variants by appending the modifiers to the base.

Unfortunately, this fails for all of the emojis that have U+FE0F VARIATION SELECTOR-16 appended. As an example, when copying "βœ‹" and "πŸ–οΈ" out of emojis.json, I can do "βœ‹" + "🏻" and get "βœ‹πŸ»", but "πŸ–οΈ" + "🏻" results in "πŸ–οΈπŸ»".

It looks like this library intentionally includes the selector for certain emojis. Moreover, trying to drop the selector, then append the modifier to the remaining unicode scalars, results in correctly modified emoji for only some of the results ("πŸ–οΈ" yes; "πŸ‘¨β€πŸ³" no).

Do you folks have recommendations on how to apply the modifiers?

Emoji not loading on browser

hi! am trying to setup gemoji but when i try to use render the emoji to my view i get an 404 error for the emoji.

am on OS X Yosemite, for what i get the gemoji extract command is only for macOS Sierra or later. so am not sure whats wrong. Any help will be appreciated. thanks

Add missing writing emoji for my project

Was looking to create a project on reusable react components (github.com/copied-components/copied-components) and would like to use the writing hand emoji from Apple ✍️
Would this be possible? Also looking for contributors to get started!

Cricket emoji missing

It appears the cricket πŸ¦— emoji is missing from emoji.json. Maybe that has something to do with 🏏 being present and its alias being "cricket"?

Where do tags come from?

There are no keywords in vendor/unicode-emoji-test.txt
I also cannot find machine-readable emoji list with tags at unicode.org
The best source I found is keywords from this page:
https://unicode.org/emoji/charts/emoji-list.html
But looks like tags in db/emoji.json do not match these keywords.
I tried to look into the code, but found no signs of external resources usage.

I ask about tags because I need them, but I see a lot of emojis do not have tags.
So I suspect emoji.json is not fully generated using external resources but maintained manually?

So should/may I contribute by adding missing tags?

Add support for empty ballot box and radio button emoji

Forgive me if this isn't the right place for this, but I'd love to see two new emoji added: :ballot_box_without_check: and :radio_button_unchecked:.

While I was writing some documentation for a project, I wanted to display what settings a user should set with GitHub's emoji. Only problem is, there's no "unchecked" state for either the ballot box or radio button emojis, so I had to resort to using :white_large_square: and :white_circle:, which don't really look like the ballot box or radio button emojis.

How to escape emoji?

Hi, I'm using your gemoji to create this https://github.com/onmyway133/emoji, to help myself search emoji better.

It 'd be great if I can display like : star : (I add spaces here to that it is not converted to emoji) so that I can copy-paste it right away. I try to escape with back tick, but it always shows as "⭐ "

Thanks

image_path with sprockets-rails 3.2.0 / Rails 5.1.1

Hi we recently upgraded to Rails 5.1.1 and sprockets-rails 3.2.0 and saw an issue with the emojify helper you guys suggest. sprockets-rails 3.2.0 requires you to to explicitly tell the image_path helper if you'd like it to skip the asset pipeline and use the public/ folder.

rails/rails#29535
https://www.schneems.com/2016/11/21/writing-a-rails-feature-blow-by-blow/

Not sure what the best way to update the instructions would be but happy to open a PR.

Unicode 11.0 / Emoji 11.0 (2018)

While Gemoji currently does not even support Unicode 10.0 / Emoji 5.0 yet #134 #136, the 2018 Emoji 11.0 data files have already been published with a full release being scheduled for June.

Apple will probably not release iOS and macOS updates with new emoji graphics before very late in 2018, but since Apple lately seems to be pushing against other vendors reusing their graphics, you might as well update emoji.json now and adopt Google Noto, Twitter Twemoji or Emojione/Emojitwo (which were intended to be supported anyway #72). Twitter in particular was very early to release an update in 2017.

Electron emoji

It does not seem to be documented in this repository, but somehow Github seems to support non-standard electron and atom emojis :electron: :atom: for the respective products. They should probably be dealt with the same as other extensions like octocat :octocat:. The same goes, of course, for any other "emojis" I'm not yet aware of.

Multithread error

Hello!

We use your gems in high-load application and faced with a problem :
NoMethodError in function .find_by_unicode/.find_by_alias.After some review, we found problem: when we use Gemoji in multithreading, variable @all defined in first thread, but not fill-in yet. Second thread use .find_by_unicode, pass check on @all and return not defined @unicode_index => NoMethodError.

I create a RSpec test for you:(it don't looks great, but I have small xp in testing yet:) )

require 'emoji'

RSpec.describe "Multithread error" do

  it "raises" do
    Thread.new { 10000.times { Emoji.find_by_unicode 't' }}
    expect { Emoji.find_by_unicode 't' }.to raise_error {NoMethodError}
  end
end

and propose to use Mutex in this functions to avoid this problem.

private
@mutex = Mutex.new
...

def find_by_unicode(unicode)
   @mutex.syncronize do
      unicodes_index[unicode]
  end
end

def find_by_alias(unicode)
   @mutex.syncronize do
      names_index[names]
  end
end

Maybe, you have another ideas for this error :)

Any suggestions for linux users?

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: 😒

If there's a relatively easy win for this, I'd be happy to add to the documentation.

Thank you!

How do you remove emojis?

We had some that were added during testing and these need removing, but it's not clear how I can do that. Removing the image files from assets just leaves a missing image icon where the emoji was.

Alias :boom: to :collision:

How is there no πŸ’₯? HOW? Today I realized this and it was sad. I searched long and hard and have found πŸ’₯, which seems completely appropriate.

  1. is there a consensus that this should be aliased to πŸ’₯
  2. if so, how do I make this happen

/cc @kneath @rtomayko

Raising errors during use

I'm afraid this is was not an error previously but I'm assuming this library hasn't been updated recently.

The EmojiHelper module indicated on the Readme docs is raising errors during its execution.

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

Error is a NoMethodError thrown by Ruby reading the h(content) method.

NoMethodError (undefined method `h' for #<BlogsController:0x00007f4a2e1f7488>):

New line problem?

I'm writing the following in my code without new lines:

:eu: :romania: :portugal: :it: :es: :fr:

But each emoji displays on a new line.

error extracting emoji on El Capitan

When I run bundle exec gemoji extract public/images/emoji, I get the following error:

.../.bundle/gems/gemoji-3.0.0.rc1/lib/emoji/extractor.rb:18:in `initialize': No such file or directory - /System/Library/Fonts/Apple Color Emoji.ttc (Errno::ENOENT)

lsing the Fonts directory reveals that on my machine, the font has an extension of .ttf rather than .ttc. Logging an issue here rather than creating a PR since I don't know if this is a typo or if some machines have the font under .ttc instead of .ttf.

cant parse man shrugging πŸ€·β€β™‚

Hi,

I tried to use gemoji to take the unicode then display with twemoji, and react-emoji as svg file. unfortunately for the 2 unicode like man_shrugging or woman_student. it is failed to load properly. please refer to imaage attached. May i know how to deal with 2 unicode to parse as 1 emoji?
image

find some issues in emoji.json

When I use emoji.json, I found some emoji code may be not correctly, such as: keycap from 0 to 9.

There are a screenshot:
emoji

Thanks a lot!

Extracting emojis

Extracting emojis does not work as described in the Readme at all, neither on Mac OS El Capitan nor on Mac OS Sierra. The command gemoji extract public/images/emoji was introduced for 3.0.0.rc1, so the current description does not match the behavior of the version 2.1.0 that is installed currently using bundle install. Previously the gemoji gem apparently used rake emoji but this does not work either for the gem version 2.1.0. This leaves the user a bit confused πŸ˜• .

Need help! I got the error " A JSON text must at least contain two octets! (JSON::ParserError)" when exec ./script/regenerate

the detail error message as follow:

/usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `initialize': A JSON text must at least contain two octets! (JSON::ParserError)
    from /usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `new'
    from /usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `parse'
    from /Users/FE/code/github/gemoji/lib/emoji.rb:84:in `block in parse_data_file'
    from /Users/FE/code/github/gemoji/lib/emoji.rb:84:in `open'
    from /Users/FE/code/github/gemoji/lib/emoji.rb:84:in `parse_data_file'
    from /Users/FE/code/github/gemoji/lib/emoji.rb:23:in `all'
    from db/dump.rb:57:in `<main>'
 db/emoji.json | 22561 --------------------------------------------------------
 1 file changed, 22561 deletions(-)

Thanks a lot!

New release?

Hello! Any chance you can cut a new release of this gem? We have the latest version (3.0.1), but it's missing a fair number of newer emoji, e.g. πŸ₯ͺ.

cannot export the "26D1.png"

Sorry, I have a lot of questions, so I feel may be I was a trouble-maker (cry emoji) now.

But I found can't export "26D1.png".

Thanks!

Category-Emoji.plist no longer exists on macOS 10.13+

The db:generate rake task is broken on macOS 10.13 and up because (I might be wrong on this) it looks like Apple started using a private framework to get emoji data in the Character Palette. I did some junior-level spelunking with class-dump but couldn’t figure out how to use the private framework. The best solution that I can think of at the moment is to cross-reference the output of Apple Color Emoji.ttc with unicode CLDR data.

Dashes in aliases

There's a couple of aliases that use dashes instead of underscores: t-rex, e-mail, non-potable_water, -1.

Discord for example uses underscores for first three, and doesn't have -1 alias.

In The Lounge typing :-P would trigger our auto completion for non-potable_water, so for now I just replaced dashes to underscores (except for -1) which should probably be fine.

Any reason for gemoji to keep dashes in these?

ZWJ sequences for custom images

Please define Emoji ZWJ Sequences for custom emojis, so they become interchangeable. That would be perfectly valid according to UTR#51.

Example emoji.json snippet

{
    "emoji": "⛺️\u200DπŸ”"
  , "aliases": [
      "basecamp"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "⛺️\u200Dβ›°"
  , "aliases": [
      "basecampy"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "😁\u200DπŸŽ€"
  , "aliases": [
      "bowtie"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "😏\u200DπŸ‘Ύ"
  , "aliases": [
      "feelsgood"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "πŸ’€\u200DπŸ‘Ύ"
  , "aliases": [
      "finnadie"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "😈\u200DπŸ‘Ύ"
  , "aliases": [
      "goberserk"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "πŸ˜‘\u200DπŸ‘Ύ"
  , "aliases": [
      "godmode"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "πŸ€•\u200DπŸ‘Ύ"
  , "aliases": [
      "hurtrealbad"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "πŸ€“\u200DπŸ’―"
  , "aliases": [
      "neckbeard"
    ]
  , "tags": [
       "custom"
   ]
  }
, {
    "emoji": "🐱\u200DπŸ™"
  , "aliases": [
      "octocat"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "😑\u200DπŸ‘Ύ"
  , "aliases": [
      "rage1"
    ]
  , "tags": [
       "custom"
   ]
  }
, {
    "emoji": "😑\u200DπŸ’’\u200DπŸ‘Ύ"
  , "aliases": [
      "rage2"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "😑\u200DπŸ’’\u200DπŸ’’\u200DπŸ‘Ύ"
  , "aliases": [
      "rage3"
    ]
  , "tags": [
       "custom"
   ]
  }
, {
    "emoji": "😑\u200DπŸ’’\u200DπŸ’’\u200DπŸ’’\u200DπŸ‘Ύ"
  , "aliases": [
      "rage4"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "🐿\u200DπŸ•΄"
  , "aliases": [
      "shipit"
    , "squirrel"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "πŸ€”\u200DπŸ‘Ύ"
  , "aliases": [
      "suspect"
    ]
  , "tags": [
      "custom"
    ]
  }
, {
    "emoji": "😬\u200DπŸ’’"
  , "aliases": [
      "trollface"
    ]
  , "tags": [
      "custom"
    ]
  }

`bundle exec gemoji extract` doesn't work for the RubyGems version

What I expected to happen

  • Add gem "gemoji" (v2.1.0) to my Gemfile
  • Run bundle exec gemoji public/images/emoji
  • It to "just work"

What actually happened

  • Add the gem "gemoji" to my Gemfile
  • Ran bundle exec gemoji public/images/emoji
  • Error returned was bundler: command not found: gemoji

Workaround

Use the gem directly from the GitHub repo (repo version is 3.0.0.rc1)

Other information:
Unsure if this would impact it but my Ruby version is 2.3.1 and I'm running Rails 5.

Add walrus emoji

This adds a walrus emoji. I personally believe this would make the world a better place. This is wished for by everyone at my company. We all really like walruses.

<3 <3 <3 <3 <3 :walrus: <3 <3 <3 <3 <3

Update for latest iOS version

I see that the current latest ios_version is 10.2, can you update emoji for iOS 11.
My project is using iOS 11 and i foudn that some emoji is not supported.
What about emoji for android, I see that some emoji for android isn't supported.

Can't find 'raised_eyebrow' emoji (U+1F928) by alias or unicode

It's in db/emoji.json starting at line 439, but both Emoji.find_by_alias 'raised_eyebrow' and Emoji.find_by_unicode("\u{1f928}") return nil.

I tested on two different systems (macOS 10.15.5 and Ubuntu 16.04), both running Ruby 2.7.1 with gemoji 3.0.1 installed from the gem.

New emojis in Unicode v8.0

There seems to be a bunch of emojis that've been introduced in version 8.0 of Unicode. It'd be awesome if you guys could update your emoji set for the new emojis. We use your gem to tokenize emojis so that they don't break content during database inserts and we have started noticing instances where your gem fails to tokenize.

References
[1] http://www.unicode.org/versions/Unicode8.0.0/?utm_source=next.36kr.com#Character_Additions
[2] https://m.reddit.com/r/Unicode/comments/2m45k9/new_emoji_coming_for_upcoming_unicode_8/

Aliases for Piñata

gemoji/db/emoji.json

Lines 13394 to 13405 in 5361b56

, {
"emoji": "πŸͺ…"
, "description": "piΓ±ata"
, "category": "Activities"
, "aliases": [
"pi_ata"
]
, "tags": [
]
, "unicode_version": "13.0"
, "ios_version": "14.0"
}

The aliase for Piñata is pi_ata as shown above. Is it correct? I think pinata may be better?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.