From 0ea6367011435af03a1e14bde85a56b2926ddacd Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Tue, 26 May 2015 19:25:49 +0200 Subject: [PATCH 1/2] Add `exclude` option to avoid prefixing some selectors --- README.md | 17 +++++++++++++++++ index.js | 3 +++ test/test.js | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/README.md b/README.md index 519935a..e0cc909 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index 72628ea..4b283a6 100644 --- a/index.js +++ b/index.js @@ -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(', ') }) diff --git a/test/test.js b/test/test.js index 87a1a99..75a1811 100644 --- a/test/test.js +++ b/test/test.js @@ -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)')) +}) From 9d7f3fd5bb7fbd1fac69d981d12c263c899f19ef Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Tue, 26 May 2015 19:36:28 +0200 Subject: [PATCH 2/2] Bump version number to 1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 141ac87..6b2708a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "postcss-prefix-selector", "description": "Prefix all CSS rules with a selector", - "version": "1.1.0", + "version": "1.2.0", "author": "Jonathan Ong (http://jongleberry.com)", "license": "MIT", "repository": "jonathanong/postcss-prefix-selector",