Fixes emoji name to code missing tones

This commit is contained in:
Joffrey JAFFEUX 2017-06-13 20:03:59 +02:00 committed by Robin Ward
parent 13f89a53a3
commit 299339a373
3 changed files with 27 additions and 2 deletions

View File

@ -220,7 +220,7 @@ module ApplicationHelper
def gsub_emoji_to_unicode(str)
if str
str.gsub(/:([\w\-+]*):/) { |name| Emoji.lookup_unicode($1) || name }
str.gsub(/:([\w\-+]*(?::t\d)?):/) { |name| Emoji.lookup_unicode($1) || name }
end
end

View File

@ -2,6 +2,8 @@ class Emoji
# update this to clear the cache
EMOJI_VERSION = "v5"
FITZPATRICK_SCALE ||= [ "1f3fb", "1f3fc", "1f3fd", "1f3fe", "1f3ff" ]
include ActiveModel::SerializerSupport
attr_reader :path
@ -147,8 +149,17 @@ class Emoji
db['emojis'].each do |e|
next if e['name'] == 'tm'
code = replacement_code(e['code'])
map[e['name']] = code if code
next unless code
map[e['name']] = code
if Emoji.tonable_emojis.include?(e['name'])
FITZPATRICK_SCALE.each_with_index do |scale, index|
toned_code = (code.codepoints.insert(1, scale.to_i(16))).pack("U*")
map["#{e['name']}:t#{index+2}"] = toned_code
end
end
end
Emoji.aliases.each do |key, alias_names|

View File

@ -28,4 +28,18 @@ describe Emoji do
end
end
describe '.lookup_unicode' do
it 'should return the emoji' do
expect(Emoji.lookup_unicode("blonde_man")).to eq("👱")
end
it 'should return an aliased emoji' do
expect(Emoji.lookup_unicode("anger_right")).to eq("🗯")
end
it 'should return a skin toned emoji' do
expect(Emoji.lookup_unicode("blonde_woman:t6")).to eq("👱🏿‍♀️")
end
end
end