Git Product home page Git Product logo

gemojione's Introduction

Gemojione

Build Status Downloads Version Emojione Dependencies Coverage GPA

A gem for EmojiOne

This gem exposes the emojione unicode/image assets and APIs for working with them.

Easily lookup emoji name, unicode character, or image assets and convert emoji representations.

Installation

Add this line to your application's Gemfile:

gem 'gemojione'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gemojione

Install emoji image library assets:

$ rake gemojione:install_assets
====================================================================
= emoji image assets install
= Target: /Users/user/src/rails-app/app/assets/images/emoji
= Source: /Users/user/src/emoji/assets
====================================================================
- 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:

> Gemojione.replace_unicode_moji_with_images('I ❤ Emoji')
=> "I <img alt=\"\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/2764.png\"> Emoji"

> Gemojione.replace_named_moji_with_images('I :heart: Emoji')
=> "I <img alt=\"\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/2764.png\"> Emoji"

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

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

> Gemojione.replace_ascii_moji_with_images("I <3 Emoji")
=> "I <img alt=\"\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/2764.png\"> Emoji"

Sprite Replacement APIs:

Gemojione.use_sprite=true
> Gemojione.replace_unicode_moji_with_images("I ❤ Emoji")
=> "I <span class=\"emojione emojione-2764\" alt=\"\" title=\"\">❤</span> Emoji"

> Gemojione.replace_named_moji_with_images("I :heart: Emoji")
=> "I <span class=\"emojione emojione-2764\" alt=\"\" title=\"\">❤</span> Emoji"

> Gemojione.replace_ascii_moji_with_images("I <3 Emoji")
=> "I <span class=\"emojione emojione-2764\" alt=\"\" title=\"\">❤</span> Emoji"

Emoji Library Index APIs:

> index = Gemojione::Index.new

> index.find_by_name('heart')

=> {"moji"=>"❤", "unicode"=>"2764", "unicode_alternates"=>["2764-FE0F"], "name"=>"heart", "shortname"=>":heart:", "category"=>"symbols", "aliases"=>[], "aliases_ascii"=>["<3"], "keywords"=>["like", "love", "red", "pink", "black", "heart", "love", "passion", "romance", "intense", "desire", "death", "evil", "cold", "valentines"], "description"=>"heavy black heart"}

> index.find_by_moji('❤')
=> {"moji"=>"❤", "unicode"=>"2764", "unicode_alternates"=>["2764-FE0F"], "name"=>"heart", "shortname"=>":heart:", "category"=>"symbols", "aliases"=>[], "aliases_ascii"=>["<3"], "keywords"=>["like", "love", "red", "pink", "black", "heart", "love", "passion", "romance", "intense", "desire", "death", "evil", "cold", "valentines"], "description"=>"heavy black heart"}

> index.find_by_keyword('teeth')
=> [{"unicode"=>"1F62C", "unicode_alternates"=>[], "name"=>"grimacing", "shortname"=>":grimacing:", "category"=>"people", "aliases"=>[], "aliases_ascii"=>[], "keywords"=>["face", "grimace", "teeth", "disapprove", "pain", "silly", "smiley", "emotion", "selfie"], "moji"=>"😬", "description"=>"grimacing face"}, {"unicode"=>"1F479", "unicode_alternates"=>[], "name"=>"japanese_ogre", "shortname"=>":japanese_ogre:", "category"=>"people", "aliases"=>[], "aliases_ascii"=>[], "keywords"=>["monster", "japanese", "oni", "demon", "troll", "ogre", "folklore", "devil", "mask", "theater", "horns", "teeth"], "moji"=>"👹", "description"=>"japanese ogre"}]

> index.find_by_ascii(':)')
=> {"unicode"=>"1F604", "unicode_alternates"=>[], "name"=>"smile", "shortname"=>":smile:", "category"=>"people", "aliases"=>[], "aliases_ascii"=>[":)", ":-)", "=]", "=)", ":]"], "keywords"=>["face", "funny", "haha", "happy", "joy", "laugh", "smile", "smiley", "smiling", "emotion"], "moji"=>"😄","description"=>"smiling face with open mouth and smiling eyes"}

Other:

> Gemojione.replace_named_moji_with_unicode_moji("Going for a walk! :woman_walking:")
=> "Going for a walk! 🚶‍♀️"

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

# config/initializers/gemojione.rb
Gemojione.asset_host = "emoji.cdn.com"
Gemojione.asset_path = '/assets/emoji'
Gemojione.default_size = '64px'
Gemojione.use_svg = true
Gemojione.use_sprite = true

You can also serve the assets directly from the gem in your rails app:

