- Use unicode when selecting emoji through picker - Convert shortcodes to unicode when storing text input server-side - Do not convert shortcodes in JS anymoremaster
parent
c42092ba7a
commit
e2685ccc81
@ -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 |
@ -0,0 +1,15 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe EmojiHelper, type: :helper do |
||||
describe '#emojify' do |
||||
it 'converts shortcodes to unicode' do |
||||
text = ':book: Book' |
||||
expect(emojify(text)).to eq '📖 Book' |
||||
end |
||||
|
||||
it 'does not convert shortcodes that are part of a string into unicode' do |
||||
text = ':see_no_evil::hear_no_evil::speak_no_evil:' |
||||
expect(emojify(text)).to eq text |
||||
end |
||||
end |
||||
end |
@ -1,5 +0,0 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe RoutingHelper, type: :helper do |
||||
|
||||
end |
Loading…
Reference in new issue