Skip to content

Commit

Permalink
Merge pull request #140 from bem/issue-138
Browse files Browse the repository at this point in the history
Add ignoring of duplicate 'css' classes
  • Loading branch information
eGavr committed Mar 16, 2016
2 parents fa61856 + 88dc255 commit d322204
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ For example, the following two code samples will be considered to be equivalent:
```

```html
<span class=" cd ab bc">Text</span>
<span class=" cd ab bc bc">Text</span>
```

**CAUTION!**<br>
Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
```

```html
<span class=" cd ab bc">Text</span>
<span class=" cd ab bc bc">Text</span>
```

**ВНИМАНИЕ!**<br>
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ function sortCssClasses(attrs) {
function _sortCssClassesValues(cssClasses) {
var classList = (cssClasses || '').split(' ');

return _.filter(classList).sort().join(' ');
return _(classList)
.filter()
.uniq()
.sort()
.join(' ');
}

var classIndexes = _getIndexesInArray(attrs, 'class');
Expand Down
2 changes: 1 addition & 1 deletion test/differ/fixtures/second/sort-classes.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<input class=" cd ab bc">
<input class=" cd ab bc bc">
4 changes: 3 additions & 1 deletion test/unit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ describe('\'utils\'', function () {
{ name: 'class', value: ' b c a' },
{ name: 'blah', value: 'b c a' },
{ name: 'class', value: '' },
{ name: 'class', value: 'a a a' }
],
output = [
{ name: 'class', value: 'a b c' },
{ name: 'blah', value: 'b c a' },
{ name: 'class', value: '' }
{ name: 'class', value: '' },
{ name: 'class', value: 'a' }
];

utils.sortCssClasses(input).must.be.eql(output);
Expand Down

0 comments on commit d322204

Please sign in to comment.