Class: Gollum::Filter::Emoji

Inherits:
Gollum::Filter show all
Defined in:
lib/gollum-lib/filter/emoji.rb

Overview

Emoji

Render an emoji tag such as “:smile:”. In some rare situations, you have to escape emoji tags e.g. when your content contains something like “hh:mm:ss” or “rake app:shell:install”. Prefix the leading colon with a backslash to disable this emoji tag e.g. “hh:mm:ss”.

Constant Summary collapse

EXTRACT_PATTERN =
%r{
  (?<!\[{2})
  (?<escape>\\)?:(?<name>[\w-]+):
  (?!\]{^2})
}ix

Constants inherited from Gollum::Filter

PLACEHOLDER_PATTERN

Instance Attribute Summary

Attributes inherited from Gollum::Filter

#close_pattern, #open_pattern

Instance Method Summary collapse

Methods inherited from Gollum::Filter

#initialize

Methods included from Helpers

#path_to_link_text, #trim_leading_slashes

Constructor Details

This class inherits a constructor from Gollum::Filter

Instance Method Details

#extract(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/gollum-lib/filter/emoji.rb', line 17

def extract(data)
  data.gsub! EXTRACT_PATTERN do
    case
      when $~[:escape] then $&[1..-1]
      when emoji_exists?($~[:name]) then "#{open_pattern}#{$~[:name]}#{close_pattern}"
      else $&
    end
  end
  data
end

#process(data) ⇒ Object



28
29
30
31
32
# File 'lib/gollum-lib/filter/emoji.rb', line 28

def process(data)
  src = ::File.join(@markup.wiki.base_path, '/gollum/emoji/\\k<name>')
  data.gsub! process_pattern, %Q(<img src="#{src}" alt="\\k<name>" class="emoji">)
  data
end