diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-07-14 19:47:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-14 19:47:53 +0200 |
commit | e2685ccc81f04e1a63a97af80686bf85027418a6 (patch) | |
tree | 20e9847c734a11f7a80d31eb8104bc84bbffa9a1 /app/helpers | |
parent | c42092ba7ad1cbf78ca8463b6525ec2b7efbdd92 (diff) |
Fix #4149, fix #1199 - Store emojis as unicode (#4189)
- Use unicode when selecting emoji through picker - Convert shortcodes to unicode when storing text input server-side - Do not convert shortcodes in JS anymore
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/emoji_helper.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/helpers/emoji_helper.rb b/app/helpers/emoji_helper.rb new file mode 100644 index 000000000..c1595851f --- /dev/null +++ b/app/helpers/emoji_helper.rb @@ -0,0 +1,19 @@ +# 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 + + if emoji + emoji.raw + else + match + end + end + end +end |