Small emoji refactor.
authorRoger Braun <roger@rogerbraun.net>
Sat, 16 Sep 2017 13:47:45 +0000 (15:47 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sat, 16 Sep 2017 13:47:45 +0000 (15:47 +0200)
lib/pleroma/formatter.ex
test/formatter_test.exs

index e95a314b484c1d661dd41d7994ca95e0f0282df2..c3b7bdaee9271f413841380e6e529d658a0e4126 100644 (file)
@@ -23,75 +23,81 @@ defmodule Pleroma.Formatter 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"
+  ]
+
+  @finmoji_with_filenames Enum.map(@finmoji, fn (finmoji) ->
+    {finmoji, "/finmoji/128px/#{finmoji}-128.png"}
+  end)
 
-    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' />")
+  @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
index 9b6ee2425e939b8c466fe981b08a2c260b639aa2..4b15f408052b3c36eca50e52918cc321a780a6ae 100644 (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