Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxvipon/priv-js
Storage of blocks functions that generats BEMJSON
https://github.com/maxvipon/priv-js
Last synced: 9 days ago
JSON representation
Storage of blocks functions that generats BEMJSON
- Host: GitHub
- URL: https://github.com/maxvipon/priv-js
- Owner: maxvipon
- License: mit
- Created: 2014-08-22T06:23:01.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-09T13:20:06.000Z (almost 8 years ago)
- Last Synced: 2024-11-02T03:06:46.743Z (14 days ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 6
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# priv-js [![NPM version](https://badge.fury.io/js/priv-js.svg)](http://badge.fury.io/js/priv-js) [![Build Status](https://travis-ci.org/maxvipon/priv-js.svg)](https://travis-ci.org/maxvipon/priv-js) [![Coverage Status](https://coveralls.io/repos/maxvipon/priv-js/badge.png)](https://coveralls.io/r/maxvipon/priv-js)
Helper library, that contains functions and methods which will help you form final BEMJSON object in `*.priv.js` files.
## Install
```
npm install priv-js
```## Usage
```js
var Blocks = require('priv-js');
var blocks = new Blocks;
```All `*.priv.js` files exports function:
```js
// button.priv.js
module.exports = function(blocks) {
// ...
};
```This function expects to get instance of `priv-js` object in first argument:
```js
var privFile = require('button.priv.js');
privFile(blocks);
```## API
### Blocks()
Constructor. Returns `Blocks` instance, that have next methods:
### blocks.declare(name, object)
Declares object by name.
```javascript
blocks.declare('header', function(data) {
return {
block: 'header',
content: data.name
}
});blocks.declare('utils', {
format: function(number) { ... },
inverse: function(obj) { ... }
});
```
### blocks.has(name)Checks whether block is declared or not.
```javascript
blocks.declare('layout-vertical', function () {
return {
block: 'layout-vertical'
};
});
blocks.declare('layout', function () {
if (blocks.has('layout-vertical')) {
return blocks.exec('layout-vertical');
}return {
block: 'layout'
};
});
```### blocks.get(name)
Get declared object by name.
```javascript
blocks.declare('price', function(data) {
var utils = blocks.get('utils');
return {
block: 'price',
content: utils.format(data.price) + 'руб.'
}
});
```### blocks.exec(name, args...)
Executes stored function with `args`. If type of stored object is not a function, exception will be thrown. Returns result of execution.
```javascript
blocks.declare('item', function(data) {
return [
{ block: 'image' },
blocks.exec('price');
blocks.exec('debug', data.debug);
]
});
```## Tests
```
$ npm test
```