Skip to content

Instantly share code, notes, and snippets.

@valentin-radulescu-hs
Created October 1, 2015 12:36
Show Gist options
  • Save valentin-radulescu-hs/9742bbb784da54dafd0a to your computer and use it in GitHub Desktop.
Save valentin-radulescu-hs/9742bbb784da54dafd0a to your computer and use it in GitHub Desktop.
PostCSS Selector Prefixer
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-namespace-selectors',
namespaceSelectors);
function namespaceSelectors(options) {
var options = options || {};
return function(root) {
root.walkRules(function transformRule(rule) {
if (!rule.selectors) {
return rule;
}
rule.selectors = rule.selectors.map(function transformSelector(selector) {
return prefixSelector(options, selector);
});
});
}
}
function prefixSelector(options, selector) {
if (!options.prefix) {
return selector;
} else if (options.exclude && options.exclude.indexOf(selector) >= 0) {
return selector;
}
return options.prefix + ' ' + selector;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment