Compare commits
35 Commits
v4.0.0.rc1
...
v4.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed57eb86fd | ||
|
|
33caddce20 | ||
|
|
ac35c33c44 | ||
|
|
70eb18cf81 | ||
|
|
d04fd7701e | ||
|
|
744495f776 | ||
|
|
ea4d73899a | ||
|
|
d7ca116556 | ||
|
|
f7a6bb68c0 | ||
|
|
a8d55fd539 | ||
|
|
5f3415f5fe | ||
|
|
9917299963 | ||
|
|
e13ac61ebd | ||
|
|
6af51fcecd | ||
|
|
a166a06499 | ||
|
|
44c22eac93 | ||
|
|
1c3519c6bb | ||
|
|
55bb37afa4 | ||
|
|
64cd0e9ccf | ||
|
|
0f2f9ce047 | ||
|
|
b1c7878afe | ||
|
|
ce6c4ab12a | ||
|
|
4c47a26900 | ||
|
|
2a97e7e98c | ||
|
|
f6fa963350 | ||
|
|
2eb30abcd1 | ||
|
|
59ef859169 | ||
|
|
be99618db3 | ||
|
|
3675a8781f | ||
|
|
7f6550fe73 | ||
|
|
5361b5639f | ||
|
|
955be747f2 | ||
|
|
d98617abf2 | ||
|
|
bf598c57fc | ||
|
|
a5865153a2 |
24
.github/workflows/test.yml
vendored
Normal file
24
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
name: Test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
ruby: ["2.7", "3.0", "3.1"]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: ${{matrix.ruby}}
|
||||
bundler-cache: true
|
||||
|
||||
- name: Run tests
|
||||
run: bundle exec rake
|
||||
12
.travis.yml
12
.travis.yml
@@ -1,12 +0,0 @@
|
||||
sudo: false
|
||||
script: script/test
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- '2.1'
|
||||
- '2.2'
|
||||
- '2.3'
|
||||
- '2.4'
|
||||
- '2.5'
|
||||
- '2.6'
|
||||
notifications:
|
||||
email: false
|
||||
1
Gemfile
1
Gemfile
@@ -2,5 +2,6 @@ source "https://rubygems.org"
|
||||
|
||||
gem "rake", "~> 10.3.2"
|
||||
gem "minitest", "~> 5.3.5"
|
||||
gem "i18n", "~> 1.8.5"
|
||||
|
||||
gemspec
|
||||
|
||||
25
Gemfile.lock
Normal file
25
Gemfile.lock
Normal file
@@ -0,0 +1,25 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
gemoji (4.0.1)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
concurrent-ruby (1.1.7)
|
||||
i18n (1.8.5)
|
||||
concurrent-ruby (~> 1.0)
|
||||
minitest (5.3.5)
|
||||
rake (10.3.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
gemoji!
|
||||
i18n (~> 1.8.5)
|
||||
minitest (~> 5.3.5)
|
||||
rake (~> 10.3.2)
|
||||
|
||||
BUNDLED WITH
|
||||
2.0.2
|
||||
2
Rakefile
2
Rakefile
@@ -20,5 +20,5 @@ namespace :db do
|
||||
end
|
||||
|
||||
file 'vendor/unicode-emoji-test.txt' do |t|
|
||||
system 'curl', '-fsSL', 'http://unicode.org/Public/emoji/12.1/emoji-test.txt', '-o', t.name
|
||||
system 'curl', '-fsSL', 'http://unicode.org/Public/emoji/14.0/emoji-test.txt', '-o', t.name
|
||||
end
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "i18n"
|
||||
require 'emoji'
|
||||
require 'json'
|
||||
require_relative './emoji-test-parser'
|
||||
|
||||
I18n.config.available_locales = :en
|
||||
items = []
|
||||
|
||||
_, categories = EmojiTestParser.parse(File.expand_path("../../vendor/unicode-emoji-test.txt", __FILE__))
|
||||
@@ -34,10 +36,10 @@ for category in categories
|
||||
)
|
||||
else
|
||||
output_item.update(
|
||||
aliases: [description.gsub(/\W+/, '_').downcase],
|
||||
aliases: [I18n.transliterate(description).gsub(/\W+/, '_').downcase],
|
||||
tags: [],
|
||||
unicode_version: "12.1",
|
||||
ios_version: "13.2",
|
||||
unicode_version: "14.0",
|
||||
ios_version: "15.4",
|
||||
)
|
||||
end
|
||||
output_item[:skin_tones] = true if emoji_item[:skin_tones]
|
||||
|
||||
1748
db/emoji.json
1748
db/emoji.json
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "gemoji"
|
||||
s.version = "4.0.0.rc1"
|
||||
s.version = "4.0.1"
|
||||
s.summary = "Unicode emoji library"
|
||||
s.description = "Character information and metadata for Unicode emoji."
|
||||
|
||||
|
||||
@@ -51,11 +51,12 @@ module Emoji
|
||||
|
||||
# Public: Find an emoji by its unicode character. Return nil if missing.
|
||||
def find_by_unicode(unicode)
|
||||
unicodes_index[unicode]
|
||||
unicodes_index[unicode] || unicodes_index[unicode.sub(SKIN_TONE_RE, "")]
|
||||
end
|
||||
|
||||
private
|
||||
VARIATION_SELECTOR_16 = "\u{fe0f}".freeze
|
||||
SKIN_TONE_RE = /[\u{1F3FB}-\u{1F3FF}]/
|
||||
|
||||
# Characters which must have VARIATION_SELECTOR_16 to render as color emoji:
|
||||
TEXT_GLYPHS = [
|
||||
@@ -70,7 +71,7 @@ module Emoji
|
||||
"\u{3030}", # wavy dash
|
||||
].freeze
|
||||
|
||||
private_constant :VARIATION_SELECTOR_16, :TEXT_GLYPHS
|
||||
private_constant :VARIATION_SELECTOR_16, :TEXT_GLYPHS, :SKIN_TONE_RE
|
||||
|
||||
def parse_data_file
|
||||
data = File.open(data_file, 'r:UTF-8') do |file|
|
||||
@@ -118,6 +119,7 @@ module Emoji
|
||||
emoji.description = dedup.call(raw_emoji[:description])
|
||||
emoji.unicode_version = dedup.call(raw_emoji[:unicode_version])
|
||||
emoji.ios_version = dedup.call(raw_emoji[:ios_version])
|
||||
emoji.skin_tones = raw_emoji.fetch(:skin_tones, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,6 +11,11 @@ module Emoji
|
||||
# True if the emoji is not a standard Emoji character.
|
||||
def custom?() !raw end
|
||||
|
||||
# True if the emoji supports Fitzpatrick scale skin tone modifiers
|
||||
def skin_tones?() @skin_tones end
|
||||
|
||||
attr_writer :skin_tones
|
||||
|
||||
# A list of names uniquely referring to this emoji.
|
||||
attr_reader :aliases
|
||||
|
||||
@@ -38,6 +43,21 @@ module Emoji
|
||||
# Raw Unicode string for an emoji. Nil if emoji is non-standard.
|
||||
def raw() unicode_aliases.first end
|
||||
|
||||
# Raw Unicode strings for each skin tone variant of this emoji.
|
||||
def raw_skin_tone_variants
|
||||
return [] if custom? || !skin_tones?
|
||||
raw_normalized = raw.sub("\u{fe0f}", "") # strip VARIATION_SELECTOR_16
|
||||
idx = raw_normalized.index("\u{200d}") # detect zero-width joiner
|
||||
SKIN_TONES.map do |modifier|
|
||||
if idx
|
||||
# insert modifier before zero-width joiner
|
||||
raw_normalized[0...idx] + modifier + raw_normalized[idx..nil]
|
||||
else
|
||||
raw_normalized + modifier
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_unicode_alias(str)
|
||||
unicode_aliases << str
|
||||
end
|
||||
@@ -54,6 +74,7 @@ module Emoji
|
||||
@aliases = Array(name)
|
||||
@unicode_aliases = []
|
||||
@tags = []
|
||||
@skin_tones = false
|
||||
end
|
||||
|
||||
def inspect
|
||||
@@ -76,6 +97,16 @@ module Emoji
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
SKIN_TONES = [
|
||||
"\u{1F3FB}", # light skin tone
|
||||
"\u{1F3FC}", # medium-light skin tone
|
||||
"\u{1F3FD}", # medium skin tone
|
||||
"\u{1F3FE}", # medium-dark skin tone
|
||||
"\u{1F3FF}", # dark skin tone
|
||||
]
|
||||
|
||||
private_constant :SKIN_TONES
|
||||
|
||||
def default_image_filename
|
||||
if custom?
|
||||
|
||||
@@ -50,14 +50,19 @@ class EmojiTest < TestCase
|
||||
GENDER_EXCEPTIONS = [
|
||||
"man_with_gua_pi_mao",
|
||||
"woman_with_headscarf",
|
||||
"man_in_tuxedo",
|
||||
"pregnant_woman",
|
||||
"isle_of_man",
|
||||
"blonde_woman",
|
||||
"blonde_woman", # blond_haired_man
|
||||
/^couple(kiss)?_/,
|
||||
/^family_/,
|
||||
]
|
||||
|
||||
DASH_EXCEPTIONS = [
|
||||
"-1",
|
||||
"t-rex",
|
||||
"e-mail",
|
||||
"non-potable_water",
|
||||
]
|
||||
|
||||
test "emojis have valid names" do
|
||||
aliases = Emoji.all.flat_map(&:aliases)
|
||||
|
||||
@@ -76,7 +81,7 @@ class EmojiTest < TestCase
|
||||
alias_count = Hash.new(0)
|
||||
aliases.each do |name|
|
||||
alias_count[name] += 1
|
||||
invalid << name if name !~ /\A[\w+-]+\Z/
|
||||
invalid << name if name !~ /\A[\w+]+\Z/ && !DASH_EXCEPTIONS.include?(name)
|
||||
another_gender = to_another_gender.call(name)
|
||||
gender_mismatch << another_gender unless aliases.include?(another_gender)
|
||||
end
|
||||
@@ -91,7 +96,6 @@ class EmojiTest < TestCase
|
||||
test "missing or incorrect unicodes" do
|
||||
emoji_map, _ = EmojiTestParser.parse(File.expand_path("../../vendor/unicode-emoji-test.txt", __FILE__))
|
||||
source_unicode_emoji = emoji_map.values
|
||||
supported_sequences = Emoji.all.flat_map(&:unicode_aliases)
|
||||
text_glyphs = Emoji.const_get(:TEXT_GLYPHS)
|
||||
|
||||
missing = 0
|
||||
@@ -153,6 +157,27 @@ class EmojiTest < TestCase
|
||||
assert_equal '8.3', emoji.ios_version
|
||||
end
|
||||
|
||||
test "skin tones" do
|
||||
smiley = Emoji.find_by_alias("smiley")
|
||||
assert_equal false, smiley.skin_tones?
|
||||
assert_equal [], smiley.raw_skin_tone_variants
|
||||
|
||||
wave = Emoji.find_by_alias("wave")
|
||||
assert_equal true, wave.skin_tones?
|
||||
|
||||
wave = Emoji.find_by_unicode("\u{1f44b}\u{1f3ff}") # wave + dark skin tone
|
||||
assert_equal "wave", wave.name
|
||||
|
||||
woman_with_beard = Emoji.find_by_unicode("\u{1f9d4}\u{200d}\u{2640}\u{fe0f}")
|
||||
assert_equal [
|
||||
"1f9d4-1f3fb-200d-2640",
|
||||
"1f9d4-1f3fc-200d-2640",
|
||||
"1f9d4-1f3fd-200d-2640",
|
||||
"1f9d4-1f3fe-200d-2640",
|
||||
"1f9d4-1f3ff-200d-2640",
|
||||
], woman_with_beard.raw_skin_tone_variants.map { |u| Emoji::Character.hex_inspect(u) }
|
||||
end
|
||||
|
||||
test "no custom emojis" do
|
||||
custom = Emoji.all.select(&:custom?)
|
||||
assert 0, custom.size
|
||||
|
||||
8778
vendor/unicode-emoji-test.txt
vendored
8778
vendor/unicode-emoji-test.txt
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user