You can create your own Elm types to represent your documents using the following components.
Prismic.Internal.Field
A field in the Document
.
Prismic.Internal.StructuredText
StructuredText
can be rendered to HTML using structuredTextAsHtml
.
Prismic.Internal.StructuredTextBlock
An element of StructuredText
.
Prismic.Internal.ImageViews
A collection of image views.
Prismic.Internal.ImageView
Properties for a single image view.
Prismic.Internal.ImageDimensions
Dimensions of an image view.
Prismic.Internal.Embed
Embed elements.
Prismic.Internal.Link
Links to other documents or to the web.
Prismic.Internal.DocumentReference
A reference to a Prismic document.
text : Prismic.Internal.Decoder Field String
Decode a Text field.
structuredText : Prismic.Internal.Decoder Field StructuredText
Decode a StructuredText field.
image : Prismic.Internal.Decoder Field ImageViews
Decode an Image field.
date : Prismic.Internal.Decoder Field Date
Decode a Date field.
link : Prismic.Internal.Decoder Field Link
Decode a Link field.
structuredTextAsHtml : LinkResolver msg -> StructuredText -> List (Html msg)
Render some StructuredText
as HTML.
You must supply a LinkResolver
to resolve any links in the StructuredText
.
If you don't care about this, you can use the defaultLinkResolver
.
structuredTextBlockAsHtml : LinkResolver msg -> StructuredTextBlock -> Html msg
Render a single block of StructuredText
as HTML.
imageAsHtml : ImageView -> Html msg
embedAsHtml : Embed -> Html msg
linkAsHtml : LinkResolver msg -> Link -> Html msg
{ resolveDocumentReference : DocumentReference -> List (Html.Attribute msg)
, resolveUrl : String -> List (Html.Attribute msg)
}
A LinkResolver
simply converts a Prismic DocumentReference
to a list of
Html.Attribute
s. structuredTextAsHtml
and friends add these attributes to
links in the text.
For example, you can use this to add onClick
handlers to links:
type Msg
= NavigateTo DocumentReference
myLinkResolver : LinkResolver Msg
myLinkResolver docRef =
[ Html.Attributes.href ""
, Html.Events.onClick (NavigateTo docRef)
]
view : StructuredText -> Html Msg
view myStructuredText =
structuredTextAsHtml myLinkResolver myStructuredText
Your update
function would handle the NavigateTo
message and perform the
appropriate routing.
defaultLinkResolver : LinkResolver msg
Adds a default href
attribute to links:
[ href "documents/{doc.id}/{doc.slug}" ]
resolveLink : LinkResolver msg -> Link -> List (Html.Attribute msg)
StructuredText
helpersgetTitle : StructuredText -> Maybe StructuredTextBlock
Get the first title out of some StructuredText
, if there is one.
getFirstImage : StructuredText -> Maybe ImageView
Get the first image out of some StructuredText
, if there is one.
getFirstParagraph : StructuredText -> Maybe StructuredTextBlock
Get the first paragraph out of some StructuredText
, if there is one.
getText : StructuredTextBlock -> String
Get the contents of a single StructuredText
element as a String
.
getTexts : StructuredText -> String
Get the contents of a some StructuredText
as a String
.