Small emoji refactor.

This commit is contained in:
Roger Braun 2017-09-16 15:47:45 +02:00
parent c17c8ce36d
commit 79aeb219d8
2 changed files with 75 additions and 69 deletions

View File

@ -23,8 +23,7 @@ defmodule Pleroma.Formatter do
|> Enum.filter(fn ({_match, user}) -> user end)
end
def finmojifiy(text) do
emoji_list = [
@finmoji [
"a_trusted_friend",
"alandislands",
"association",
@ -90,8 +89,15 @@ defmodule Pleroma.Formatter do
"woollysocks"
]
Enum.reduce(emoji_list, text, fn (emoji, text) ->
String.replace(text, ":#{String.replace(emoji, "_", "")}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{String.replace(emoji, "_", "")}' src='#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/#{emoji}-128.png' />")
@finmoji_with_filenames Enum.map(@finmoji, fn (finmoji) ->
{finmoji, "/finmoji/128px/#{finmoji}-128.png"}
end)
@emoji @finmoji_with_filenames
def finmojifiy(text) do
Enum.reduce(@emoji, text, fn ({emoji, file}, text) ->
String.replace(text, ":#{emoji}:", "<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{file}' />")
end)
end
end

View File

@ -47,7 +47,7 @@ defmodule Pleroma.FormatterTest do
test "it adds cool emoji" do
text = "I love :moominmamma:"
expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/moominmamma-128.png' />"
expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
assert Formatter.finmojifiy(text) == expected_result
end