Add configurable social media links

Co-authored-by: tmecklem <timothy@mecklem.com>
pull/163/head
Tim Mecklem 7 years ago committed by jimmay5469
parent bf45faa513
commit 48f5f04a11
  1. 11
      apps/explorer_web/config/config.exs
  2. 9
      apps/explorer_web/lib/explorer_web/social_media.ex
  3. 22
      apps/explorer_web/lib/explorer_web/templates/layout/app.html.eex
  4. 6
      apps/explorer_web/lib/explorer_web/views/layout_view.ex
  5. 21
      apps/explorer_web/test/explorer_web/features/social_media_links_test.exs

@ -10,15 +10,20 @@ config :explorer_web,
namespace: ExplorerWeb,
ecto_repos: [Explorer.Repo]
# Configures gettext
config :explorer_web, ExplorerWeb.Gettext, locales: ~w(en), default_locale: "en"
# Configures the endpoint
config :explorer_web, ExplorerWeb.Endpoint,
url: [host: "localhost"],
render_errors: [view: ExplorerWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: ExplorerWeb.PubSub, adapter: Phoenix.PubSub.PG2]
# Configures gettext
config :explorer_web, ExplorerWeb.Gettext, locales: ~w(en), default_locale: "en"
config :explorer_web, ExplorerWeb.SocialMedia,
facebook: "https://www.facebook.com/PoaNetwork",
instagram: "https://www.instagram.com/PoaNetwork",
twitter: "https://www.twitter.com/PoaNetwork"
config :ex_cldr,
default_locale: "en",
locales: ["en"],

@ -0,0 +1,9 @@
defmodule ExplorerWeb.SocialMedia do
@moduledoc """
This module provides social media links
"""
def links do
Application.get_env(:explorer_web, __MODULE__, [])
end
end

@ -59,21 +59,13 @@
<% end %>
</div>
<div class="header__cell header__cell--links u-nudge-top" align="right">
<a href="https://www.facebook.com/PoaNetwork/" target="_blank" class="header__link">
<div class="social-media">
<i class="fa fa-facebook-f"></i>
</div>
</a>
<a href="https://www.instagram.com/PoaNetwork/" target="_blank" class="header__link">
<div class="social-media">
<i class="fa fa-instagram"></i>
</div>
</a>
<a href="https://www.twitter.com/PoaNetwork/" target="_blank" class="header__link">
<div class="social-media">
<i class="fa fa-twitter"></i>
</div>
</a>
<%= for {service, link} <- configured_social_media_services() do %>
<%= link to: link, class: "header__link", target: "_blank", "data-test": "#{service}_link" do %>
<div class="social-media">
<i class="fa fa-<%= service %>"></i>
</div>
<% end %>
<% end %>
</div>
</div>
</div>

@ -1,3 +1,9 @@
defmodule ExplorerWeb.LayoutView do
use ExplorerWeb, :view
alias ExplorerWeb.SocialMedia
def configured_social_media_services do
SocialMedia.links()
end
end

@ -0,0 +1,21 @@
defmodule ExplorerWeb.SocialMediaLinksTest do
use ExplorerWeb.FeatureCase, async: true
import Wallaby.Query
test "it shows twitter when twitter is configured", %{session: session} do
Application.put_env(:explorer_web, ExplorerWeb.SocialMedia, twitter: "https://twitter.com/twitter")
session
|> visit("/")
|> assert_has(css("[data-test='twitter_link']"))
end
test "it hides twitter when twitter is not configured", %{session: session} do
Application.put_env(:explorer_web, ExplorerWeb.SocialMedia, facebook: "https://facebook.com/")
session
|> visit("/")
|> refute_has(css("[data-test='twitter_link']"))
end
end
Loading…
Cancel
Save