Twitter Emoji has a official JavaScript implementation of twemoji. This RubyGem Twemoji is a minimum implementation in Ruby, does not implement all its features.
Add this line to your application's Gemfile:
gem "twemoji"
And then execute:
$ bundle
Or install it yourself as:
$ gem install twemoji
@bramswenson has put an effeort to support Ruby 1.9.3, please use his forked branch:
gem "twemoji", github: "bramswenson/twemoji", branch: "ruby-1.9.3"
> Twemoji.find_by(text: ":heart_eyes:")
=> "1f60d"
> Twemoji.find_by(code: "1f60d")
=> ":heart_eyes:"
> Twemoji.find_by(unicode: "😍")
=> ":heart_eyes:"
> Twemoji.find_by(unicode: "\u{1f60d}")
=> ":heart_eyes:"
> Twemoji.find_by_text(":heart_eyes:")
=> "1f60d"
> Twemoji.find_by_code("1f60d")
=> ":heart_eyes:"
> Twemoji.find_by(unicode: "😍")
=> ":heart_eyes:"
> Twemoji.render_unicode ":heart_eyes:"
=> "😍"
> Twemoji.render_unicode "1f60d"
=> "😍"
> Twemoji.parse "I like chocolate :heart_eyes:!"
=> "I like chocolate <img class='emoji' draggable='false' title=':heart_eyes:' alt='😍' src='https://twemoji.maxcdn.com/16x16/1f60d.png'>!"
Default assets root url, by default will be https://twemoji.maxcdn.com/
:
> Twemoji.parse 'I like chocolate :heart_eyes:!', asset_root: "foocdn.com"
=> "I like chocolate <img class='emoji' draggable='false' title=':heart_eyes:' alt='😍' src='foocdn.com/16x16/1f60d.png'>!"
Default assets file extensions, by default .png
.
> Twemoji.parse 'I like chocolate :heart_eyes:!', file_ext: ".svg"
=> "I like chocolate <img class='emoji' draggable='false' title=':heart_eyes:' alt='😍' src='https://twemoji.maxcdn.com/svg/1f60d.svg'>!"
Default assets/folder size, by default "16x16"
. Available via Twitter CDN: 16
, 36
, 72
.
> Twemoji.parse 'I like chocolate :heart_eyes:!', image_size: "72x72"
=> "I like chocolate <img class='emoji' draggable='false' title=':heart_eyes:' alt='😍' src='https://twemoji.maxcdn.com/72x72/1f60d.png'>!"
Default img css class name, by default "emoji"
.
> Twemoji.parse 'I like chocolate :heart_eyes:!', class_name: "superemoji"
=> "I like chocolate <img class='superemoji' draggable='false' title=':heart_eyes:' alt='😍' src='https://twemoji.maxcdn.com/16x16/1f60d.png'>!"
> Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji', img_attr: "style='height: 1.3em;'")
=> "I like chocolate <img class='twemoji' draggable='false' title=':heart_eyes:' alt='😍' style='height: 1.3em;' src='https://twemoji.maxcdn.com/16x16/1f60d.png'>!"
> Twemoji.emoji_pattern
=> /(:smile:|:laughing:| ... |:womens:|:x:|:zero:)/
- Fork it ( https://github.com/jollygoodcode/twemoji/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
A huge THANK YOU to all our [contributors] (https://github.com/jollygoodcode/twemoji/graphs/contributors)! ❤️
This project is maintained by Jolly Good Code.
MIT License. See LICENSE for details.