/twemoji

:shipit: Twitter emoji in Ruby :blush:

Primary LanguageRubyMIT LicenseMIT

Twemoji

Gem Version Build Status Inline docs

Twitter Emoji has a official JavaScript implementation of twemoji. This RubyGem Twemoji is a minimum implementation in Ruby, does not implement all its features.

Installation

Add this line to your application's Gemfile:

gem "twemoji"

And then execute:

$ bundle

Or install it yourself as:

$ gem install twemoji

Ruby 1.9.3 Support

@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"

Integration

Usage

API

Twemoji.find_by text or code or unicode

> 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

> Twemoji.find_by_text(":heart_eyes:")
=> "1f60d"

Twemoji.find_by_code

> Twemoji.find_by_code("1f60d")
=> ":heart_eyes:"

Twemoji.find_by_unicode

> Twemoji.find_by(unicode: "😍")
=> ":heart_eyes:"

Twemoji.render_unicode

> Twemoji.render_unicode ":heart_eyes:"
=> "😍"

> Twemoji.render_unicode "1f60d"
=> "😍"

Twemoji.parse

> 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'>!"
Twemoji.parse options
asset_root

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'>!"
file_ext

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'>!"
image_size

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'>!"
class_name

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'>!"
img_attr
> 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

> Twemoji.emoji_pattern
=> /(:smile:|:laughing:| ... |:womens:|:x:|:zero:)/

Contributing

  1. Fork it ( https://github.com/jollygoodcode/twemoji/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Credits

A huge THANK YOU to all our [contributors] (https://github.com/jollygoodcode/twemoji/graphs/contributors)! ❤️

This project is maintained by Jolly Good Code.

License

MIT License. See LICENSE for details.