npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-data-prismic

v0.3.0

Published

Ember Data adapter for the Prismic API

Downloads

3

Readme

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

  import PrismicAdapter from 'ember-data-prismic/adapters/prismic';
  export default PrismicAdapter.extend({});
Models

  //models/example.js
  import PrismicDocument from 'ember-data-prismic/models/prismic-document';
  import attr from 'ember-data/attr';

  // 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

  export default PrismicDocument.extend({
    // your prismic model fields
    date: attr('date') // a prismic date field
    description: attr() // this keeps a prismic object in tact so we can use our template helpers for displaying HTML or text
  });
In Templates

  {{prismic-html model.description}} // displays html
  {{prismic-text model.description}} // converts the rich text to text


  {{#each model.slices as |slice|}}
    {{#if (eq slice.sliceType 'text')}}
      {{prismic-html slice.textBody}}
    {{/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

import PrismicService from 'ember-data-prismic/services/prismic';

export default PrismicService.extend({
  urlFor(doc) {
    // default: this.router.urlFor(doc.type, doc.uid);
    // insert your custom logic here
  }
});
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.route('post', {path: "post/:post_id"});

  // routes/post.js
  model(params) {
    return this.store.findRecord('post', params.post_id);
  },

  afterModel(model /*, transition */) {
    this.transitionTo('post', model.get('id')); // 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.