Created
October 1, 2015 12:36
-
-
Save valentin-radulescu-hs/9742bbb784da54dafd0a to your computer and use it in GitHub Desktop.
PostCSS Selector Prefixer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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