# config/application.rb
config.assets.paths << Gemojione.images_path
config.assets.precompile << "emoji/*.png"
# or
config.assets.precompile << "emoji/*.svg"

#for spritesheets
config.assets.paths << Gemojione.sprites_path
config.assets.precompile << "emojione.sprites.css"
config.assets.precompile << "emojione.sprites.png"

String Helper Methods:

You can also

include 'gemojione/string_ext'

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

> 'I ❤ Emoji'.with_emoji_images
=> "I <img alt=\"\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/2764.png\"> Emoji"

> 'I :heart: Emoji'.with_emoji_names
=> "I <img alt=\"\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/2764.png\"> Emoji"

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

> 'heart'.emoji_data
> '❤'.emoji_data
=> {"moji"=>"❤", "unicode"=>"2764", "unicode_alternates"=>["2764-FE0F"], "name"=>"heart", "shortname"=>":heart:", "category"=>"symbols", "aliases"=>[], "aliases_ascii"=>["<3"], "keywords"=>["like", "love", "red", "pink", "black", "heart", "love", "passion", "romance", "intense", "desire", "death", "evil", "cold", "valentines"], "description"=>"heavy black heart"}

Upgrading to 4

Version 4 is a large update and may introduce breaking changes. Please feel free to open issues.

Emojione v4 dropped support for free SVGs. The SVG images included in this gem are from v2.3. If you would like to use the newer emojis, please use PNG or spritesheet.

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:

gem 'escape_utils'

Spritesheet scaling

If you’re using spritesheets, customising Gemojione.default_size at config/initializers/gemojione.rb won’t work. Default size for sprite tag is 64px x 64px, but zoom or transform: scale() can be used for custom scaling. transform: scale() is more widely supported.

.emojione{
  transform: scale(.5);
  margin: -15px;
}

Projects using the gem

If your application uses the gem, open a PR and show your project's ❤️ for the gem so it gets listed here.

Contributors: ❤️

This gem is a former fork of the emoji gem that has been adapted for EmojiOne.

Contributing

  1. Fork it
  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

Notes

Run rake resprite to regenerate the spritesheets if you're adding new images

About Bonusly

Bonusly Logo

Bonusly is the fun and easy way to engage all of your employees and improve retention and productivity at every level of your organization.

Check out our product or our engineering blog.

gemojione's People

Contributors

amclelland avatar amyspark avatar artfuldodger avatar balasankarc avatar connorshea avatar corneliusellen avatar dometto avatar edwardbetts avatar eric-guo avatar georgebrock avatar gnclmorais avatar jonathanwiesel avatar kendrikat avatar lrisberg avatar mikowitz avatar naveed-ahmad avatar parndt avatar peque avatar rspeicher avatar ryan-orr avatar ryosuke-endo avatar semanticart avatar steveklabnik avatar wpeterson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gemojione's Issues

Add moji property for all / most of the definitions

Many definitions in the index.json have their moji property missing.

For example:

"airplane_arriving": {
  "unicode": "1F6EC",
  "unicode_alternates": [],
  "name": "airplane arriving",
  "shortname": ":airplane_arriving:",
  "category": "travel_places",
  "aliases": [],
  "aliases_ascii": [],
  "keywords": [
    "flight",
    "transportation",
    "vehicle",
    "plane",
    "airport",
    "travel",
    "airlines",
    "fly",
    "jet",
    "jumbo",
    "boeing",
    "airbus"
  ]
}

Should have a property "moji": 🛬.

v3.0.1 checksum mismatch

RubyGems says the SHA256 sum should be 7c2c938d64ced0ebed9e1ea842e3982bb88137530c38b2057bb69c752e1bde9f, but a gem fetch gemojione -v '3.0.1' will download a file with 6ab088a5dae3a04196d1059f067ea874aec124431b0dc05c262bfd5ef990685c checksum, which seems to be corrupted when installed, producing the following error:

Bundler::GemspecError: Could not read gem at
/usr/local/lib/ruby/gems/2.3.0/cache/gemojione-3.0.1.gem. It may be corrupted.
An error occurred while installing gemojione (3.0.1), and Bundler cannot
continue.
Make sure that `gem install gemojione -v '3.0.1' --source 'https://rubygems.org/'`
succeeds before bundling.

Support for Emojione v3.x.x

Hi there,

Thanks for an awesome product.
Just wondering if there's plans to update to the latest version of Emojione / Unicode 10?

Thanks!

Can't display the punctuation of '

The punctuation of ' will be translated into it's character number: &#39;
e.g. Gemojione.replace_unicode_moji_with_images "what's your name" will be translated into:
"what&#39;s your name"

