module Gemojione

Constants

VERSION

Public Class Methods

asset_host() click to toggle source
# File lib/gemojione.rb, line 26
def self.asset_host
  @asset_host || 'http://localhost:3000'
end
asset_host=(host) click to toggle source
# File lib/gemojione.rb, line 30
def self.asset_host=(host)
  @asset_host = host
end
asset_path() click to toggle source
# File lib/gemojione.rb, line 34
def self.asset_path
  @asset_path || '/'
end
asset_path=(path) click to toggle source
# File lib/gemojione.rb, line 38
def self.asset_path=(path)
  @asset_path = path
end
default_size() click to toggle source
# File lib/gemojione.rb, line 42
def self.default_size
  @default_size
end
default_size=(size) click to toggle source
# File lib/gemojione.rb, line 46
def self.default_size=(size)
  @default_size = size
end
escape_html(string) click to toggle source
# File lib/gemojione.rb, line 187
def self.escape_html(string)
  @escaper.escape_html(string)
end
image_tag_for_moji(moji) click to toggle source
# File lib/gemojione.rb, line 77
def self.image_tag_for_moji(moji)
  emoji = index.find_by_moji(moji)
  if use_sprite
    %Q{<span class="emojione emojione-#{emoji['unicode'].to_s.downcase}" alt="#{ emoji['name'] }" title="#{ emoji['shortname'] }">#{ moji }</span>}
  else
    %Q{<img alt="#{emoji['moji']}" class="emoji" src="#{ image_url_for_unicode_moji(moji) }"#{ default_size ? ' style="width: '+default_size+';"' : '' }>}
  end
end
image_tag_for_unicode(unicode) click to toggle source
# File lib/gemojione.rb, line 86
def self.image_tag_for_unicode(unicode)
  emoji = index.find_by_unicode(unicode)
  if use_sprite
    %Q{<span class="emojione emojione-#{emoji['unicode'].to_s.downcase}" alt="#{ emoji['name'] }" title="#{ emoji['shortname'] }">#{ emoji['moji'] }</span>}
  else
    %Q{<img alt="#{emoji['name']}" class="emoji" src="#{ image_url_for_unicode_moji(emoji['moji']) }"#{ default_size ? ' style="width: '+default_size+';"' : '' }>}
  end
end
image_url_for_name(name) click to toggle source
# File lib/gemojione.rb, line 66
def self.image_url_for_name(name)
  emoji = index.find_by_name(name)
  unicode = use_svg ? emoji['unicode'].upcase : emoji['unicode'].downcase
  "#{asset_host}#{ File.join(asset_path, unicode) }.#{ use_svg ? 'svg' : 'png' }"
end
image_url_for_unicode_moji(moji) click to toggle source
# File lib/gemojione.rb, line 72
def self.image_url_for_unicode_moji(moji)
  emoji = index.find_by_moji(moji)
  image_url_for_name(emoji['name'])
end
images_path() click to toggle source
# File lib/gemojione.rb, line 195
def self.images_path
  File.expand_path("../assets/#{ use_svg ? 'svg' : 'png' }", File.dirname(__FILE__))
end
index() click to toggle source
# File lib/gemojione.rb, line 191
def self.index
  @index ||= Index.new
end
replace_ascii_moji_with_images(string) click to toggle source
# File lib/gemojione.rb, line 145
def self.replace_ascii_moji_with_images(string)
  return string unless string
  unless string.match(index.ascii_moji_regex)
    return safe_string(string)
  end

  string.gsub!(index.ascii_moji_regex) do |code|
    moji = index.find_by_ascii(code)['moji']
    Gemojione.image_tag_for_moji(moji)
  end

  unless string.respond_to?(:html_safe?) && string.html_safe?
    safe_string = CGI::unescapeElement(CGI.escape_html(string), %w[span img])
  end
  safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)

  safe_string
end
replace_named_moji_with_images(string) click to toggle source
# File lib/gemojione.rb, line 110
def self.replace_named_moji_with_images(string)
  return string unless string
  unless string.match(index.shortname_moji_regex)
    return safe_string(string)
  end

  safe_string = safe_string(string.dup)
  safe_string.gsub!(index.shortname_moji_regex) do |code|
    name = code.tr(':','')
    moji = index.find_by_name(name)
    Gemojione.image_tag_for_unicode(moji['unicode'])
  end
  safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)

  safe_string
end
replace_named_moji_with_unicode_moji(string) click to toggle source
# File lib/gemojione.rb, line 127
def self.replace_named_moji_with_unicode_moji(string)
  return string unless string
  unless string.match(index.shortname_moji_regex)
    return safe_string(string)
  end

  safe_string = safe_string(string.dup)
  safe_string.gsub!(index.shortname_moji_regex) do |code|
    name = code.tr(':','')
    moji = index.find_by_name(name)
    moji['moji']
  end

  safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)

  safe_string
end
replace_unicode_moji_with_images(string) click to toggle source
# File lib/gemojione.rb, line 95
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|
    Gemojione.image_tag_for_moji(moji)
  end
  safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)

  safe_string
end
replace_unicode_moji_with_names(string) click to toggle source
# File lib/gemojione.rb, line 164
def self.replace_unicode_moji_with_names(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|
      index.find_by_moji(moji)['shortname']
    end
    safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)

    safe_string
end
safe_string(string) click to toggle source
# File lib/gemojione.rb, line 179
def self.safe_string(string)
  if string.respond_to?(:html_safe?) && string.html_safe?
    string
  else
    escape_html(string)
  end
end
sprites_path() click to toggle source
# File lib/gemojione.rb, line 199
def self.sprites_path
  File.expand_path("../assets/sprites", File.dirname(__FILE__))
end
use_sprite() click to toggle source
# File lib/gemojione.rb, line 58
def self.use_sprite
  @use_sprite
end
use_sprite=(useit) click to toggle source
# File lib/gemojione.rb, line 62
def self.use_sprite=(useit)
  @use_sprite = useit
end
use_svg() click to toggle source
# File lib/gemojione.rb, line 50
def self.use_svg
  @use_svg
end
use_svg=(useit) click to toggle source
# File lib/gemojione.rb, line 54
def self.use_svg=(useit)
  @use_svg = useit
end