2016-04-16 15:09:08 -04:00
|
|
|
module Gitlab
|
|
|
|
class AwardEmoji
|
|
|
|
CATEGORIES = {
|
|
|
|
objects: "Objects",
|
2016-07-13 10:43:42 -04:00
|
|
|
travel: "Travel",
|
|
|
|
symbols: "Symbols",
|
2016-04-16 15:09:08 -04:00
|
|
|
nature: "Nature",
|
|
|
|
people: "People",
|
|
|
|
activity: "Activity",
|
|
|
|
flags: "Flags",
|
2016-07-13 10:43:42 -04:00
|
|
|
food: "Food"
|
2016-04-16 15:09:08 -04:00
|
|
|
}.with_indifferent_access
|
|
|
|
|
|
|
|
def self.normalize_emoji_name(name)
|
|
|
|
aliases[name] || name
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.emoji_by_category
|
|
|
|
unless @emoji_by_category
|
|
|
|
@emoji_by_category = Hash.new { |h, key| h[key] = [] }
|
|
|
|
|
|
|
|
emojis.each do |emoji_name, data|
|
|
|
|
data["name"] = emoji_name
|
|
|
|
|
|
|
|
# Skip Fitzpatrick(tone) modifiers
|
|
|
|
next if data["category"] == "modifier"
|
|
|
|
|
2016-07-13 10:43:42 -04:00
|
|
|
category = data["category"]
|
2016-04-16 15:09:08 -04:00
|
|
|
|
|
|
|
@emoji_by_category[category] << data
|
|
|
|
end
|
|
|
|
|
|
|
|
@emoji_by_category = @emoji_by_category.sort.to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
@emoji_by_category
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.emojis
|
2016-06-01 05:23:09 -04:00
|
|
|
@emojis ||=
|
|
|
|
begin
|
|
|
|
json_path = File.join(Rails.root, 'fixtures', 'emojis', 'index.json' )
|
|
|
|
JSON.parse(File.read(json_path))
|
|
|
|
end
|
2016-04-16 15:09:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.aliases
|
2016-06-01 05:23:09 -04:00
|
|
|
@aliases ||=
|
|
|
|
begin
|
2016-07-13 10:43:42 -04:00
|
|
|
json_path = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json')
|
|
|
|
JSON.parse(File.read(json_path))
|
|
|
|
end
|
2016-04-16 15:09:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Returns an Array of Emoji names and their asset URLs.
|
|
|
|
def self.urls
|
|
|
|
@urls ||= begin
|
|
|
|
path = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json')
|
2016-06-30 15:12:16 -04:00
|
|
|
# Construct the full asset path ourselves because
|
|
|
|
# ActionView::Helpers::AssetUrlHelper.asset_url is slow for hundreds
|
|
|
|
# of entries since it has to do a lot of extra work (e.g. regexps).
|
2016-04-16 15:09:08 -04:00
|
|
|
prefix = Gitlab::Application.config.assets.prefix
|
|
|
|
digest = Gitlab::Application.config.assets.digest
|
2016-06-30 15:12:16 -04:00
|
|
|
base =
|
|
|
|
if defined?(Gitlab::Application.config.relative_url_root) && Gitlab::Application.config.relative_url_root
|
|
|
|
Gitlab::Application.config.relative_url_root
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
2016-04-16 15:09:08 -04:00
|
|
|
|
|
|
|
JSON.parse(File.read(path)).map do |hash|
|
|
|
|
if digest
|
|
|
|
fname = "#{hash['unicode']}-#{hash['digest']}"
|
|
|
|
else
|
|
|
|
fname = hash['unicode']
|
|
|
|
end
|
|
|
|
|
2016-06-30 15:12:16 -04:00
|
|
|
{ name: hash['name'], path: File.join(base, prefix, "#{fname}.png") }
|
2016-04-16 15:09:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|