Commit 52be0404 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Refactor codebase to use unicode_version from TanukiEmoji

parent 1a1c5adb
......@@ -16,7 +16,7 @@ class AwardEmojiPresenter < Gitlab::View::Presenter::Delegated
end
def unicode_version
Gitlab::Emoji.emoji_unicode_version(award_emoji.name)
as_emoji&.unicode_version
end
private
......
This diff is collapsed.
......@@ -24,10 +24,6 @@ module Gitlab
TanukiEmoji.find_by_codepoints(moji).image_name
end
def emoji_unicode_version(name)
emoji_unicode_versions_by_name[name]
end
def normalize_emoji_name(name)
emojis_aliases[name] || name
end
......@@ -58,7 +54,7 @@ module Gitlab
data = {
name: emoji.name,
unicode_version: emoji_unicode_version(emoji.name)
unicode_version: emoji.unicode_version
}
options = { title: emoji.description, data: data }.merge(options)
......@@ -74,12 +70,5 @@ module Gitlab
emoji_image_tag(name, image_source).html_safe
end
end
private
def emoji_unicode_versions_by_name
@emoji_unicode_versions_by_name ||=
Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'emoji-unicode-version-map.json')))
end
end
end
......@@ -3,7 +3,7 @@
namespace :tanuki_emoji do
desc 'Generates Emoji SHA256 digests'
task aliases: %w[environment] do
task aliases: :environment do
aliases = {}
TanukiEmoji.index.all.each do |emoji|
......@@ -18,12 +18,8 @@ namespace :tanuki_emoji do
end
end
task digests: ['yarn:check', 'environment'] do
task digests: :environment do
require 'digest/sha2'
require 'json'
# We don't have `node_modules` available in built versions of GitLab
FileUtils.cp_r(Rails.root.join('node_modules', 'emoji-unicode-version', 'emoji-unicode-version-map.json'), File.join(Rails.root, 'fixtures', 'emojis'))
digest_emoji_map = {}
emojis_map = {}
......@@ -35,7 +31,7 @@ namespace :tanuki_emoji do
category: emoji.category,
moji: emoji.codepoints,
description: emoji.description,
unicodeVersion: Gitlab::Emoji.emoji_unicode_version(emoji.name),
unicodeVersion: emoji.unicode_version,
digest: Digest::SHA256.file(emoji_path).hexdigest
}
......@@ -46,7 +42,7 @@ namespace :tanuki_emoji do
c: emoji.category,
e: emoji.codepoints,
d: emoji.description,
u: Gitlab::Emoji.emoji_unicode_version(emoji.name)
u: emoji.unicode_version
}
emojis_map[emoji.name] = emoji_entry
......@@ -71,7 +67,10 @@ namespace :tanuki_emoji do
# occasionally, such as when new Emojis are added to Gemojione.
task sprite: :environment do
begin
require 'mini_magick'
require 'sprite_factory'
# Sprite-Factory still requires rmagick, but maybe could be migrated to support minimagick
# Upstream issue: https://github.com/jakesgordon/sprite-factory/issues/47#issuecomment-929302890
require 'rmagick'
rescue LoadError
# noop
......@@ -94,7 +93,7 @@ namespace :tanuki_emoji do
TanukiEmoji.index.all.each do |emoji|
source = File.join(TanukiEmoji.images_path, emoji.image_name)
destination = File.join(emoji_dir, TanukiEmoji.name, '.png')
destination = File.join(emoji_dir, "#{emoji.name}.png")
FileUtils.cp(source, destination)
end
......@@ -179,7 +178,7 @@ namespace :tanuki_emoji do
end
def check_requirements!
return if defined?(SpriteFactory) && defined?(Magick)
return if defined?(Magick)
puts <<-MSG.strip_heredoc
This task is disabled by default and should only be run when the TanukiEmoji
......@@ -188,8 +187,12 @@ namespace :tanuki_emoji do
To enable this task, *temporarily* add the following lines to Gemfile and
re-bundle:
gem 'sprite-factory'
gem 'rmagick'
gem 'rmagick', '~> 3.2'
It depends on ImageMagick 6, which can be installed via HomeBrew with:
brew unlink imagemagick
brew install imagemagick@6 && brew link imagemagick@6 --force
MSG
exit 1
......@@ -197,9 +200,9 @@ namespace :tanuki_emoji do
def resize!(image_path, size)
# Resize the image in-place, save it, and free the object
image = Magick::Image.read(image_path).first
image.resize!(size, size)
image.write(image_path) { self.quality = 100 }
image.destroy!
image = MiniMagick::Image.open(image_path)
image.quality(100)
image.resize("#{size}x#{size}")
image.write(image_path)
end
end
......@@ -6,6 +6,7 @@ RSpec.describe EmojiHelper do
describe '#emoji_icon' do
let(:options) { {} }
let(:emoji_text) { 'rocket' }
let(:emoji_version) { '6.0' }
let(:aria_hidden_option) { "aria-hidden=\"true\"" }
subject { helper.emoji_icon(emoji_text, options) }
......@@ -14,7 +15,7 @@ RSpec.describe EmojiHelper do
is_expected.to include('<gl-emoji',
"title=\"#{emoji_text}\"",
"data-name=\"#{emoji_text}\"",
"data-unicode-version=\"#{::Gitlab::Emoji.emoji_unicode_version(emoji_text)}\"")
"data-unicode-version=\"#{emoji_version}\"")
is_expected.not_to include(aria_hidden_option)
end
......@@ -25,7 +26,7 @@ RSpec.describe EmojiHelper do
is_expected.to include('<gl-emoji',
"title=\"#{emoji_text}\"",
"data-name=\"#{emoji_text}\"",
"data-unicode-version=\"#{::Gitlab::Emoji.emoji_unicode_version(emoji_text)}\"",
"data-unicode-version=\"#{emoji_version}\"",
aria_hidden_option)
end
end
......
......@@ -4,7 +4,6 @@ require 'spec_helper'
RSpec.describe Gitlab::Emoji do
let_it_be(:emojis_by_moji) { TanukiEmoji.index.all.index_by(&:codepoints) }
let_it_be(:emoji_unicode_versions_by_name) { Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'emoji-unicode-version-map.json'))) }
let_it_be(:emojis_aliases) { Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'aliases.json'))) }
describe '.emojis_aliases' do
......@@ -32,14 +31,6 @@ RSpec.describe Gitlab::Emoji do
end
end
describe '.emoji_unicode_version' do
it 'returns emoji unicode version by name' do
emoji_unicode_version = described_class.emoji_unicode_version('100')
expect(emoji_unicode_version).to eq(emoji_unicode_versions_by_name['100'])
end
end
describe '.normalize_emoji_name' do
it 'returns same name if not found in aliases' do
emoji_name = described_class.normalize_emoji_name('random')
......
......@@ -17,7 +17,7 @@ RSpec.describe AwardEmojiPresenter do
end
describe '#unicode_version' do
it { expect(presenter.unicode_version).to eq Gitlab::Emoji.emoji_unicode_version(emoji_name) }
it { expect(presenter.unicode_version).to eq('6.0') }
end
describe '#emoji' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment