{ a | id : Ginger.Id.ResourceId
, title : Ginger.Translation.Translation
, body : Ginger.Translation.Translation
, subtitle : Ginger.Translation.Translation
, summary : Ginger.Translation.Translation
, path : String
, category : List.NonEmpty.NonEmpty Ginger.Category.Category
, name : Maybe String
, properties : Json.Decode.Value
, publicationDate : Maybe Time.Posix
, media : Ginger.Media.Media
, blocks : List Block
}
An Elm representation of a Ginger resource.
Note the a
in the record definition, this an extensible record.
This means it includes at least all of these fields but may have others
as well. This lets us reason about whether the edges are included in the data,
compile time. The Ginger REST API includes edges nested only one level deep,
but since the edges are also resources we can re-use this datatype like
ResourceWith {}
. This tells use there are no other fields besides the ones here.
So you'll see this used in function signatures like:
ResourceWith Edges -- has edges
ResourceWith {} -- does not have the edges
ResourceWith a -- might have them but the code that's using this doesn't really care
Note: the ResourceWith {}
might actually have edges, they are just not fetched.
{ edges : List Edge }
The record we use to extend ResourceWith a
.
You can render a list of resource depictions like so:
viewDepictions : ResourceWith Edges -> List (Html msg)
viewDepictions resource =
List.map viewImage <|
depictions Media.Medium resource
This next example won't compile because you need a ResourceWith Edges
and this signature indicates they are missing.
viewDepictions : ResourceWith {} -> List (Html msg)
viewDepictions resource =
List.map viewImage <|
depictions Media.Medium resource
{ predicate : Ginger.Predicate.Predicate
, resource : ResourceWith {}
}
A connection to a resource named by Predicate
ResourceWith Edges
Alias for ResourceWith Edges
{ body : Ginger.Translation.Translation
, name : String
, type_ : BlockType
, relatedRscId : Maybe Ginger.Id.ResourceId
, properties : Json.Decode.Value
}
getCategory : ResourceWith a -> Ginger.Category.Category
Get the category of a ResourceWith
.
Every resource has a category, and that category can be part of a category tree.
For instance, the news
category belongs to the category tree text > news
.
This function will return only the category stored with the ResourceWith
,
so in this case news
, but not its parent text
.
getCategories : ResourceWith a -> List Ginger.Category.Category
Get the entire category tree of a ResourceWith
starting from the parent
category and ending with the smallest child. For example, in the case of a
news
resource, it will return [text
, news
].
getDepiction : Ginger.Media.MediaClass -> ResourceWith Edges -> Maybe String
The image url of the ResourceWith
depiction.
Returns the image url if there is a depiction and the mediaclass exists.
getDepictions : Ginger.Media.MediaClass -> ResourceWith Edges -> List String
The image urls of the ResourceWith
depictions
Returns a list of image urls if there is a depiction and the mediaclass exists.
objectsOfPredicate : Ginger.Predicate.Predicate -> { a | edges : List Edge } -> List (ResourceWith {})
Return all resources with a given predicate.
The returned resources won't have any edges themselves, indicated by the {}
in ResourceWith {}
.
fromJsonWithEdges : Json.Decode.Decoder (ResourceWith Edges)
Decode a ResourceWith
that has edges.
fromJsonWithoutEdges : Json.Decode.Decoder (ResourceWith {})
Decode a ResourceWith
that does not have edges.