debian-mirror-gitlab/lib/gitlab/emoji.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
module Gitlab
module Emoji
extend self
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
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-11-03 12:29:30 +05:30
def emojis_unicodes
emojis_by_moji.keys
end
2016-08-24 12:49:21 +05:30
def emojis_names
2016-11-03 12:29:30 +05:30
emojis.keys
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
def emojis_aliases
@emoji_aliases ||= JSON.parse(File.read(Rails.root.join('fixtures', 'emojis', 'aliases.json')))
end
2016-08-24 12:49:21 +05:30
def emoji_filename(name)
emojis[name]["unicode"]
end
2016-11-03 12:29:30 +05:30
def emoji_unicode_filename(moji)
emojis_by_moji[moji]["unicode"]
end
2017-08-17 22:00:37 +05:30
def emoji_unicode_version(name)
@emoji_unicode_versions_by_name ||= JSON.parse(File.read(Rails.root.join('fixtures', 'emojis', 'emoji-unicode-version-map.json')))
@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
data = {
name: emoji_name,
unicode_version: emoji_unicode_version(emoji_name)
}
ActionController::Base.helpers.content_tag('gl-emoji', emoji_info['moji'], title: emoji_info['description'], data: data)
end
2016-08-24 12:49:21 +05:30
end
end