module UrijiEmojiPicker
Constants
- VERSION
Public Instance Methods
emojify(text)
click to toggle source
# File lib/helper/emoji_helper.rb, line 5 def emojify(text) find_emoji(text) end
Private Instance Methods
emoji_map()
click to toggle source
# File lib/helper/emoji_helper.rb, line 75 def emoji_map UrijiEmojiPicker::EmojiMap end
exceptions_emoji(emoji)
click to toggle source
# File lib/helper/emoji_helper.rb, line 79 def exceptions_emoji(emoji) UrijiEmojiPicker::EmojiExceptions.call(emoji) end
find_emoji(text)
click to toggle source
# File lib/helper/emoji_helper.rb, line 11 def find_emoji(text) string = replace_unicode_moji_with_images(text) || text emoji = string.scan(regex) unicodes = [] index = UrijiEmojiPicker::EmojiMap.new emoji.each do |e| next if e.empty? tmp_emoji = e.join('') moji = index.find_by_moji(tmp_emoji) if moji flags = exceptions_emoji(tmp_emoji) if flags.empty? name = moji[0] if moji[0] char = moji[1]['char'] if moji[1]['char'] hash_emoji = { name: name, char: char } else hash_emoji = flags end else hash_emoji = exceptions_emoji(tmp_emoji) end unicodes << hash_emoji end unicodes.each do |hash| next if hash.nil? hash.reject! { |i| i.nil? } insert_image_to_image_tag(string, hash) if hash[:char] end string.respond_to?(:html_safe) ? string.html_safe : string end
insert_image_to_image_tag(string, img)
click to toggle source
# File lib/helper/emoji_helper.rb, line 63 def insert_image_to_image_tag(string, img) stanadrt_replace(string, img) end
regex()
click to toggle source
# File lib/helper/emoji_helper.rb, line 71 def regex UrijiEmojiPicker::EmojiRegex.regex end
replace_unicode_moji_with_images(string)
click to toggle source
# File lib/helper/emoji_helper.rb, line 48 def replace_unicode_moji_with_images(string) index = UrijiEmojiPicker::EmojiMap.new string.gsub!(regex) do |moji| if moji.size < 2 && index.find_by_moji(moji) alt = index.find_by_moji(moji)[0] else tmp = exceptions_emoji(moji) alt = tmp[:name] if tmp.key?(:name) end %(<span class='emoji-image'><img alt='#{alt}' class="emoji" src="#{moji}"></span>) end end
stanadrt_replace(string, img)
click to toggle source
# File lib/helper/emoji_helper.rb, line 67 def stanadrt_replace(string, img) string.gsub!(img[:char], "#{Emoji.asset_host}#{Emoji.asset_path}/#{img[:name]}.png") end