You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
400 B

  1. # frozen_string_literal: true
  2. module EmojiHelper
  3. EMOJI_PATTERN = /(?<=[^[:alnum:]:]|\n|^):([\w+-]+):(?=[^[:alnum:]:]|$)/x
  4. def emojify(text)
  5. return text if text.blank?
  6. text.gsub(EMOJI_PATTERN) do |match|
  7. emoji = Emoji.find_by_alias($1) # rubocop:disable Rails/DynamicFindBy,Style/PerlBackrefs
  8. if emoji
  9. emoji.raw
  10. else
  11. match
  12. end
  13. end
  14. end
  15. end