2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-25 17:48:12 -04:00
|
|
|
module Gitlab
|
|
|
|
module Emoji
|
|
|
|
extend self
|
2017-02-27 23:44:34 -05:00
|
|
|
|
2021-10-19 17:12:08 -04:00
|
|
|
# When updating emoji assets increase the version below
|
|
|
|
# and update the version number in `app/assets/javascripts/emoji/index.js`
|
2021-12-15 16:11:32 -05:00
|
|
|
EMOJI_VERSION = 2
|
2017-03-06 12:59:26 -05:00
|
|
|
|
2021-10-19 17:12:08 -04:00
|
|
|
# Return a Pathname to emoji's current versioned folder
|
|
|
|
#
|
|
|
|
# @return [Pathname] Absolute Path to versioned emojis folder in `public`
|
|
|
|
def emoji_public_absolute_path
|
|
|
|
Rails.root.join("public/-/emojis/#{EMOJI_VERSION}")
|
2017-02-27 23:44:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def emoji_image_tag(name, src)
|
2021-06-07 08:10:00 -04:00
|
|
|
image_options = {
|
2022-08-23 11:09:40 -04:00
|
|
|
class: 'emoji',
|
|
|
|
src: src,
|
|
|
|
title: ":#{name}:",
|
|
|
|
alt: ":#{name}:",
|
2021-06-07 08:10:00 -04:00
|
|
|
height: 20,
|
2022-08-23 11:09:40 -04:00
|
|
|
width: 20,
|
|
|
|
align: 'absmiddle'
|
2021-06-07 08:10:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionController::Base.helpers.tag(:img, image_options)
|
2017-02-27 23:44:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# CSS sprite fallback takes precedence over image fallback
|
2021-10-19 17:12:08 -04:00
|
|
|
# @param [TanukiEmoji::Character] emoji
|
|
|
|
# @param [Hash] options
|
|
|
|
def gl_emoji_tag(emoji, options = {})
|
|
|
|
return unless emoji
|
2017-03-06 12:59:26 -05:00
|
|
|
|
|
|
|
data = {
|
2021-10-19 17:12:08 -04:00
|
|
|
name: emoji.name,
|
|
|
|
unicode_version: emoji.unicode_version
|
2017-03-06 12:59:26 -05:00
|
|
|
}
|
2021-10-19 17:12:08 -04:00
|
|
|
options = { title: emoji.description, data: data }.merge(options)
|
2017-03-16 06:03:35 -04:00
|
|
|
|
2021-10-19 17:12:08 -04:00
|
|
|
ActionController::Base.helpers.content_tag('gl-emoji', emoji.codepoints, options)
|
2017-02-27 23:44:34 -05:00
|
|
|
end
|
2017-09-18 13:25:23 -04:00
|
|
|
|
2021-02-05 10:09:28 -05:00
|
|
|
def custom_emoji_tag(name, image_source)
|
|
|
|
data = {
|
2022-04-02 08:08:25 -04:00
|
|
|
name: name,
|
|
|
|
fallback_src: image_source,
|
|
|
|
unicode_version: 'custom' # Prevents frontend to check for Unicode support
|
2021-02-05 10:09:28 -05:00
|
|
|
}
|
2022-04-02 08:08:25 -04:00
|
|
|
options = { title: name, data: data }
|
2021-02-05 10:09:28 -05:00
|
|
|
|
2022-04-02 08:08:25 -04:00
|
|
|
ActionController::Base.helpers.content_tag('gl-emoji', "", options)
|
2021-02-05 10:09:28 -05:00
|
|
|
end
|
2016-06-25 17:48:12 -04:00
|
|
|
end
|
|
|
|
end
|