Ember Data Adapter For Prismic CMS
This is an ember data adapter for the V2 Prismic CMS. There are many incomplete ember/prismic addons trying to get ember to integrate easily into Prismic and none of them seemed to do the job. This one actually works and is being used and developed on multiple projects. Get in touch if you've got problems.
Usage
Install
ember install ember-data-prismic
Environment
//config/environment.js prismic: apiEndpoint: YOUR_PRISMIC_API_ENDPOINT // Make sure this is the v2 API url accessToken: YOUR_PRISMIC_ACCESS_TOKEN
Adapter
// adapters/application.js ; ;
Models
//models/example.js ; ; // PrismicDocument contains these fields // recordId : attr('string'), // recordType : attr('string'), // uid : attr('string'), // tags : attr(), // slugs : attr(), // alternateLanguages : attr(), // firstPublicationDate: attr('date'), // lastPublicationDate : attr('date'), // body : attr(), // linkedDocuments : attr(), // slices // computed field of slice objects ;
In Templates
prismic-html modeldescription // displays html prismic-text modeldescription // converts the rich text to text #each modelslices as |slice| #if eq slicesliceType 'text' prismic-html slicetextBody /if /each
Resolution of Document Links
Prismic allows you to link to other prismic documents within a rich text field. When that data arrives to ember and is rendered using the prismic-html
helper, it will try to resolve the link by assuming the document type
is the same as the name of the route and the id is the uid
field. This can be overriden if needed by extending the PrismicService in your application
; ;
Routes and URLS
The Data Adapter's primary key is set to 'uid', so if your prismic model has a UID that's what will request the record and what the model's id will be set to. If findRecord
doesn't find anything by looking for the UID, it will request by the internal prismic id.
//router.js this; // routes/post.js { return thisstore; } { this; // if there are multiple slugs this will transition to the correct url (the UID) }
Still to do
-
Pagination support
-
Advanced queries
-
Make a generator to create a prismic backed model, along with the ids inherited and a comment of the inherited fields
-
Make the slices real models that the adapter inserts into the store. Maybe by default if the slice on prismic is named "gallery", the data adapter will automatically look for a model called "prismic-slice-gallery"?
This project is licensed under the MIT License.