An Elm SDK for Prismic.io.
Represents a Prismic request.
Go and fetch the Prismic Api metadata, if it has not already been fetched.
The Api is cached in the returned Model, so we don't have to fetch it next
time.
You start every Prismic request with this function.
Choose a form on which to base the rest of the Prismic request.
Convenience function for fetching a bookmarked document.
Override a Form's default ref
Override a Form's default lang.
Override a Form's default query.
See the section on Predicates below for how to construct a Predicate.
Submit the request.
Pass this function a Decoder to decode each document in the response into your
own Elm document type.
Represents a Prismic response.
This type is parameterized by docType, which is determined by the Decoder
you pass to submit.
The submit Task returns an updated Prismic Model with the request and
response cached.
In your app's update function, you should merge this with the existing cache
using cache.
update msg model =
case msg of
MyPrismicMsg (Ok ( prismic, response )) ->
{ model
| prismic =
cache model.prismic prismic
}The type representing Prismic query predicates.
atL fragment values matches documents having a list of values at fragment.
any fragment values matches documents having any of values at fragment.
fulltext fragment value matches documents with a full text search at fragment.
The Prismic Model keeps track of configuration and holds the response cache.
The possible errors elm-prismicio raises.
The Api for your Prismic repository.
Your app can look things up in this if you need to (for example, to resolve
links using the bookmarks Dict).
Properties representing a Prismic ref.
Most of the time you will be working with the master ref, which is added to
all requests by default.
A type to disambiguate Refs from other Strings.
Properties representing a Prismic form.
These are used to construct a default query.
A field in a Prismic form.
These are combined to construct query parameters for the eventual Http request.
The type of values for a Prismic form field.
TODO: Experiments are not Strings. Fill out this type.
Helpers for decoding various parts of a Document.
Decoders are parameterized by the input type val (Document, Field,
Group or Slice) and the result type a -- your type representing your
custom Prismic document type.
The following combinators can be used with any Decoder.
Transform a decoder.
Begin a decoding pipeline.
type alias MyDoc =
{ title : StructuredText }
myDocDecoder : Decoder Document MyDoc
myDocDecoder =
decode MyDoc
|> required "title" structuredTextUse a standard decoder in a pipeline.
The following is equivalent to the example using required:
myDocDecoder : Decoder Document MyDoc
myDocDecoder =
decode MyDoc
|> custom (requiredField "title" structuredText)Holds the Prismic document.
Documents consist of basic Fields, Groups and Slices.
You will decode this into your own document type by passing a Decoder Document
MyDocType to submit.
The document's ID.
The document's href.
The document's linked documents.
The document's slugs.
The document's tags.
The document's UID.
Decode a field.
Pass this function a Decoder Field a from the Prismic.Field module.
Decode a field that might be missing.
Decode a group.
Pass this function a Decoder Group a from the Prismic.Group module.
Groups can contain Fields, but not other Groups or Slices.
Here is an example with a document containing a group:
type alias MyDoc =
{ albums : List Album }
type alias Album =
{ title : String
, cover : Field.ImageViews
}
albumDecoder : Decoder Group Album
albumDecoder =
Prismic.decode Album
|> Group.required "title" Field.text
|> Group.required "cover" Field.image
myDocDecoder : Decoder Document MyDoc
myDocDecoder =
Prismic.map MyDoc
(Prismic.groupField "albums" albumDecoder)Decode a SliceZone.
Pass this function a Decoder Slice a from the Prismic.Slice module.
Slices can contain Fields and Groups, but not other Slices.
type alias MyDoc =
{ sections : List Section }
type Section
= -- The "my-content" slice has a non-repeating zone.
MyContent Field.StructuredText
| -- The "my-image-gallery" slice has a repeating zone.
MyImageGallery (List Field.ImageViews)
| -- The "my-links-section" slice has both non-repeating and repeating
-- zones.
MyLinksSection LinksSection
type alias LinksSection =
{ title : Field.StructuredText
, links : List Field.Link
}
myDocDecoder : Decoder Document MyDoc
myDocDecoder =
Prismic.map MyDoc
(Prismic.sliceZoneField "sections" sectionDecoder)
sectionDecoder : Decoder Slice Section
sectionDecoder =
Slice.oneOf
[ Slice.slice "my-content"
-- Decode the non-repeating zone and ignore the repeating zone.
(Group.field "text" Field.structuredText)
(Prismic.succeed ())
|> Prismic.map (\( content, _ ) -> MyContent content)
, Slice.slice "my-image-gallery"
-- Ignore the non-repeating zone and decode the repeating zone.
(Prismic.succeed ())
(Group.field "image" Field.image)
|> Prismic.map (\( _, images ) -> MyImageGallery images)
, Slice.slice "my-links-section"
-- Decode both the non-repeating and repeating zones.
(Group.field "title" Field.structuredText)
(Group.field "link" Field.link)
|> Prismic.map
(\( title, links ) -> MyLinksSection (LinksSection title links))
]Decode a required field.
Decode a field that might be missing.
Pipeline version of groupField.
Pipeline version of sliceZoneField.
Initialise the Prismic model with the URL for your Prismic repository. Save this in your application's Model somewhere.