Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/devils_dictionary_web/components/culture.ex
Original file line number Diff line number Diff line change
Expand Up @@ -547,16 +547,18 @@ defmodule DevilsDictionaryWeb.Culture do
|> Enum.filter(&match?(%{placement: :shelf}, &1.mark))
end

# The mark the cards of one state carry, or nothing. The state's, not the
# item's: what a source's licence requires is a fact about the source, and
# a shelf holding two sources' items gives each card the mark of the source
# that supplied it.
defp card_mark(state) do
case mark(Map.get(state, :attribution_mark)) do
%{placement: :card} = mark -> mark
_other -> nil
end
end
# The mark of the source that supplied one state's cards, or nothing. The
# state's, not the item's: what a source's licence requires is a fact about
# the source, and a shelf holding two sources' items gives each card the
# mark of the source that supplied it.
#
# Whatever its placement. A `:card` mark draws its image on the card; a
# `:shelf` mark draws it once in the byline column — but the *wording* of
# the link back is a separate obligation the mark also carries, and it is
# per item wherever the image goes. Spotify's mark moved to the shelf in
# #152 and every card's link-out silently became *Open at Spotify*, which is
# not one of the three phrases its Branding Guidelines permit.
defp card_mark(state), do: mark(Map.get(state, :attribution_mark))

attr :mark, :map, required: true
attr :provider, :string, required: true
Expand Down Expand Up @@ -833,7 +835,7 @@ defmodule DevilsDictionaryWeb.Culture do
and this card's dark surface is neither, so the black logo takes
the light theme and the white one the dark. --%>
<div
:if={@mark}
:if={@mark && @mark.placement == :card}
id={"culture-mark-#{@item.external_namespace}-#{@item.external_id}"}
class="-mx-2.5 p-2.5"
>
Expand All @@ -852,7 +854,7 @@ defmodule DevilsDictionaryWeb.Culture do
target="_blank"
rel="noreferrer"
id={"culture-source-#{@item.external_id}"}
title={"Open at #{@source_name || "the source"}"}
title={(@mark && @mark.link_text) || "Open at #{@source_name || "the source"}"}
class="inline-flex rounded-sm text-sm text-mist-500 underline-offset-4 transition-colors hover:text-mist-950 hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 dark:hover:text-white"
>
<span :if={@mark && @mark.link_text}>{@mark.link_text} ↗</span>
Expand Down
38 changes: 38 additions & 0 deletions test/devils_dictionary_web/components/culture_chrome_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,44 @@ defmodule DevilsDictionaryWeb.CultureChromeTest do
end
end

describe "the wording of the link back travels with the mark, wherever the image goes" do
# A mark carries two obligations: an image, whose `:placement` says where
# it is drawn, and the wording of the link back, which is per item
# whatever the placement. #152 moved Spotify's image to the shelf and
# every card's link-out silently became *Open at Spotify* — not one of
# the three phrases its guidelines permit.
defp marked_search(placement) do
searches("aa_search", "AA stock", 2, %{
attribution_mark: %{
light: "/images/a-mark.png",
dark: nil,
alt: "A Service",
href: "https://a.test/",
width: 80,
link_text: "Listen on A Service",
placement: placement
}
})
end

test "a shelf-placed mark still words every card's link back, and draws no card image" do
html = render([marked_search(:shelf)])

assert html =~ ~s(id="culture-mark-aa_search")
refute html =~ ~s(id="culture-mark-aa_search-)
assert Regex.scan(~r/Listen on A Service ↗/, html) |> length() == 2
refute html =~ "Open at AA stock"
end

test "a card-placed mark draws the image on each card and words the link the same way" do
html = render([marked_search(:card)])

refute html =~ ~s(id="culture-mark-aa_search")
assert Regex.scan(~r/id="culture-mark-aa_search-/, html) |> length() == 2
assert Regex.scan(~r/Listen on A Service ↗/, html) |> length() == 2
end
end

describe "D4 — the byline is names" do
test "the header carries the name and the qualifier moves into the About" do
html =
Expand Down