Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e4801df
Replaced CDN URL (jsdelivr.net hosts Twemoji now)
makaroni4 Jun 12, 2023
810f983
WIP: added a script to download all emojies from unicode.org
makaroni4 Jun 12, 2023
644ef45
Download unicode.org emojies and prepare valid emoji list for the lat…
makaroni4 Jun 12, 2023
53ec1d9
Finally, copy new data files to the lib folder
makaroni4 Jun 12, 2023
12b67af
Roll back original twemoji lists
makaroni4 Jun 12, 2023
b013bdb
Keep old unicode definitions, add new ones from 14.0.2
makaroni4 Jun 12, 2023
d6e0658
Merge old and new unicode names to prevent breaking existing emojies
makaroni4 Jun 12, 2023
d785d81
Fix specs
makaroni4 Jun 12, 2023
dba4c23
More TODO-s before shipping it
makaroni4 Jun 13, 2023
83d92ae
Extracted emoji name generator method to a file, sort absent emojies …
Jun 15, 2023
eb45baf
Added sorting to emoji data sets to prevent random changes in commits
Jun 15, 2023
c1be7d4
DRY emoji CDN URL, doubled CDN check parallelism to speed up tooling …
Jun 15, 2023
eb743a0
Fix specs
Jun 15, 2023
ac38ea0
Added specs for emojies with multiple keys, switch docs to use single…
Jun 15, 2023
252f1ca
Extracted emoji name fixing to a helper
Jun 15, 2023
7fcb853
Extract emoji validation to a helper method
Jun 15, 2023
78cb424
Extract CDN validation to a helper
Jun 15, 2023
8c0d996
Extract absent emojies file saving to a helper
Jun 15, 2023
6e69396
Nicely print the final emoji count after CDN validation
Jun 15, 2023
95821cc
Extract final unicode maps preparation into a helper
Jun 15, 2023
241af32
Added README
Jun 15, 2023
a5ac73a
Fix README typos
Jun 15, 2023
4025292
Added a REAMDE line on how to add this fork to a Rails app
Jun 15, 2023
32c8ce0
Added a README note that it's a fork
Jun 15, 2023
d27d5ee
Fix typo
Jun 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.3
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
```ruby
{
...
":heart_eyes:" => "https://twemoji.maxcdn.com/2/svg/1f60d.svg",
":heart_eyes:" => "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f60d.svg",
...
}
```
Expand All @@ -70,7 +70,7 @@
```ruby
{
...
":heart_eyes:" => "https://twemoji.maxcdn.com/2/72x72/1f60d.png",
":heart_eyes:" => "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f60d.png",
...
}
```
Expand All @@ -80,7 +80,7 @@
- Require Ruby 2.0+
- `Twemoji::CODES` changes to `Twemoji.codes`
- `Twemoji::ICODES` changes to `Twemoji.invert_codes`
- `asset_root` config default value changed to `https://twemoji.maxcdn.com/2`
- `asset_root` config default value changed to `https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets`
- `file_ext` config default value changed to `svg`, available values are `"svg"` and `"png"`
- PNG now only has one size `72x72`
- Remove `Twemoji.to_json` method
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ group :development do
gem "rake"
gem "bundler"
gem "pry"
gem "async"
gem "async-http"
end

group :test do
Expand Down
55 changes: 44 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Twemoji

:warning: This is a fork of an unmaintained **twemoji** gem that contains the latest Twemoji set of 3.2K emojies.

