Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Emoji images and names.

License

NotificationsYou must be signed in to change notification settings

github/gemoji

Emoji images and names. See the LICENSE for copyright information.

Installation

Addgemoji to your Gemfile.

gem'gemoji'

Sync images

Images can be copied to your public directory withrake emoji in your app. This is the recommended approach since the images will be available at a consistent location. This works best with cached formatted user content generated by tools likehtml-pipeline.

# Rakefileload'tasks/emoji.rake'
$ rake emoji

Assets Precompiling

If you must, you can manually add all the images to your asset load path.

# config/application.rbconfig.assets.paths <<Emoji.images_path

Then have them compiled to public on deploy.

# config/application.rbconfig.assets.precompile <<"emoji/**/*.png"

WARNING Since there are a ton of images, just adding the path may slow down other lookups if you aren't using it. Compiling all the emojis on deploy will add overhead to your deploy if even the images haven't changed. Theres just so many more superfluous files to iterate over. Also, the urls will be fingerprinted which may not be ideal for referencing from cached content.

Example Rails Helper

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

See theEmoji cheat sheet for more examples.

moduleEmojiHelperdefemojify(content)h(content).to_str.gsub(/:([\w+-]+):/)do |match|ifemoji=Emoji.find_by_alias($1)%(<img alt="#$1" src="#{image_path("emoji/#{emoji.image_filename}")}" width="20" height="20" />)elsematchendend.html_safeifcontent.present?endend

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 theEmoji.all list:

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?#=> trueemoji.image_filename#=> "music.png"

As you create new emoji, you must ensure that you also create and put the imagesthey reference by theirimage_filename to your assets directory.

You can customizeimage_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"endEmoji.find_by_alias"music"#=> emojiEmoji.find_by_unicode"\u{266b}"#=> emoji

[8]ページ先頭

©2009-2025 Movatter.jp