Small emoji refactor.
This commit is contained in:
parent
c17c8ce36d
commit
79aeb219d8
@ -23,8 +23,7 @@ def parse_mentions(text) do
|
|||||||
|> Enum.filter(fn ({_match, user}) -> user end)
|
|> Enum.filter(fn ({_match, user}) -> user end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def finmojifiy(text) do
|
@finmoji [
|
||||||
emoji_list = [
|
|
||||||
"a_trusted_friend",
|
"a_trusted_friend",
|
||||||
"alandislands",
|
"alandislands",
|
||||||
"association",
|
"association",
|
||||||
@ -90,8 +89,15 @@ def finmojifiy(text) do
|
|||||||
"woollysocks"
|
"woollysocks"
|
||||||
]
|
]
|
||||||
|
|
||||||
Enum.reduce(emoji_list, text, fn (emoji, text) ->
|
@finmoji_with_filenames Enum.map(@finmoji, fn (finmoji) ->
|
||||||
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, "/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
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ test "it can parse mentions and return the relevant users" do
|
|||||||
test "it adds cool emoji" do
|
test "it adds cool emoji" do
|
||||||
text = "I love :moominmamma:"
|
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
|
assert Formatter.finmojifiy(text) == expected_result
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user