License for emojione 4.5 assets may be problematic

It seems the png's in this gem are from the 4.5 distribution of emojione, which is not under a CC license, but can only be used for personal use unless an enterprise license is purchased. Please consider reverting to the 2.3 version.

Update badges

I noticed this on the Readme:

Travis still points to the old URL.

  • Gemnasium is shut down.
  • Code coverage badge is missing.

Add keywords for unicode9

Unicode 9 definitions presented in #18 have no keywords (most of them).

We need to add keywords to them once source repo (Ranks/emojione) add them

Add emoji retrieval via shortname

At the moment, gemojione provides a regex for matching all possible emoji short names. However, there is not a find_by_shortname method in the index. Could this be added?

I can file a pull request if asked, I've done it locally.

README regarding loading assets directly from gem

The README currently states that the following lines should be added to serve the SVG image versions directly from the gem instead of having to add them to the application:

# config/application.rb
config.assets.paths << Gemojione.images_path
config.assets.precompile << "emoji/*.svg"

Gemojione.images_path returns the correct path within the gem (assets/svg), but it does not contain another directory named "emoji" - leading to the images not being precompiled / available in development.

Currently, this can be solved by removing the emoji directory name, but this of course leads to all assets being in the main assets namespace:

# config/application.rb
config.assets.precompile << "*.svg"

# config/initializers/gemojione.rb
Gemojione.asset_path = '/assets'

I'd like to load the images from the gem as I don't really want to add another 7MB to the application, but I'd prefer to still have them in their own namespace (as described in the README).

Did I simply do something wrong, is this a bug or the intended behaviour and the README just wasn't updated?

Thanks in advance and in general for this great gem!

Missing Emojis in index.json (Version 4.5.0)

Hey,

just saw that quite a lot emojis are missing in the index.json file. (Seems 162 are missing, unless I'm totally wrong. I compared with this file)

A few examples:

  • zany_face
  • hot_face
  • cold_face

Is there a way to generate these, or do we have to add each emoji manually?

`replace_named_moji_with_images` doesn't work with aliases

I'm not sure if this is intended, but I was expecting that replace_named_moji_with_images would work with aliases too. My specific case is :robot_face:: its actual name is :robot: and :robot_face: is an alias. But when I call Gemojione.replace_named_moji_with_images(":robot_face:"), it returns ":robot_face:".

Looking at the source, I suppose it's because the regex used in this method (shortname_moji_regex) is generated from the Index's @emoji_by_code, and aliases are added to @emoji_by_name. Would it be acceptable if aliases were added to @emoji_by_code too? If so, I could make a pull request for that.

Thanks in advance 😄

Add gay_pride_flag when EmojiOne adds the asset

When doing the unicode9 joining process, I identified a new definition:

{
  "gay_pride_flag": {
    "unicode": "1F3F3-1F308",
    "unicode_alternates": [],
    "name": "gay_pride_flag",
    "shortname": ":gay_pride_flag:",
    "category": "extras",
    "aliases": [
      ":rainbow_flag:"
    ],
    "aliases_ascii": [],
    "keywords": []
  }
}

However this asset is not present yet in the source repo.
See joypixels/emojione#274

When added, will add here

missing regional images from emojione 2.2.6

Not sure if this is intentional, but these 39 emoji( all from regional category ) are missing.

["0023", "002a", "0030", "0031", "0032", "0033", "0034", "0035", "0036", "0037", "0038", "0039", "1f1e6", "1f1e7", "1f1e8", "1f1e9", "1f1ea", "1f1eb", "1f1ec", "1f1ed", "1f1ee", "1f1ef", "1f1f0", "1f1f1", "1f1f2", "1f1f3", "1f1f4", "1f1f5", "1f1f6", "1f1f7", "1f1f8", "1f1f9", "1f1fa", "1f1fb", "1f1fc", "1f1fd", "1f1fe", "1f1ff", "1f5e8"]

Possibility to downcase emoji codes when generating urls?

Some CDNs name the emoji image files with the downcased version of the emoji code, for example "1f61b" instead of "1F61B". Cloudflare is an example.

Even jsdelivr, which I was using, is failing for some uppercase codes, but working for the downcase version. Example: I get this url for :clown:: https://cdn.jsdelivr.net/emojione/assets/svg/1F921.svg, which gives me an "Access Denied" error, but the downcase version works normally: https://cdn.jsdelivr.net/emojione/assets/svg/1f921.svg.

Is this a problem with the CDNs or would it make sense to be able to downcase the codes in this gem?

Add emoji order

As mentioned in #18, adding this feature will improve emoji sorting inside each category.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.