mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-23 22:48:07 +01:00
a390abdefb
* Use the same emoji data on the frontend and backend * Move emoji.json to repository, add tests This way you don't need to install node dependencies if you only want to run Ruby code
24 lines
489 B
Ruby
24 lines
489 B
Ruby
# frozen_string_literal: true
|
|
|
|
module EmojiHelper
|
|
def emojify(text)
|
|
return text if text.blank?
|
|
|
|
text.gsub(emoji_pattern) do |match|
|
|
emoji = Emoji.instance.unicode($1) # rubocop:disable Style/PerlBackrefs
|
|
|
|
if emoji
|
|
emoji
|
|
else
|
|
match
|
|
end
|
|
end
|
|
end
|
|
|
|
def emoji_pattern
|
|
@emoji_pattern ||=
|
|
/(?<=[^[:alnum:]:]|\n|^)
|
|
(#{Emoji.instance.names.map { |name| Regexp.escape(name) }.join('|')})
|
|
(?=[^[:alnum:]:]|$)/x
|
|
end
|
|
end
|