Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

Add support for @bem/cell #11

Merged
merged 4 commits into from
Jan 25, 2017
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
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@

## Usage
```js
var entity = {
block: 'b1',
elem: 'e1',
modName: 'm1',
modVal: 'v1'
};

var tech = 'js';
var BemCell = require('@bem/cell'),
BemEntityName = require('@bem/entity-name');

var atom = new BemCell(
{
entity: new BemEntityName({
block: 'b1',
elem: 'e1',
mod: {name: 'm1', val: 'v1'}
}),
tech: 'js'
}
);

var options = {
naming: {
Expand All @@ -25,7 +30,9 @@ var options = {
}
}; // this is default value

require('bem-fs-scheme')('nested').path(entity, tech, options); // b1/__e1/_m1/b1__e1_m1_v1.js
var bemFs = require('bem-fs-scheme')('nested')

bemFs.path(atom, options); // b1/__e1/_m1/b1__e1_m1_v1.js
```

License
Expand Down
21 changes: 18 additions & 3 deletions lib/schemes/flat.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
var bemNaming = require('bem-naming');
var path = require('path'),
assert = require('assert'),
BemCell = require('@bem/cell'),
bemNaming = require('bem-naming');

module.exports = {
path: function(entity, tech, options) {
path: function(cell, options) {
assert(BemCell.isBemCell(cell),
'Provide instance of [@bem/cell](https://github.com/bem-sdk/bem-cell).'
)

options || (options = {});

var layer = '';
var tech = cell.tech;
var entity = cell.entity;

cell.layer && (layer = cell.layer);

var naming = bemNaming(options.naming);

return naming.stringify(entity) + '.' + tech;
return path.join(layer,
naming.stringify(entity) + (tech ? '.' + tech : ''));
}
};
28 changes: 20 additions & 8 deletions lib/schemes/nested.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
var path = require('path'),
assert = require('assert'),
BemCell = require('@bem/cell'),
bemNaming = require('bem-naming');

module.exports = {
path: function(entity, tech, options) {
path: function(cell, options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should throw an exception if there isn't BemCell?

assert(BemCell.isBemCell(cell),
'Provide instance of [@bem/cell](https://github.com/bem-sdk/bem-cell).'
)

options || (options = {});
var naming = bemNaming(options.naming),
elemFolder = naming.elemDelim + entity.elem,
modFolder = naming.modDelim + entity.modName,
folder = path.join(entity.block,
entity.elem ? elemFolder : '',
entity.modName ? modFolder : '');

var layer = '';
var tech = cell.tech;
var entity = cell.entity;
var modName = Object(entity.mod).name;

cell.layer && (layer = cell.layer);

var naming = bemNaming(options.naming);
var folder = path.join(layer, entity.block,
entity.elem ? (naming.elemDelim + entity.elem) : '',
modName ? (naming.modDelim + modName) : '');

return path.join(folder,
naming.stringify(entity) + '.' + tech);
naming.stringify(entity) + (tech ? '.' + tech : ''));
}
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
},
"homepage": "https://github.com/bem-sdk/bem-fs-scheme#readme",
"dependencies": {
"@bem/cell": "^0.2.1",
"bem-naming": "^1.0.1"
},
"devDependencies": {
"@bem/entity-name": "^1.1.0",
"chai": "^3.5.0",
"eslint": "^3.1.1",
"eslint-config-pedant": "^0.7.0",
Expand Down
Loading