gitlab-org--gitlab-foss/lib/gitlab/emoji.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

module Gitlab
module Emoji
extend self
def emojis
Gemojione.index.instance_variable_get(:@emoji_by_name)
end
def emojis_by_moji
Gemojione.index.instance_variable_get(:@emoji_by_moji)
end
2016-10-11 10:27:09 -04:00
2016-10-11 09:41:10 -04:00
def emojis_unicodes
2016-10-11 10:27:09 -04:00
emojis_by_moji.keys
2016-10-11 09:41:10 -04:00
end
2016-10-11 10:27:09 -04:00
def emojis_names
2016-10-11 10:27:09 -04:00
emojis.keys
end
def emojis_aliases
2017-03-06 12:59:26 -05:00
@emoji_aliases ||= JSON.parse(File.read(Rails.root.join('fixtures', 'emojis', 'aliases.json')))
end
def emoji_filename(name)
emojis[name]["unicode"]
end
2016-10-11 10:27:09 -04:00
2016-10-11 09:41:10 -04:00
def emoji_unicode_filename(moji)
emojis_by_moji[moji]["unicode"]
end
def emoji_unicode_version(name)
@emoji_unicode_versions_by_name ||= JSON.parse(File.read(Rails.root.join('fixtures', 'emojis', 'emoji-unicode-version-map.json')))
2017-03-06 12:59:26 -05:00
@emoji_unicode_versions_by_name[name]
end
def normalize_emoji_name(name)
emojis_aliases[name] || name
end
def emoji_image_tag(name, src)
"<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{src}' height='20' width='20' align='absmiddle' />"
end
# CSS sprite fallback takes precedence over image fallback
def gl_emoji_tag(name)
emoji_name = emojis_aliases[name] || name
emoji_info = emojis[emoji_name]
return unless emoji_info
2017-03-06 12:59:26 -05:00
data = {
name: emoji_name,
unicode_version: emoji_unicode_version(emoji_name)
}
ActionController::Base.helpers.content_tag('gl-emoji', emoji_info['moji'], data: data)
end
end
end