2015-11-18 10:38:15 -05:00
|
|
|
class AwardEmoji
|
2015-12-17 07:29:55 -05:00
|
|
|
CATEGORIES = {
|
|
|
|
other: "Other",
|
|
|
|
objects: "Objects",
|
|
|
|
places: "Places",
|
|
|
|
travel_places: "Travel",
|
|
|
|
emoticons: "Emoticons",
|
|
|
|
objects_symbols: "Symbols",
|
|
|
|
nature: "Nature",
|
|
|
|
celebration: "Celebration",
|
|
|
|
people: "People",
|
|
|
|
activity: "Activity",
|
|
|
|
flags: "Flags",
|
|
|
|
food_drink: "Food"
|
|
|
|
}.with_indifferent_access
|
|
|
|
|
2016-04-14 12:38:17 -04:00
|
|
|
CATEGORY_ALIASES = {
|
|
|
|
symbols: "objects_symbols",
|
|
|
|
foods: "food_drink",
|
|
|
|
travel: "travel_places"
|
|
|
|
}.with_indifferent_access
|
|
|
|
|
2015-12-11 06:10:00 -05:00
|
|
|
def self.normilize_emoji_name(name)
|
2015-12-24 04:28:51 -05:00
|
|
|
aliases[name] || name
|
2015-12-11 06:10:00 -05:00
|
|
|
end
|
2015-12-17 07:29:55 -05:00
|
|
|
|
|
|
|
def self.emoji_by_category
|
|
|
|
unless @emoji_by_category
|
2016-04-14 12:38:17 -04:00
|
|
|
@emoji_by_category = Hash.new { |h, key| h[key] = [] }
|
2015-12-17 07:29:55 -05:00
|
|
|
|
2015-12-24 04:28:51 -05:00
|
|
|
emojis.each do |emoji_name, data|
|
|
|
|
data["name"] = emoji_name
|
2015-12-17 07:29:55 -05:00
|
|
|
|
2016-04-14 12:38:17 -04:00
|
|
|
# Skip Fitzpatrick(tone) modifiers
|
|
|
|
next if data["category"] == "modifier"
|
|
|
|
|
|
|
|
category = CATEGORY_ALIASES[data["category"]] || data["category"]
|
|
|
|
|
|
|
|
@emoji_by_category[category] << data
|
2015-12-17 07:29:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
@emoji_by_category = @emoji_by_category.sort.to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
@emoji_by_category
|
|
|
|
end
|
2015-12-24 04:28:51 -05:00
|
|
|
|
|
|
|
def self.emojis
|
|
|
|
@emojis ||= begin
|
|
|
|
json_path = File.join(Rails.root, 'fixtures', 'emojis', 'index.json' )
|
|
|
|
JSON.parse(File.read(json_path))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-22 12:01:53 -04:00
|
|
|
def self.unicode
|
2016-04-22 16:53:26 -04:00
|
|
|
@unicode ||= emojis.map {|key, value| { key => emojis[key]["unicode"] } }.inject(:merge!)
|
2016-04-22 12:01:53 -04:00
|
|
|
end
|
|
|
|
|
2015-12-24 04:28:51 -05:00
|
|
|
def self.aliases
|
|
|
|
@aliases ||= begin
|
|
|
|
json_path = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json' )
|
|
|
|
JSON.parse(File.read(json_path))
|
|
|
|
end
|
|
|
|
end
|
2016-03-30 13:29:17 -04:00
|
|
|
|
|
|
|
# Returns an Array of Emoji names and their asset URLs.
|
|
|
|
def self.urls
|
|
|
|
@urls ||= begin
|
|
|
|
path = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json')
|
|
|
|
prefix = Gitlab::Application.config.assets.prefix
|
|
|
|
digest = Gitlab::Application.config.assets.digest
|
|
|
|
|
|
|
|
JSON.parse(File.read(path)).map do |hash|
|
|
|
|
if digest
|
|
|
|
fname = "#{hash['unicode']}-#{hash['digest']}"
|
|
|
|
else
|
|
|
|
fname = hash['unicode']
|
|
|
|
end
|
|
|
|
|
|
|
|
{ name: hash['name'], path: "#{prefix}/#{fname}.png" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-11-18 18:31:15 -05:00
|
|
|
end
|