From 79aeb219d8a1d50f076e0e8cc55da83d9ba8b502 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 16 Sep 2017 15:47:45 +0200 Subject: [PATCH] Small emoji refactor. --- lib/pleroma/formatter.ex | 142 ++++++++++++++++++++------------------- test/formatter_test.exs | 2 +- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index e95a314b4..c3b7bdaee 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -23,75 +23,81 @@ def parse_mentions(text) do |> Enum.filter(fn ({_match, user}) -> user end) end - def finmojifiy(text) do - emoji_list = [ - "a_trusted_friend", - "alandislands", - "association", - "auroraborealis", - "baby_in_a_box", - "bear", - "black_gold", - "christmasparty", - "crosscountryskiing", - "cupofcoffee", - "education", - "fashionista_finns", - "finnishlove", - "flag", - "forest", - "four_seasons_of_bbq", - "girlpower", - "handshake", - "happiness", - "headbanger", - "icebreaker", - "iceman", - "joulutorttu", - "kaamos", - "kalsarikannit_f", - "kalsarikannit_m", - "karjalanpiirakka", - "kicksled", - "kokko", - "lavatanssit", - "losthopes_f", - "losthopes_m", - "mattinykanen", - "meanwhileinfinland", - "moominmamma", - "nordicfamily", - "out_of_office", - "peacemaker", - "perkele", - "pesapallo", - "polarbear", - "pusa_hispida_saimensis", - "reindeer", - "sami", - "sauna_f", - "sauna_m", - "sauna_whisk", - "sisu", - "stuck", - "suomimainittu", - "superfood", - "swan", - "the_cap", - "the_conductor", - "the_king", - "the_voice", - "theoriginalsanta", - "tomoffinland", - "torillatavataan", - "unbreakable", - "waiting", - "white_nights", - "woollysocks" - ] + @finmoji [ + "a_trusted_friend", + "alandislands", + "association", + "auroraborealis", + "baby_in_a_box", + "bear", + "black_gold", + "christmasparty", + "crosscountryskiing", + "cupofcoffee", + "education", + "fashionista_finns", + "finnishlove", + "flag", + "forest", + "four_seasons_of_bbq", + "girlpower", + "handshake", + "happiness", + "headbanger", + "icebreaker", + "iceman", + "joulutorttu", + "kaamos", + "kalsarikannit_f", + "kalsarikannit_m", + "karjalanpiirakka", + "kicksled", + "kokko", + "lavatanssit", + "losthopes_f", + "losthopes_m", + "mattinykanen", + "meanwhileinfinland", + "moominmamma", + "nordicfamily", + "out_of_office", + "peacemaker", + "perkele", + "pesapallo", + "polarbear", + "pusa_hispida_saimensis", + "reindeer", + "sami", + "sauna_f", + "sauna_m", + "sauna_whisk", + "sisu", + "stuck", + "suomimainittu", + "superfood", + "swan", + "the_cap", + "the_conductor", + "the_king", + "the_voice", + "theoriginalsanta", + "tomoffinland", + "torillatavataan", + "unbreakable", + "waiting", + "white_nights", + "woollysocks" + ] - Enum.reduce(emoji_list, text, fn (emoji, text) -> - String.replace(text, ":#{String.replace(emoji, "_", "")}:", "#{emoji}") + @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}:", "#{emoji}") end) end end diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 9b6ee2425..4b15f4080 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -47,7 +47,7 @@ test "it can parse mentions and return the relevant users" do test "it adds cool emoji" do text = "I love :moominmamma:" - expected_result = "I love moominmamma" + expected_result = "I love moominmamma" assert Formatter.finmojifiy(text) == expected_result end