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

59 lines
1.6 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
module Gitlab
module Emoji
extend self
2017-08-17 22:00:37 +05:30
2021-12-11 22:18:48 +05:30
# When updating emoji assets increase the version below
# and update the version number in `app/assets/javascripts/emoji/index.js`
2022-01-26 12:08:38 +05:30
EMOJI_VERSION = 2
2017-08-17 22:00:37 +05:30
2021-12-11 22:18:48 +05:30
# 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-08-17 22:00:37 +05:30
end
def emoji_image_tag(name, src)
2021-09-04 01:27:46 +05:30
image_options = {
class: 'emoji',
src: src,
title: ":#{name}:",
alt: ":#{name}:",
height: 20,
width: 20,
align: 'absmiddle'
}
ActionController::Base.helpers.tag(:img, image_options)
2017-08-17 22:00:37 +05:30
end
# CSS sprite fallback takes precedence over image fallback
2021-12-11 22:18:48 +05:30
# @param [TanukiEmoji::Character] emoji
# @param [Hash] options
def gl_emoji_tag(emoji, options = {})
return unless emoji
2017-08-17 22:00:37 +05:30
data = {
2021-12-11 22:18:48 +05:30
name: emoji.name,
unicode_version: emoji.unicode_version
2017-08-17 22:00:37 +05:30
}
2021-12-11 22:18:48 +05:30
options = { title: emoji.description, data: data }.merge(options)
2017-08-17 22:00:37 +05:30
2021-12-11 22:18:48 +05:30
ActionController::Base.helpers.content_tag('gl-emoji', emoji.codepoints, options)
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
def custom_emoji_tag(name, image_source)
data = {
2022-06-21 17:19:12 +05:30
name: name,
fallback_src: image_source,
unicode_version: 'custom' # Prevents frontend to check for Unicode support
2021-03-11 19:13:27 +05:30
}
2022-06-21 17:19:12 +05:30
options = { title: name, data: data }
2021-03-11 19:13:27 +05:30
2022-06-21 17:19:12 +05:30
ActionController::Base.helpers.content_tag('gl-emoji', "", options)
2021-03-11 19:13:27 +05:30
end
2016-08-24 12:49:21 +05:30
end
end