Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

emoji

> 编程语言
Open source

A gem. For Emoji. For everyone. ❤

445 stars0 likes0 views
WebsiteGitHub

About

A gem. For Emoji. For everyone. ❤

Emoji

A Ruby gem. For emoji. For everyone. :heart:

This gem exposes the Phantom Open Emoji library unicode/image assets and APIs for working with them.

Easily look up emoji's name, unicode character, or image assets and convert it into emoji representations.

Table of Contents

  • Installation
  • Usage
    • Image Replacement APIs
    • Emoji Library Index APIs
    • String Helper Methods
  • Emoji Asset Host
  • HTML Safety and Performance
  • Contributors :heart:
  • Contributing

Installation

First, add this line to your application's Gemfile:

ruby
gem 'emoji'

And then execute:

$ bundle

Or install it yourself as:

$ gem install emoji

Finally, install the emoji image library assets:

$ rake emoji:install_assets
====================================================================
= emoji image assets install
= Target: /Users/user/src/rails-app/app/assets/images/emoji
= Source: /Users/user/src/emoji/assets/images
====================================================================
- Creating /Users/user/src/rails-app/app/assets/images/emoji...
- Installing assets...

Usage

You can use this gem to replace unicode emoji characters with img tags linking to the appropriate emoji image.

Image Replacement APIs:

ruby
> Emoji.replace_unicode_moji_with_images('I ❤ Emoji')
=> "I  Emoji"

> Emoji.image_url_for_unicode_moji('❤')
=> "http://localhost:3000/assets/emoji/heart.png"

> Emoji.image_url_for_name('heart')
=> "http://localhost:3000/assets/emoji/heart.png"

Emoji Library Index APIs:

ruby
> index = Emoji::Index.new

> index.find_by_name('heart')
=> {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}

> index.find_by_moji('❤')
=> {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}

> index.find_by_unicode('2764')
=> {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}

Default configuration integrates with Rails, but you can change it with an initializer:

ruby
# config/initializers/emoji.rb
Emoji.asset_host = "emoji.cdn.com"
Emoji.asset_path = '/assets/emoji'
Emoji.use_plaintext_alt_tags = true

String Helper Methods:

You can also include the string helper module

ruby
require 'emoji/string_ext'

and call methods directly on your string to return the same results:

ruby
> 'I ❤ Emoji'.with_emoji_images
=> "I  Emoji"

> 'heart'.image_url
> '❤'.image_url
=> "http://localhost:3000/assets/emoji.heart.png"

> 'heart'.emoji_data
> '❤'.emoji_data
=> {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}

Emoji Asset Host

By default when used with Rails, this gem will inherit Rails configured Rails.asset_host. Otherwise, you will need to manually configure the Emoji.asset_host as a string URL or a lambda/proc.

ruby
# String URL
Emoji.asset_host = 'http://your.com'

# Custom Host Proc, takes asset path as a param
Emoji.asset_host = lambda {|path| path.size % 2 == 0 ? 'http://even.com' : 'http://odd.com'}

HTML Safety and Performance

This gem uses pure Ruby code for compatibility with different Ruby virtual machines. However, there can be significant performance gains to escaping incoming HTML strings using optimized, native code in the escape_utils gem.

The emoji gem will try to use escape_utils if it's available, but does not require it. Benchmarks show a 10x-100x improvement in HTML escaping performance, based on the size of the string being processed.

To enable native HTML escaping, add this line to your application's Gemfile:

ruby
gem 'escape_utils'

Contributors: :heart:

This project was spawned from conversation at the BurlingtonRB conference between Steve/Winfield. Together, they built the the initial gem. Huge thanks to everyone else who's submitted code and work to the project.

  • @steveklabnik: Created this project and made it all happen
  • @wpeterson: gem implementation
  • @ryan-orr: Granted the official emoji rubygems account
  • @mikowitz: String ext helpers
  • @semanticart: Cleanup/Ruby 1.9.3 support
  • @parndt: README doc fixes
  • @neuegram: XSS Security Audit
  • @tumes: Plaintext Emoji Alt Tags
  • @poporul: Emoji::Index Refactoring
  • @dilkhush: Emoji::Index Search by Unicode
  • @cromulus: Emoji.replace_unicode_moji_with_name() API

Contributing

  1. Fork the repo
  2. Bundle Install (bundle install)
  3. Run the Tests (rake test)
  4. Create your feature branch (git checkout -b my-new-feature)
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

Issues· 5 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言