GithubHelp home page GithubHelp logo

emoji's Introduction

Emoji

Build Status

A Ruby gem. For emoji. For everyone. ❤️

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

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

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:

> Emoji.replace_unicode_moji_with_images('I ❤ Emoji')
=> "I <img alt=\"\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/heart.png\"> 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:

> 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:

# 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

require 'emoji/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/heart.png\"> 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.

# 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:

gem 'escape_utils'

Contributors: ❤️

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.

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

emoji's People

Contributors

cromulus avatar dilkhush avatar georgebrock avatar id25 avatar maxcell avatar mikowitz avatar parndt avatar poporul avatar ryan-orr 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  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

emoji's Issues

Make escaping HTML optional

Any way to have the escaping be optional?

Otherwise, we end up with something like this where Emoji's turns into Emoji&#39;s:

2.1.1p76 :009 > Emoji.replace_unicode_moji_with_images("I ❤ Emoji's")
 => "I <img alt=\"\" class=\"emoji\" src=\"http://hello.cloudfront.net/images/emojis/heart.png\"> Emoji&#39;s"

Complete emoji list from Unicode

Leaving some notes for others who run across missing emojis.

The Unicode organization releases regular updates to their CLDR project which annotates every character and emoji that is published.

This gem would ideally:

  1. Use the standard format released by Unicode
  2. Have a script to pull the latest annotations whenever a new Gem gets built.

Links:

Sample:

{
  "🥸": {
        "default": [
          "disguise",
          "disguised face",
          "face",
          "glasses",
          "incognito",
          "nose"
        ],
        "tts": [
          "disguised face"
        ]
      },
}

It appears the tts property would be most suited for a "name" property.

There are 24 Emoji Unicode blocks with varying ranges but the annotation file seems to have a good select list.

Opening a can of worms, there are additional Unicode blocks worth considering. Example Chess Symbols but I cannot find those annotated by the CLDR project.

However, here is the UnicodeData.txt data file which appears to annotates every character. This might be the best file to use. Sample:

Hex; Description
1F600;GRINNING FACE;So;0;ON;;;;;N;;;;;
1F601;GRINNING FACE WITH SMILING EYES;So;0;ON;;;;;N;;;;;
1F602;FACE WITH TEARS OF JOY;So;0;ON;;;;;N;;;;;
1F603;SMILING FACE WITH OPEN MOUTH;So;0;ON;;;;;N;;;;;
1F604;SMILING FACE WITH OPEN MOUTH AND SMILING EYES;So;0;ON;;;;;N;;;;;
1F605;SMILING FACE WITH OPEN MOUTH AND COLD SWEAT;So;0;ON;;;;;N;;;;;
1F606;SMILING FACE WITH OPEN MOUTH AND TIGHTLY-CLOSED EYES;So;0;ON;;;;;N;;;;;
1F607;SMILING FACE WITH HALO;So;0;ON;;;;;N;;;;;
1F608;SMILING FACE WITH HORNS;So;0;ON;;;;;N;;;;;
1F609;WINKING FACE;So;0;ON;;;;;N;;;;;
1F60A;SMILING FACE WITH SMILING EYES;So;0;ON;;;;;N;;;;;
1F60B;FACE SAVOURING DELICIOUS FOOD;So;0;ON;;;;;N;;;;;
1F60C;RELIEVED FACE;So;0;ON;;;;;N;;;;;
1F60D;SMILING FACE WITH HEART-SHAPED EYES;So;0;ON;;;;;N;;;;;
1F60E;SMILING FACE WITH SUNGLASSES;So;0;ON;;;;;N;;;;;
1F60F;SMIRKING FACE;So;0;ON;;;;;N;;;;;
1F610;NEUTRAL FACE;So;0;ON;;;;;N;;;;;
1F611;EXPRESSIONLESS FACE;So;0;ON;;;;;N;;;;;
1F612;UNAMUSED FACE;So;0;ON;;;;;N;;;;;
1F613;FACE WITH COLD SWEAT;So;0;ON;;;;;N;;;;;
puts [0x1F600].pack('U*')
puts "\u{1F600}"
puts ["1F600".to_i(16)].pack('U*')

Unable to use in console

Hi i am trying to use this gem functionality on rails console. I tried to require 'emoji' but get following exception.

LoadError: cannot load such file -- emoji
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
	from (irb):2
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/console.rb:65:in `start'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/console_helper.rb:9:in `start'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:78:in `console'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
	from /home/wasifsaeed/Projects/edu_boss/bin/rails:9:in `<top (required)>'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `block in load'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /home/wasifsaeed/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'

Apostrophes are clobbered when string contains emoji + contraction

If I have a string It's time to go home 🎉, it will replace the apostrophe in It's with &#39. Any way to keep the apostrophe as it is and convert the emoji?

It's time to go home 🎉 => It&#39s time to go home :tada I'd like to see It's time to go home :tada:.

I'm passing my string into the self.replace_unicode_moji_with_name method.

Disclose the fact that numerous emoji are missing from this gem

"massage", "satellite", and other emoji don't work with this library.

The incompleteness, due to your reliance on the Phantom Open Emoji set, should be clearly spelled out at the top of the readme. This way, I may be the last person to waste an hour of his weekend digging through scripts and repos to find a really unexpected bug.

I like your gem otherwise, but it's called "emoji", implying that it's the Ruby library for handling those characters. The facts that it only handles some of them, and that you already knew about this issue but didn't tell us is bad form and frankly rude to your users.

It's not clear what the value of the asset_host configuration option should be.

It was not clear whether asset_host should be set to the hostname only (example.com) or if it should also include the scheme (https://example.com). The example given in the README does not include the scheme, which suggested that it only takes a hostname:

Emoji.asset_host = "emoji.cdn.com"

However, this results in the following output (note the leading forward slash in src):

<img src="/emoji.cdn.com/emoji/heart.png" />

Instead of:

<img src="http://emoji.cdn.com/emoji/heart.png" />

Perhaps the name of the option should be asset_base_url? Or, if it's possible, prepend the value of asset_host with what ever scheme the app is using?

Otherwise a handy little gem, and the casbah, it rocks.

find_by_moji can't parse ❤ emoji.

index.find_by_moji('❤')
# => nil

When i parse emoji from json, heart and maybe a few more emoji's are broken.
I figured out the problem, and found something.
Can you fix it?

# This emoji return nil:
"❤".bytes
# => [226, 157, 164]

#This is correct:
"❤️".bytes
# => [226, 157, 164, 239, 184, 143]

Gem crash when asset_host_spec is a Proc

I have a certain use-case where my global (development) asset_host is set to a Proc.

In that case, my development server crashes on startup:

.../emoji-1.0.4/lib/emoji.rb:31:in `parse_and_validate_asset_host': undefined method `size' for #<Proc:0x007fd44c4439f0> (NoMethodError)

Broken heart emoji (💔)

Great gem.

Can you tell me where the broken heart (💔) emoji can be found?
All emoji aren't included?

Thanks, Lasse.

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.