Fixes emoji name to code missing tones
This commit is contained in:
parent
13f89a53a3
commit
299339a373
|
@ -220,7 +220,7 @@ module ApplicationHelper
|
||||||
|
|
||||||
def gsub_emoji_to_unicode(str)
|
def gsub_emoji_to_unicode(str)
|
||||||
if 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ class Emoji
|
||||||
# update this to clear the cache
|
# update this to clear the cache
|
||||||
EMOJI_VERSION = "v5"
|
EMOJI_VERSION = "v5"
|
||||||
|
|
||||||
|
FITZPATRICK_SCALE ||= [ "1f3fb", "1f3fc", "1f3fd", "1f3fe", "1f3ff" ]
|
||||||
|
|
||||||
include ActiveModel::SerializerSupport
|
include ActiveModel::SerializerSupport
|
||||||
|
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
|
@ -147,8 +149,17 @@ class Emoji
|
||||||
|
|
||||||
db['emojis'].each do |e|
|
db['emojis'].each do |e|
|
||||||
next if e['name'] == 'tm'
|
next if e['name'] == 'tm'
|
||||||
|
|
||||||
code = replacement_code(e['code'])
|
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
|
end
|
||||||
|
|
||||||
Emoji.aliases.each do |key, alias_names|
|
Emoji.aliases.each do |key, alias_names|
|
||||||
|
|
|
@ -28,4 +28,18 @@ describe Emoji do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue