Class: AutoHtml::Emoji

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_html/emoji.rb

Overview

Emoji filter

Instance Method Summary collapse

Constructor Details

#initialize(asset_root: '/images', width: 20, height: 20) ⇒ Emoji

Returns a new instance of Emoji.



7
8
9
10
11
# File 'lib/auto_html/emoji.rb', line 7

def initialize(asset_root: '/images', width: 20, height: 20)
  @asset_root = asset_root
  @width = width
  @height = height
end

Instance Method Details

#call(text) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/auto_html/emoji.rb', line 13

def call(text)
  text.gsub(emoji_pattern) do
    name = Regexp.last_match(1)
    alt = ":#{name}:"
    html_options = {
      src: emoji_url(name),
      class: 'emoji',
      title: alt,
      alt: alt,
      height: @width,
      witdh: @height,
      align: 'absmiddle'
    }
    TagHelper.tag(:img, html_options)
  end
end