Repository navigation
Phase 1 of #102: harden the discovery provider contract #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5f57405
Harden the discovery provider contract before a second provider
holden ab36884
Record the Artsy section rendering on /define/allegory
holden 7b11929
Let a provider decide which HTTP statuses are worth retrying
holden f9e5527
Close the two gaps the registry left between claim and proof
holden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| defmodule DevilsDictionary.Discovery.ContentTypes do | ||
| @moduledoc """ | ||
| What a content type looks like on a shelf. Data, not code. | ||
|
|
||
| A provider declares `content_types` in its capabilities; the reader asks this | ||
| table how to present them. Adding a content type is an entry here, not a new | ||
| branch in `DevilsDictionaryWeb.Culture` or `WordLive`, which is the whole | ||
| point: the shared code stops knowing which providers exist. | ||
|
|
||
| `thumbnail_keys` is the ordered ladder read from a result's preview metadata. | ||
| A type with no `aspect` has no image slot at all, so a text result renders as | ||
| a title and its source rather than an empty poster frame. | ||
| """ | ||
|
|
||
| @table %{ | ||
| film: %{ | ||
| heading: "Films", | ||
| label: "film", | ||
| badge: "Film", | ||
| aspect: "aspect-[2/3]", | ||
| icon: "hero-film", | ||
| thumbnail_keys: ~w(poster_url still_url image_url media_url) | ||
| }, | ||
| artwork: %{ | ||
| heading: "Artworks", | ||
| label: "artwork", | ||
| badge: "Artwork", | ||
| aspect: "aspect-square", | ||
| icon: "hero-photo", | ||
| thumbnail_keys: ~w(image_url thumbnail_url) | ||
| }, | ||
| gif: %{ | ||
| heading: "GIFs", | ||
| label: "GIFs", | ||
| badge: nil, | ||
| aspect: "aspect-square", | ||
| icon: "hero-photo", | ||
| thumbnail_keys: ~w(media_url image_url) | ||
| }, | ||
| text: %{ | ||
| heading: "Texts", | ||
| label: "text", | ||
| badge: "Text", | ||
| aspect: nil, | ||
| icon: "hero-document-text", | ||
| thumbnail_keys: [] | ||
| } | ||
| } | ||
|
|
||
| @known [:film, :artwork, :gif, :text] | ||
|
|
||
| @doc "Every content type the reader can present, in shelf order." | ||
| def known, do: @known | ||
|
|
||
| @doc "True when at least one of `types` can be presented." | ||
| def any_known?(types), do: Enum.any?(types, &(&1 in @known)) | ||
|
|
||
| @doc "The presentation entry for a known content type." | ||
| def fetch!(type) when is_map_key(@table, type), do: Map.fetch!(@table, type) | ||
|
|
||
| @doc "The presentation entry, or the entry for `default` when the type is unknown." | ||
| def get(type, default \\ :film) | ||
|
|
||
| def get(type, _default) when is_map_key(@table, type), do: Map.fetch!(@table, type) | ||
| def get(_type, default), do: fetch!(default) | ||
|
|
||
| @doc "Reads a preview thumbnail using this content type's key ladder." | ||
| def thumbnail_url(type, metadata) when is_map(metadata) do | ||
| type | ||
| |> get() | ||
| |> Map.fetch!(:thumbnail_keys) | ||
| |> Enum.find_value(&metadata[&1]) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.