[![Gem Version](https://badge.fury.io/rb/twemoji.svg)](https://badge.fury.io/rb/twemoji)
[![Build Status](https://travis-ci.org/jollygoodcode/twemoji.svg)][travis]
[![Inline docs](http://inch-ci.org/github/jollygoodcode/twemoji.svg?branch=master)][inch-doc]
Expand All @@ -12,10 +14,41 @@ Twitter [opensourced Twitter Emoji](http://twitter.github.io/twemoji/) and the o

This RubyGem `twemoji` is a minimum implementation of Twitter Emoji in Ruby so that you can use emoji in your Ruby/Rails apps too!

__Note:__ This gem might not implement all the features available in the JavaScript implementation.
## About this fork

It looks like the original Twemoji gem isn't maintained – the latest version contains only 1.6K emojies from 3.2K emojies present in the latest Twemoji version.

This fork:

* fixes a broken CDN URL (Twemojies are hosted on [jsdelivr.com](https://www.jsdelivr.com/) now :heart:)
* imports the latest emojies set (with backwards compatibility)
* adds the necessary tooling to easily import future editions

### How to import the latest Twemoji set

**Step 1**. Change the CDN URL (`Twemoji::Configuration::DEFAULT_ASSET_ROOT`) constant.

**Step 2**. Run the tooling script that downloads the latest [unicode.org](https://unicode.org/Public/emoji/latest/emoji-test.txt) official emoji list, validates which emojies are present on CDN and prepares unicode-emoji name maps for the gem.

```bash
bundle install

bundle exec ruby tooling/import_latest_emojies.rb
```

**Step 3**. PROFIT :beers:

### How to use this fork in your Rails app

In your Gemfile, include the latest fork's tag:

```ruby
gem "twemoji", github: "sqlhabit/twemoji", tag: "v4.0.1"
```

## Twemoji Gem and twemoji.js versions

- Twemoji Gem 4.x supports Twemoji v14 (3245 emojis)
- Twemoji Gem 3.x supports twemoji.js V2 (1661 emojis) [Preview](https://jollygoodcode.github.io/twemoji/)
- Twemoji Gem 2.x supports twemoji.js V1 (874 emojis) [Preview](http://jollygoodcode.github.io/twemoji/v1/)

Expand Down Expand Up @@ -66,7 +99,7 @@ In your ERb view:
will render

```
I like chocolate <img class="emoji" draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/2/72x72/1f60d.png">!
I like chocolate <img class="emoji" draggable="false" title=":heart_eyes:" alt="😍" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f60d.png">!
```

More options could be passed in, please see [Twemoji.parse options](https://github.com/jollygoodcode/twemoji#twemojiparse-options) for more details.
Expand Down Expand Up @@ -130,28 +163,28 @@ Parsing by name token:

```ruby
> Twemoji.parse "I like chocolate :heart_eyes:!"
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/2/svg/1f60d.svg" class="emoji">!'
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f60d.svg" class="emoji">!'
```

Parsing by name unicode values:

```ruby
> Twemoji.parse "I like chocolate 😍!"
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/2/svg/1f60d.svg" class="emoji">!'
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f60d.svg" class="emoji">!'
```

Parsing by both name and unicode:

```ruby
> Twemoji.parse ":cookie: 🎂"
=> '<img draggable="false" title=":cookie:" alt="🍪" src="https://twemoji.maxcdn.com/2/svg/1f36a.svg" class="emoji"> <img draggable="false" title=":birthday:" alt="🎂" src="https://twemoji.maxcdn.com/2/svg/1f382.svg" class="emoji">'
=> '<img draggable="false" title=":cookie:" alt="🍪" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f36a.svg" class="emoji"> <img draggable="false" title=":birthday:" alt="🎂" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f382.svg" class="emoji">'
```

##### `Twemoji.parse` options

##### `asset_root`

Default assets root url. Defaults to `https://twemoji.maxcdn.com/2/`:
Default assets root url. Defaults to `https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/`:

```ruby
> Twemoji.parse "I like chocolate :heart_eyes:!", asset_root: "foocdn.com"
Expand All @@ -166,7 +199,7 @@ Can change to `"png"`:

```ruby
> Twemoji.parse 'I like chocolate :heart_eyes:!', file_ext: "png"
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/2/72x72/1f60d.png" class="emoji">!'
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f60d.png" class="emoji">!'
```

##### `class_name`
Expand All @@ -175,7 +208,7 @@ Default image CSS class name. Defaults to `"emoji"`.

```ruby
> Twemoji.parse "I like chocolate :heart_eyes:!", class_name: "superemoji"
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/2/svg/1f60d.svg" class="superemoji">!'
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f60d.svg" class="superemoji">!'
```

##### `img_attrs`
Expand All @@ -184,7 +217,7 @@ List of image attributes for the `img` tag. Optional.

```ruby
> Twemoji.parse "I like chocolate :heart_eyes:!", class_name: "twemoji", img_attrs: { style: "height: 1.3em;" }
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/2/svg/1f60d.svg" class="twemoji" style="height: 1.3em;">!'
=> 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f60d.svg" class="twemoji" style="height: 1.3em;">!'
```

attribute value can apply proc-like object, remove `:` from title attribute:
Expand All @@ -193,7 +226,7 @@ attribute value can apply proc-like object, remove `:` from title attribute:
> no_colons = ->(name) { name.gsub(":", "") }

> Twemoji.parse "I like chocolate :heart_eyes:!", class_name: "twemoji", img_attrs: { title: no_colons }
=> 'I like chocolate <img draggable="false" title="heart_eyes" alt="😍" src="https://twemoji.maxcdn.com/2/svg/1f60d.svg" class="twemoji">!'
=> 'I like chocolate <img draggable="false" title="heart_eyes" alt="😍" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f60d.svg" class="twemoji">!'
```

#### `Twemoji.emoji_pattern`
Expand Down Expand Up @@ -257,7 +290,7 @@ end.to_json.html_safe %>

```ruby
Twemoji.configure do |config|
config.asset_root = "https://twemoji.maxcdn.com/2"
config.asset_root = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets"
config.file_ext = "svg"
config.class_name = "emoji"
config.img_attrs = {}
Expand Down
File renamed without changes.
32 changes: 16 additions & 16 deletions lib/twemoji.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ module Twemoji
# Find code by text, find text by code, and find text by unicode.
#
# @example Usage
# Twemoji.find_by(text: ":heart_eyes:") # => "1f60d"
# Twemoji.find_by(code: "1f60d") # => ":heart_eyes:"
# Twemoji.find_by(unicode: "😍") # => ":heart_eyes:"
# Twemoji.find_by(unicode: "\u{1f60d}") # => ":heart_eyes:"
# Twemoji.find_by(text: ":cookie:") # => "1f36a"
# Twemoji.find_by(code: "1f36a") # => ":cookie:"
# Twemoji.find_by(unicode: "🍪") # => ":cookie:"
# Twemoji.find_by(unicode: "\u{1f36a}") # => ":cookie:"
#
# @option options [String] (optional) :text
# @option options [String] (optional) :code
Expand All @@ -41,8 +41,8 @@ def self.find_by(text: nil, code: nil, unicode: nil)
# Find emoji code by emoji text.
#
# @example Usage
# Twemoji.find_by_text ":heart_eyes:"
# => "1f60d"
# Twemoji.find_by_text ":cookie:"
# => "1f36a"
#
# @param text [String] Text to find emoji code.
# @return [String] Emoji Code.
Expand All @@ -53,8 +53,8 @@ def self.find_by_text(text)
# Find emoji text by emoji code.
#
# @example Usage
# Twemoji.find_by_code "1f60d"
# => ":heart_eyes:"
# Twemoji.find_by_code "1f36a"
# => ":cookie:"
#
# @param code [String] Emoji code to find text.
# @return [String] Emoji Text.
Expand All @@ -65,8 +65,8 @@ def self.find_by_code(code)
# Find emoji text by raw emoji unicode.
#
# @example Usage
# Twemoji.find_by_unicode "😍"
# => ":heart_eyes:"
# Twemoji.find_by_unicode "🍪"
# => ":cookie:"
#
# @param raw [String] Emoji raw unicode to find text.
# @return [String] Emoji Text.
Expand All @@ -77,10 +77,10 @@ def self.find_by_unicode(raw)
# Render raw emoji unicode from emoji text or emoji code.
#
# @example Usage
# Twemoji.render_unicode ":heart_eyes:"
# => "😍"
# Twemoji.render_unicode "1f60d"
# => "😍"
# Twemoji.render_unicode ":cookie:"
# => "🍪"
# Twemoji.render_unicode "1f36a"
# => "🍪"
#
# @param text_or_code [String] Emoji text or code to render as unicode.
# @return [String] Emoji UTF-8 Text.
Expand All @@ -94,8 +94,8 @@ def self.render_unicode(text_or_code)
# Parse DOM, replace emoji with image.
#
# @example Usage
# Twemoji.parse("I like chocolate :heart_eyes:!")
# => 'I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/2/svg/1f60d.svg" class="emoji">!'
# Twemoji.parse("I like chocolate :cookie:!")
# => 'I like chocolate <img draggable="false" title=":cookie:" alt="🍪" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f36a.svg" class="emoji">!'
#
# @param text [String] Source text to parse.
#
Expand Down
3 changes: 2 additions & 1 deletion lib/twemoji/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class Configuration
CODE_MAP_FILE = File.join(DATA_DIR, "emoji-unicode.yml")
PNG_MAP_FILE = File.join(DATA_DIR, "emoji-unicode-png.yml")
SVG_MAP_FILE = File.join(DATA_DIR, "emoji-unicode-svg.yml")
DEFAULT_ASSET_ROOT = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets"

attr_accessor :asset_root, :file_ext, :class_name, :img_attrs

def initialize
@asset_root = "https://twemoji.maxcdn.com/2"
@asset_root = DEFAULT_ASSET_ROOT
@file_ext = "svg"
@class_name = "emoji"
@img_attrs = {}
Expand Down
Loading