EmojiReplace
A library to work around the special UTF8MB4 encoding in Ruby and Ruby on Rails.
Uses the "emoji" gem here: https://github.com/wpeterson/emoji
Install
Add this to your Gemfile and bundle:
gem "emoji_replace"
Seamless usage
Modify your model like this:
class Message < ActiveRecord::Base
include EmojiReplace::Seamless
replace_emoji_seamlessly :message
end
You can now call the attributes like normal:
message.message = "I ❤ you"
message.message #=> "I ❤ you"
message.read_attribute(:message) #=> "I %{emoji:heart} you"
message.message(html: true) #=> "I <img alt=\"heart\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"> you"
Manual usage
If you don't want the seamless functionality, you can also perform the replace manually like this:
Replace emoji's to the code format:
replacer = EmojiReplace::Replacer.new(text: "I ❤ you")
replacer.replace
replacer.text #=> "I %{emoji:heart} you"
Replace the code format back to emoji's:
replacer = EmojiReplace::Replacer.new(text: "I %{emoji:heart} you")
replacer.back
replacer.text #=> "I ❤ you"
Replace the code format back to HTML:
replacer = EmojiReplace::Replacer.new(text: "I %{emoji:heart} you")
replacer.back(html: true)
replacer.text #=> "I <img alt=\"heart\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"> you"
Contributing to emoji_replace
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
- Fork the project.
- Start a feature/bugfix branch.
- Commit and push until you are happy with your contribution.
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright (c) 2015 kaspernj. See LICENSE.txt for further details.