Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshgillies/node-matrix-assets
A DSL for creating Squiz Matrix asset trees in JavaScript!
https://github.com/joshgillies/node-matrix-assets
Last synced: 5 days ago
JSON representation
A DSL for creating Squiz Matrix asset trees in JavaScript!
- Host: GitHub
- URL: https://github.com/joshgillies/node-matrix-assets
- Owner: joshgillies
- License: mit
- Created: 2015-09-23T10:28:22.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-10T23:49:10.000Z (over 8 years ago)
- Last Synced: 2024-10-19T00:15:12.254Z (27 days ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-matrix-assets
A DSL for creating Squiz Matrix asset trees in JavaScript!
Inspiration for this module is weighted heavily around the excellent work by [Dominic Tarr] with [hyperscript].
[![Build Status](https://travis-ci.org/joshgillies/node-matrix-assets.svg)](https://travis-ci.org/joshgillies/node-matrix-assets)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)## Install
`npm install node-matrix-assets`
## Example
```js
var asset = require('node-matrix-assets')
var getAssetById = asset.getAssetByIdvar tree = asset('folder', { name: 'Sites', links: 'type_2' },
asset('site', { id: 'site', name: 'My Site' },
asset('page_standard', { name: 'Home', links: { index: getAssetById('site') } },
asset('bodycopy', { links: 'type_2', dependant: '1', exclusive: '1' },
asset('bodycopy_div', { links: 'type_2', dependant: '1' },
asset('content_type_wysiwyg', { links: 'type_2', dependant: '1', exclusive: '1' })
)
)
)
)
)
```## API
### asset
`node-matrix-assets` provides an API for generating structured asset trees via `require('node-matrix-assets')`.
#### asset(type, properties={}, children...)
The `type` argument is _required_ and accepts a string representing a valid Squiz Matrix asset type.
The `properties` argument accepts an object used to configure the returned asset definition.
With the exception of a few optional special cases for the `properties` objects
keys/values will change depending on the type of asset you're creating.#### properties.id
Assigns a unique identifier to an asset. Typically used in conjunction with [asset.getAssetById].
#### properties.links
Default: `'type_1'`. Either a string representing a valid link type (eg. `'type_2'`),
an Array containing String or Object key/value pairs `['type_2', { notice: 'value' }]`,
or an Object of key/value pairs `{ type_2: true, notice: 'value' }`.Defining `children` is accomplished through one of the following:
* As an array containing assets `asset('type_code', [asset(...), asset(...), asset(...)])`,
* or as arguments `asset('type_code', asset(...), asset(...), asset(...))`.#### asset.getAssetById(id)
[asset.getAssetById]: #assetgetassetbyididThe `id` argument accepts a string representing a previously defined asset `property.id`:
```js
var myThing = asset('type_code', { id: 'myThing' })asset.getAssetById('myThing')
```or a `key` representing a valid asset key:
```js
var myThing = asset('type_code')asset.getAssetById(myThing.key)
```## License
MIT
[Dominic Tarr]: https://github.com/dominictarr
[hyperscript]: https://github.com/dominictarr/hyperscript