-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (29 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const postcss = require('postcss');
const skins = require('skins');
module.exports = postcss.plugin('revolutionize', function revolutionize(options) {
return function (css) {
options = options || {};
const theme = options.theme;
css.walkRules(function (rule) {
// a rule has been encountered
// get all keys from the conf object
Object.keys(options.selectors).forEach(type=>{
// get replacement configuration data
const selectors = options.selectors[type];
if(selectors) selectors.forEach(selector=>{
// if the selectors are the same, load the properties needing to be injected into this rule
if(rule.selector == selector){
try {
// grab rules from a specified skin for the selector defined by Object.keys(options.selectors).
const response = skins({theme, type});
// append the properties found under the rule in the theme being injected.
rule.append(response);
} catch(err){
console.log(err)
}
} // if rule matches selector
}) // for each selector
}) // all keys in options.selectors
}); // walk rules
}
});