Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] ES2016 locales #64

Merged
merged 8 commits into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .istanbul.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
instrumentation:
root: lib
root: src
40 changes: 26 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,41 @@
"description": "An extension for using roots with the API-driven Contentful CMS",
"version": "0.0.9",
"author": "Carrot Creative",
"ava": {
"serial": true,
"verbose": true,
"require": [
"babel-core/register",
"coffee-script/register"
]
},
"bugs": {
"url": "https://github.com/carrot/roots-contentful/issues"
},
"dependencies": {
"ava": "^0.9.2",
"babel-runtime": "^6.3.13",
"contentful": "^2.1.0",
"contentful": "^2.1.1",
"deepcopy": "^0.6.1",
"pluralize": "^1.2.1",
"roots-util": "0.2.x",
"underscore.string": "^3.2.2"
"underscore.string": "^3.2.3"
},
"devDependencies": {
"ava": "^0.9.1",
"babel-cli": "^6.3.15",
"babel-core": "^6.3.26",
"ava": "^0.10.0",
"babel-cli": "^6.4.5",
"babel-core": "^6.4.5",
"babel-eslint": "^5.0.0-beta6",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015-node5": "^1.1.1",
"babel-plugin-add-module-exports": "^0.1.3-alpha",
"babel-plugin-transform-runtime": "^6.4.3",
"babel-preset-es2015-node5": "^1.1.2",
"babel-preset-stage-0": "^6.3.13",
"babel-runtime": "^6.3.19",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.6",
"husky": "^0.10.2",
"mockery": "1.4.x",
"nyc": "^5.2.0",
"nyc": "^5.3.0",
"roots": "3.1.0",
"snazzy": "^2.0.1",
"standard": "^5.4.1"
Expand Down Expand Up @@ -62,22 +72,24 @@
"scripts": {
"build": "babel src -d lib",
"coverage": "nyc report --reporter=lcov",
"coveralls": "coveralls < coverage/lcov.info",
"debug-test": "NODE_DEBUG=request npm run test -- --serial --verbose --fail-fast",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"debug-test": "npm run test -- --fail-fast",
"lint": "standard --verbose | snazzy",
"postpublish": "git push --follow-tags",
"posttest": "node test/_teardown.js",
"prebuild": "npm test",
"precommit": "npm run lint -s",
"precoverage": "npm run test",
"precoveralls": "npm run coverage",
"prerelease": "npm run build",
"pretest": "npm run lint -s && node test/_setup.js",
"release": "npm publish",
"test": "nyc ava --require babel-core/register --require coffee-script/register"
"test": "nyc ava --verbose --serial --require babel-core/register --require coffee-script/register"
},
"standard": {
"parser": "babel-eslint",
"ignore": ["test/_setup.js", "test/_teardown.js"]
"ignore": [
"test/_setup.js",
"test/_teardown.js"
]
}
}
46 changes: 37 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports =
contentful
access_token: 'YOUR_ACCESS_TOKEN'
space_id: 'xxxxxx'
locale: 'tlh'
locales_prefix:
tlh: 'klingon_'
content_types:
blog_posts:
id: 'xxxxxx'
Expand Down Expand Up @@ -76,15 +79,17 @@ If a `template` option is defined for a Content Type in `app.coffee`, roots will

Contentful's [documentation](https://www.contentful.com/developers/documentation/content-delivery-api/#getting-entry) shows the API response when fetching an entry. Your content fields are nested in a `fields` key on the `entry` object. As a convenience, the entry object roots-contentful makes available in your views will have the `fields` key's value set one level higher on the object. System metadata remains accessible on the `sys` key and roots-contentful will raise an error if you have a field named `sys`. Inside your views, the entry object will have this structure:

```json
"entry": {
"title": "Wow. Such title. Much viral",
"author": "The Doge of Venice"
# ... the rest of the fields
"sys": {
"type": "Entry",
"id": "cat"
# ...
```js
{
"entry": {
"title": "Wow. Such title. Much viral",
"author": "The Doge of Venice"
// ... the rest of the fields
"sys": {
"type": "Entry",
"id": "cat"
# ...
}
}
}
```
Expand All @@ -109,6 +114,29 @@ Required. The space ID containing the content you wish to retrieve.

Optional. (Boolean) Allows you use the Contentful Preview API. Also able to be accessed by setting the environment variable `CONTENTFUL_ENV` to `"develop"` (preview api) or `"production"` (default cdn).

#### locales
Locales allow you to request your content in a different language, `tlh` is Klingon.

##### Global locale
Optional. (String or Array) Defines locale for all content_types.
String: `'tlh'`
Array: `['en-es', 'tlh']`
Wildcard: `'*'` - grabs all locales from contentful

##### content_type specific locale
Optional. (String) Define content_types locale, will override global locale. Add `locale: 'tlh'` to any of your content types and you'll retrieve that post in the specific locale.

#### locales_prefix
Optional. (Object) Defines the prefix given to a group of locales.

```
locales_prefix:
'tlh': 'klingon_'
'en-es': 'spanish_'
```

Lets say you have 3 global locales defined, `['tlh', 'en-us', 'en-es']`, and above is our defined locales_prefix. Since we did not declare `'en-us'` you can access it with `contentful.en_us_blog_posts`. Similarly you can access each preix according to what you've set in the object above. `'tlh'` would be accessible by `contentful.klingon_blog_posts` and `en-es` by `contentful.spanish_blog_posts`.

#### content_types

An object whose key-value pairs correspond to a Contentful Content Types. Each
Expand Down
Loading