Skip to content

Commit

Permalink
remove default transform from readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Feb 3, 2018
1 parent 3fb788d commit 9b19b29
Showing 1 changed file with 27 additions and 44 deletions.
71 changes: 27 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ In order to pass the data correctly, you must pass `spike-contentful` an object,

Once included, it will expose a `contentful` local to your markup (`.sgr`, `.html`, etc...) files, which you can use to iterate through your content types. Based on the example above, the `posts` content type will be accessible through `contentful.posts`, as such:


```jade
// a template file
ul
each(loop='post of contentful.posts')
li {{ JSON.stringify(post) }}
```

For the sugar-free
``` html

```html
<ul>
<each loop="post of contentful.blog">
<li>{{ JSON.stringify(post) }}</li>
Expand Down Expand Up @@ -118,7 +119,7 @@ new Contentful({

### Transforms

Contentful returns a lot of associated data and, as a result, we include a way to clean it up. You also have the ability to pass your own custom `transform` option to each content type allowing you to transform the data however you like before it's sent to your views.
Contentful returns a lot of associated data and, as a result, we give you the ability to pass your own custom `transform` option to each content type allowing you to transform the data however you like before it's sent to your views.

```js
new Contentful({
Expand All @@ -129,7 +130,7 @@ new Contentful({
{
name: 'posts',
id: '633fTeiMaxxxxxxxxx',
transform: (post) => {
transform: post => {
// do your transformation here...
return post
}
Expand All @@ -138,30 +139,6 @@ new Contentful({
})
```

This plugin ships with a default transform function that will run some basic cleanup. However, be warned that the transform will enter an infinite loop and crash if there are circular references within the data, which is not an uncommon occurance, so please be very careful utilizing this transform. To enable our default transform, you can pass `true` as such:

```js
new Contentful({
addDataTo: locals,
accessToken: 'xxx',
spaceId: 'xxx',
contentTypes: [
{
name: 'posts',
id: '633fTeiMaxxxxxxxxx',
transform: true
}
]
})
```

If you'd like to use our default transform outside of the library, this is also available as an export. For example, you could include it and use it with client-side JS responses.

```js
const Contentful = require('spike-contentful')
console.log(Contentful.transform)
```

### Templates

Using the template option allows you to write objects returned from Contentful to single page templates. For example, if you are trying to render a blog as static, you might want each post returned from the API to be rendered as a single page by itself.
Expand All @@ -173,14 +150,18 @@ new Contentful({
addDataTo: locals,
accessToken: 'xxx',
spaceId: 'xxx',
contentTypes: [{
name: 'posts',
id: '633fTeiMaxxxxxxxxx',
template: {
path: 'templates/post.html',
output: (post) => { return `posts/${post.id}.html` }
contentTypes: [
{
name: 'posts',
id: '633fTeiMaxxxxxxxxx',
template: {
path: 'templates/post.html',
output: post => {
return `posts/${post.id}.html`
}
}
}
}]
]
})
```

Expand All @@ -199,10 +180,12 @@ new Contentful({
addDataTo: locals,
accessToken: 'xxx',
spaceId: 'xxx',
contentTypes: [{
name: 'posts',
id: '633fTeiMaxxxxxxxxx'
}],
contentTypes: [
{
name: 'posts',
id: '633fTeiMaxxxxxxxxx'
}
],
json: 'data.json'
})
```
Expand Down Expand Up @@ -240,11 +223,11 @@ By default, this plugin will only fetch data once when you start your watcher, f

To run the tests locally, you'll need to add a `test/.env` with your name and token values:

- `cp test/.env.sample test/.env`
- `accessToken` is derived from "APIs" > "Content Delivery API Keys" in the Contentful admin section.
- `spaceId` is also derived from "APIs" > "Content Delivery API Keys" in the Contentful admin section.
* `cp test/.env.sample test/.env`
* `accessToken` is derived from "APIs" > "Content Delivery API Keys" in the Contentful admin section.
* `spaceId` is also derived from "APIs" > "Content Delivery API Keys" in the Contentful admin section.

### License & Contributing

- Details on the license [can be found here](LICENSE.md)
- Details on running tests and contributing [can be found here](CONTRIBUTING.md)
* Details on the license [can be found here](LICENSE.md)
* Details on running tests and contributing [can be found here](CONTRIBUTING.md)

0 comments on commit 9b19b29

Please sign in to comment.