Git Product home page Git Product logo

gemoji's Introduction

gemoji

Emoji images and names. See the LICENSE for copyright information.

Installation

Add gemoji to you Gemfile.

gem 'gemoji'

Sync images

Images can be copied to your public directory with rake emoji in your app. This is the recommended approach since the images will be available at a consistent location. This works best with cached formatted user content generated by tools like html-pipeline.

# Rakefile
load 'tasks/emoji.rake'
$ rake emoji

Assets Precompiling

If you must, you can manually add all the images to your asset load path.

# config/application.rb
config.assets.paths << Emoji.images_path

Then have them compiled to public on deploy.

# config/application.rb
config.assets.precompile << "emoji/*.png"

WARNING Since there are a ton of images, just adding the path may slow down other lookups if you aren't using it. Compiling all the emojis on deploy will add overhead to your deploy if even the images haven't changed. Theres just so many more superfluous files to iterate over. Also, the urls will be fingerprinted which may not be ideal for referencing from cached content.

Example Rails Helper

This would allow emojifying content such as: it's raining :cats: and :dogs:!

See the Emoji cheat sheet for more examples.

module EmojiHelper
  def emojify(content)
    h(content).to_str.gsub(/:([a-z0-9\+\-_]+):/) do |match|
      if Emoji.names.include?($1)
        '<img alt="' + $1 + '" height="20" src="' + asset_path("emoji/#{$1}.png") + '" style="vertical-align:middle" width="20" />'
      else
        match
      end
    end.html_safe if content.present?
  end

  def reverse_emojify(content)
    Emoji.unicodes.each do |unicode|
      content.gsub!(unicode, ":#{Emoji.from_unicode(unicode)}:")
    end
    content
  end
end

gemoji's People

Contributors

asianmack avatar cobyism avatar danthompson avatar jeremy avatar josh avatar julia7662 avatar lautis avatar mbillard avatar rick avatar rsenk330 avatar shayfrendt avatar skalnik avatar spraints avatar tnm avatar trevorturk avatar

Watchers

 avatar  avatar  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.