-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate photo gallery captions (#230)
- Loading branch information
Showing
4 changed files
with
157 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,20 +1,37 @@ | ||
defmodule CMS.Field.Image do | ||
@moduledoc """ | ||
Represents an image field in the Drupal CMS. This image field is embedded | ||
in other content types like CMS.Page.NewsEntry. | ||
in other content types like CMS.Page.NewsEntry. Captions only used on galleries. | ||
""" | ||
alias Phoenix.HTML | ||
|
||
import CMS.Helpers, only: [rewrite_url: 1] | ||
import CMS.Helpers, | ||
only: [ | ||
field_value: 2, | ||
handle_html: 1, | ||
rewrite_url: 1 | ||
] | ||
|
||
defstruct url: "", alt: "" | ||
defstruct url: "", | ||
alt: "", | ||
caption: nil | ||
|
||
@type t :: %__MODULE__{ | ||
url: String.t(), | ||
alt: String.t() | ||
alt: String.t(), | ||
caption: HTML.safe() | nil | ||
} | ||
|
||
@spec from_api(map) :: t | ||
def from_api(%{"alt" => alt, "url" => url}) do | ||
%__MODULE__{alt: alt, url: rewrite_url(url)} | ||
def from_api(%{"alt" => alt, "url" => url} = data) do | ||
%__MODULE__{ | ||
url: rewrite_url(url), | ||
alt: alt, | ||
caption: data |> field_value("field_image_caption") |> handle_caption() | ||
} | ||
end | ||
|
||
@spec handle_caption(String.t() | nil) :: HTML.safe() | nil | ||
defp handle_caption(nil), do: nil | ||
defp handle_caption(caption), do: handle_html(caption) | ||
end |
This file contains 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 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 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