GithubHelp home page GithubHelp logo

global-localhost / gemoji Goto Github PK

View Code? Open in Web Editor NEW

This project forked from github/gemoji

0.0 0.0 0.0 25.3 MB

Emoji images and names.

License: MIT License

Ruby 83.97% HTML 10.67% Shell 5.35%

gemoji's Introduction

gemoji

This library contains character information about native emojis.

Installation

Add gemoji to your Gemfile.

gem 'gemoji'

Example Rails Helper

This would allow emojifying content such as: it's raining :cat:s and :dog:s!

See the Emoji cheat sheet for more examples.

module EmojiHelper
  def emojify(content)
    h(content).to_str.gsub(/:([\w+-]+):/) do |match|
      if emoji = Emoji.find_by_alias($1)
        %(<img alt="#$1" src="#{image_path("emoji/#{emoji.image_filename}")}" style="vertical-align:middle" width="20" height="20" />)
      else
        match
      end
    end.html_safe if content.present?
  end
end

Unicode mapping

Translate emoji names to unicode and vice versa.

>> Emoji.find_by_alias("cat").raw
=> "๐Ÿฑ"  # Don't see a cat? That's U+1F431.

>> Emoji.find_by_unicode("\u{1f431}").name
=> "cat"

Adding new emoji

You can add new emoji characters to the Emoji.all list:

emoji = Emoji.create("music") do |char|
  char.add_alias "song"
  char.add_unicode_alias "\u{266b}"
  char.add_tag "notes"
end

emoji.name #=> "music"
emoji.raw  #=> "โ™ซ"
emoji.image_filename #=> "unicode/266b.png"

# Creating custom emoji (no Unicode aliases):
emoji = Emoji.create("music") do |char|
  char.add_tag "notes"
end

emoji.custom? #=> true
emoji.image_filename #=> "music.png"

As you create new emoji, you must ensure that you also create and put the images they reference by their image_filename to your assets directory.

You can customize image_filename with:

emoji = Emoji.create("music") do |char|
  char.image_filename = "subdirectory/my_emoji.gif"
end

For existing emojis, you can edit the list of aliases or add new tags in an edit block:

emoji = Emoji.find_by_alias "musical_note"

Emoji.edit_emoji(emoji) do |char|
  char.add_alias "music"
  char.add_unicode_alias "\u{266b}"
  char.add_tag "notes"
end

Emoji.find_by_alias "music"       #=> emoji
Emoji.find_by_unicode "\u{266b}"  #=> emoji

gemoji's People

Contributors

aroben avatar ashmaroli avatar asianmack avatar bkeepers avatar chvp avatar cobyism avatar danthompson avatar elektronaut avatar gavingmiller avatar janko avatar javan avatar jeffmcneill avatar jeremy avatar jhawthorn avatar jobveldhuis avatar josh avatar juanitofatas avatar julia7662 avatar koddsson avatar lautis avatar mikemcquaid avatar mislav avatar myxaluch avatar purplebooth avatar rick avatar shayfrendt avatar skunkmb avatar trevorturk avatar vxjasonxv avatar wearhere avatar

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.