Module: Emoji

Defined in:
lib/emoji.rb,
lib/emoji/index.rb,
lib/emoji/railtie.rb,
lib/emoji/version.rb

Defined Under Namespace

Classes: Index, Railtie

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.asset_hostObject


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

def self.asset_host
  @asset_host || 'http://localhost:3000'
end

.asset_host=(host) ⇒ Object


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

def self.asset_host=(host)
  @asset_host = host
end

.asset_pathObject


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

def self.asset_path
  @asset_path || '/'
end

.asset_path=(path) ⇒ Object


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

def self.asset_path=(path)
  @asset_path = path
end

.escape_html(string) ⇒ Object


68
69
70
# File 'lib/emoji.rb', line 68

def self.escape_html(string)
  @escaper.escape_html(string)
end

.image_url_for_name(name) ⇒ Object


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

def self.image_url_for_name(name)
  "#{asset_host}#{ File.join(asset_path, name) }.png"
end

.image_url_for_unicode_moji(moji) ⇒ Object


40
41
42
43
# File 'lib/emoji.rb', line 40

def self.image_url_for_unicode_moji(moji)
  emoji = index.find_by_moji(moji)
  image_url_for_name(emoji['name'])
end

.indexObject


72
73
74
# File 'lib/emoji.rb', line 72

def self.index
  @index ||= Index.new
end

.replace_unicode_moji_with_images(string) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/emoji.rb', line 45

def self.replace_unicode_moji_with_images(string)
  return string unless string
  unless string.match(index.unicode_moji_regex)
    return safe_string(string)
  end

  safe_string = safe_string(string.dup)
  safe_string.gsub!(index.unicode_moji_regex) do |moji|
    %Q{<img alt="#{moji}" class="emoji" src="#{ image_url_for_unicode_moji(moji) }">}
  end
  safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)

  safe_string
end

.safe_string(string) ⇒ Object


60
61
62
63
64
65
66
# File 'lib/emoji.rb', line 60

def self.safe_string(string)
  if string.respond_to?(:html_safe?) && string.html_safe?
    string
  else
    escape_html(string)
  end
end