This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2017-07-14 19:47:53 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module EmojiHelper
|
|
|
|
def emojify(text)
|
|
|
|
return text if text.blank?
|
|
|
|
|
2017-07-21 04:27:40 +02:00
|
|
|
text.gsub(emoji_pattern) do |match|
|
|
|
|
emoji = Emoji.instance.unicode($1) # rubocop:disable Style/PerlBackrefs
|
2017-07-14 19:47:53 +02:00
|
|
|
|
|
|
|
if emoji
|
2017-07-21 04:27:40 +02:00
|
|
|
emoji
|
2017-07-14 19:47:53 +02:00
|
|
|
else
|
|
|
|
match
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-21 04:27:40 +02:00
|
|
|
|
|
|
|
def emoji_pattern
|
|
|
|
@emoji_pattern ||=
|
|
|
|
/(?<=[^[:alnum:]:]|\n|^)
|
|
|
|
(#{Emoji.instance.names.map { |name| Regexp.escape(name) }.join('|')})
|
|
|
|
(?=[^[:alnum:]:]|$)/x
|
|
|
|
end
|
2017-07-14 19:47:53 +02:00
|
|
|
end
|