Module: Gitlab::Emoji

Extended by:
Emoji
Included in:
Emoji
Defined in:
lib/gitlab/emoji.rb

Instance Method Summary collapse

Instance Method Details

#emoji_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/gitlab/emoji.rb', line 47

def emoji_exists?(name)
  emojis.has_key?(name)
end

#emoji_filename(name) ⇒ Object


27
28
29
# File 'lib/gitlab/emoji.rb', line 27

def emoji_filename(name)
  emojis[name]["unicode"]
end

#emoji_image_tag(name, src) ⇒ Object


43
44
45
# File 'lib/gitlab/emoji.rb', line 43

def emoji_image_tag(name, src)
  "<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{src}' height='20' width='20' align='absmiddle' />"
end

#emoji_unicode_filename(moji) ⇒ Object


31
32
33
# File 'lib/gitlab/emoji.rb', line 31

def emoji_unicode_filename(moji)
  emojis_by_moji[moji]["unicode"]
end

#emoji_unicode_version(name) ⇒ Object


35
36
37
# File 'lib/gitlab/emoji.rb', line 35

def emoji_unicode_version(name)
  emoji_unicode_versions_by_name[name]
end

#emojisObject


7
8
9
# File 'lib/gitlab/emoji.rb', line 7

def emojis
  Gemojione.index.instance_variable_get(:@emoji_by_name)
end

#emojis_aliasesObject


23
24
25
# File 'lib/gitlab/emoji.rb', line 23

def emojis_aliases
  @emoji_aliases ||= Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'aliases.json')))
end

#emojis_by_mojiObject


11
12
13
# File 'lib/gitlab/emoji.rb', line 11

def emojis_by_moji
  Gemojione.index.instance_variable_get(:@emoji_by_moji)
end

#emojis_namesObject


19
20
21
# File 'lib/gitlab/emoji.rb', line 19

def emojis_names
  emojis.keys
end

#emojis_unicodesObject


15
16
17
# File 'lib/gitlab/emoji.rb', line 15

def emojis_unicodes
  emojis_by_moji.keys
end

#gl_emoji_tag(name, options = {}) ⇒ Object

CSS sprite fallback takes precedence over image fallback


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gitlab/emoji.rb', line 52

def gl_emoji_tag(name, options = {})
  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)
  }
  options = { title: emoji_info['description'], data: data }.merge(options)

  ActionController::Base.helpers.('gl-emoji', emoji_info['moji'], options)
end

#normalize_emoji_name(name) ⇒ Object


39
40
41
# File 'lib/gitlab/emoji.rb', line 39

def normalize_emoji_name(name)
  emojis_aliases[name] || name
end