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,75 +23,81 @@ 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", "auroraborealis",
"auroraborealis", "baby_in_a_box",
"baby_in_a_box", "bear",
"bear", "black_gold",
"black_gold", "christmasparty",
"christmasparty", "crosscountryskiing",
"crosscountryskiing", "cupofcoffee",
"cupofcoffee", "education",
"education", "fashionista_finns",
"fashionista_finns", "finnishlove",
"finnishlove", "flag",
"flag", "forest",
"forest", "four_seasons_of_bbq",
"four_seasons_of_bbq", "girlpower",
"girlpower", "handshake",
"handshake", "happiness",
"happiness", "headbanger",
"headbanger", "icebreaker",
"icebreaker", "iceman",
"iceman", "joulutorttu",
"joulutorttu", "kaamos",
"kaamos", "kalsarikannit_f",
"kalsarikannit_f", "kalsarikannit_m",
"kalsarikannit_m", "karjalanpiirakka",
"karjalanpiirakka", "kicksled",
"kicksled", "kokko",
"kokko", "lavatanssit",
"lavatanssit", "losthopes_f",
"losthopes_f", "losthopes_m",
"losthopes_m", "mattinykanen",
"mattinykanen", "meanwhileinfinland",
"meanwhileinfinland", "moominmamma",
"moominmamma", "nordicfamily",
"nordicfamily", "out_of_office",
"out_of_office", "peacemaker",
"peacemaker", "perkele",
"perkele", "pesapallo",
"pesapallo", "polarbear",
"polarbear", "pusa_hispida_saimensis",
"pusa_hispida_saimensis", "reindeer",
"reindeer", "sami",
"sami", "sauna_f",
"sauna_f", "sauna_m",
"sauna_m", "sauna_whisk",
"sauna_whisk", "sisu",
"sisu", "stuck",
"stuck", "suomimainittu",
"suomimainittu", "superfood",
"superfood", "swan",
"swan", "the_cap",
"the_cap", "the_conductor",
"the_conductor", "the_king",
"the_king", "the_voice",
"the_voice", "theoriginalsanta",
"theoriginalsanta", "tomoffinland",
"tomoffinland", "torillatavataan",
"torillatavataan", "unbreakable",
"unbreakable", "waiting",
"waiting", "white_nights",
"white_nights", "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

View file

@ -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