diff options
author | beatrix-bitrot <beatrix.bitrot@gmail.com> | 2017-07-22 01:16:53 +0000 |
---|---|---|
committer | beatrix-bitrot <beatrix.bitrot@gmail.com> | 2017-07-22 01:16:53 +0000 |
commit | 984d2d4cb626dd3a4da707ecf1e8ad45b476d8fb (patch) | |
tree | 9a7ba46c448cca4a4a245224bf421941a33c263d /app/helpers | |
parent | 0244019ca17288802a144c84b7e0f319f1685695 (diff) | |
parent | 8d6c3cd48ae4f96752ff6b698bc7244d97aa9a27 (diff) |
Merge that good fresh upstream shit
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/emoji_helper.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/app/helpers/emoji_helper.rb b/app/helpers/emoji_helper.rb index c1595851f..848c03fce 100644 --- a/app/helpers/emoji_helper.rb +++ b/app/helpers/emoji_helper.rb @@ -1,19 +1,24 @@ # frozen_string_literal: true module EmojiHelper - EMOJI_PATTERN = /(?<=[^[:alnum:]:]|\n|^):([\w+-]+):(?=[^[:alnum:]:]|$)/x - def emojify(text) return text if text.blank? - text.gsub(EMOJI_PATTERN) do |match| - emoji = Emoji.find_by_alias($1) # rubocop:disable Rails/DynamicFindBy,Style/PerlBackrefs + text.gsub(emoji_pattern) do |match| + emoji = Emoji.instance.unicode($1) # rubocop:disable Style/PerlBackrefs if emoji - emoji.raw + 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 |