Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add exclude option to avoid prefixing some selectors
  • Loading branch information
Nicolas Dupont committed May 26, 2015
commit 0ea6367011435af03a1e14bde85a56b2926ddacd
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ var out = postcss().use(prefix({
console.log(out)
```

## Options

It's possible to avoid prefixing some selectors with the option `exclude` which take an array of selectors in parameter.

```js
var css = '.a {} \nhtml{} \n.b{}'

var prefix = require('postcss-prefix-selector')

var out = postcss().use(prefix({
prefix: '.some-selector ', // <--- notice the traililng space!
exclude: ['html', '.b']
})).process(css).css

console.log(out)
```

[gitter-image]: https://badges.gitter.im/jonathanong/postcss-prefix-selector.png
[gitter-url]: https://gitter.im/jonathanong/postcss-prefix-selector
[npm-image]: https://img.shields.io/npm/v/postcss-prefix-selector.svg?style=flat-square
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = function (options) {
// pretty sure this splitting breaks for certain selectors
var selectors = rule.selector.split(/\s*,\s*/g)
rule.selector = selectors.map(function (selector) {
if (options.exclude && ~options.exclude.indexOf(selector)) {
return selector;
}
return prefix + selector
}).join(', ')
})
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ it('should prefix a group of selectors', function () {
assert(~out.indexOf('.hello .a'))
assert(~out.indexOf('.hello .b'))
})

it('should avoid prefixing excluded selectors', function () {
var out = postcss().use(prefix({
prefix: '.hello ',
exclude: ['body', '.a *:not(.b)']
})).process('.a, .b {}\n body {}\n .a *:not(.b) {}\n .c {}').css

assert(~out.indexOf('.hello .a'))
assert(~out.indexOf('.hello .b'))
assert(~out.indexOf('.hello .c'))
assert(out.indexOf('.hello body'))
assert(out.indexOf('.hello .a *:not(.b)'))
})