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

Default for bem-config and support for latest bem-walker #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# bem-tools-find

[![NPM version](http://img.shields.io/npm/v/bem-tools-find.svg?style=flat)](http://www.npmjs.org/package/bem-tools-find)
[![Build Status](https://travis-ci.org/bem-incubator/bem-tools-find.svg)](https://travis-ci.org/bem-incubator/bem-tools-find)
[![Coverage Status](https://coveralls.io/repos/bem-incubator/bem-tools-find/badge.svg?branch=master&service=github)](https://coveralls.io/github/bem-incubator/bem-tools-find?branch=master)
[![David](https://img.shields.io/david/bem-incubator/bem-tools-find.svg)](https://david-dm.org/bem-incubator/bem-tools-find)
[![Build Status](https://travis-ci.org/bem-contrib/bem-tools-find.svg)](https://travis-ci.org/bem-contrib/bem-tools-find)
[![Coverage Status](https://coveralls.io/repos/bem-contrib/bem-tools-find/badge.svg?branch=master&service=github)](https://coveralls.io/github/bem-contrib/bem-tools-find?branch=master)
[![David](https://img.shields.io/david/bem-contrib/bem-tools-find.svg)](https://david-dm.org/bem-contrib/bem-tools-find)

![Logo](./logo.ico)

Expand Down
15 changes: 12 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var Filter = require('./filter'),
var _ = require('lodash'),
Filter = require('./filter'),
Criteria = require('./criteria/criteria'),
CriteriaCollection = require('./criteria/criteria-collection');

Expand Down Expand Up @@ -49,7 +50,7 @@ exports.conditionsFromBEMItems = function(items) {
* @returns {Object}
*/
exports.initializeConfig = function(config) {
config = config.extended;
config = config.extended || {};

/**
* Returns list of levels
Expand Down Expand Up @@ -94,8 +95,16 @@ exports.getFiltersForConditions = function(conditions) {
return new Filter(criteria);
}),
apply = function(item) {
// Prepare BEM entity for check
Copy link
Member

Choose a reason for hiding this comment

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

давайте просто использовать новый формат везде вместо трансформаций?

Copy link
Author

Choose a reason for hiding this comment

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

Поправил тут: bf333b9

var prepareBemEntity = function(item) {
var bemEntity = _.omit(item, _.isObject);
return _.reduce(_.values(_.pick(item, _.isObject)), function(result, currentItem) {
return _.merge(result, currentItem);
}, bemEntity);
};

return filters.some(function(filter) {
return filter.apply(item);
return filter.apply(prepareBemEntity(item));
});
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"JSONStream": "^1.0.7",
"bem-config": "git://github.com/bem-incubator/bem-config.git",
"bem-naming": "^0.5.1",
"bem-walk": "0.0.4",
"bem-walk": "1.0.0-1",
"chalk": "^1.1.1",
"coa": "^1.0.1",
"flow-tostring": "^1.0.1",
Expand Down
26 changes: 26 additions & 0 deletions test/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,31 @@ describe('util', function() {
it('should return result with apply function', function() {
assert.instanceOf(util.getFiltersForConditions().apply, Function);
});

it('should prepare BEM entity before apply filter', function() {
var Filter = require('../../lib/filter');
sinon.stub(Filter.prototype, 'apply', function() {
return true;
});
var apply = util.getFiltersForConditions({
blocks: ['foo'],
levels: [],
modifiers: [],
elements: [],
techs: []
}).apply;
apply({
entity: {
block: 'foo'
},
tech: 'js'
});
assert.equal(Filter.prototype.apply.calledOnce, true);
assert.equal(Filter.prototype.apply.calledWith({
block: 'foo',
tech: 'js'
}), true);
Filter.prototype.apply.restore();
});
});
});