Merge pull request #163 from poanetwork/configurable-social-media-#153
Configurable social media linkspull/166/head
commit
7710814876
@ -0,0 +1,27 @@ |
|||||||
|
defmodule ExplorerWeb.SocialMedia do |
||||||
|
@moduledoc """ |
||||||
|
This module provides social media links |
||||||
|
""" |
||||||
|
|
||||||
|
@services %{ |
||||||
|
facebook: "https://www.facebook.com/", |
||||||
|
instagram: "https://www.instagram.com/", |
||||||
|
twitter: "https://www.twitter.com/", |
||||||
|
telegram: "https://t.me/" |
||||||
|
} |
||||||
|
|
||||||
|
def links do |
||||||
|
:explorer_web |
||||||
|
|> Application.get_env(__MODULE__, []) |
||||||
|
|> Enum.reverse() |
||||||
|
|> filter_and_build_links() |
||||||
|
end |
||||||
|
|
||||||
|
# Private functions |
||||||
|
|
||||||
|
defp filter_and_build_links(configured_services) do |
||||||
|
for {name, account} <- configured_services, Map.has_key?(@services, name) do |
||||||
|
{name, @services[name] <> account} |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -1,3 +1,9 @@ |
|||||||
defmodule ExplorerWeb.LayoutView do |
defmodule ExplorerWeb.LayoutView do |
||||||
use ExplorerWeb, :view |
use ExplorerWeb, :view |
||||||
|
|
||||||
|
alias ExplorerWeb.SocialMedia |
||||||
|
|
||||||
|
def configured_social_media_services do |
||||||
|
SocialMedia.links() |
||||||
|
end |
||||||
end |
end |
||||||
|
@ -0,0 +1,25 @@ |
|||||||
|
defmodule ExplorerWeb.SocialMediaTest do |
||||||
|
use Explorer.DataCase |
||||||
|
|
||||||
|
alias ExplorerWeb.SocialMedia |
||||||
|
|
||||||
|
test "it filters out unsupported services" do |
||||||
|
Application.put_env( |
||||||
|
:explorer_web, |
||||||
|
ExplorerWeb.SocialMedia, |
||||||
|
twitter: "MyTwitterProfile", |
||||||
|
myspace: "MyAwesomeProfile" |
||||||
|
) |
||||||
|
|
||||||
|
links = SocialMedia.links() |
||||||
|
assert Keyword.has_key?(links, :twitter) |
||||||
|
refute Keyword.has_key?(links, :myspace) |
||||||
|
end |
||||||
|
|
||||||
|
test "it prepends the service url" do |
||||||
|
Application.put_env(:explorer_web, ExplorerWeb.SocialMedia, twitter: "MyTwitterProfile") |
||||||
|
|
||||||
|
links = SocialMedia.links() |
||||||
|
assert links[:twitter] == "https://www.twitter.com/MyTwitterProfile" |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue