-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlstyle.js
61 lines (47 loc) · 1.19 KB
/
htmlstyle.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
**
** The author disclaims copyright to this source code.
**
*/
var CSSRule = require('./cssrule');
function HTMLStyle(options){ //HTML CSS STYLE
var _S = this;
_S.options = null;
_S.rules = [];
_S.addRule = function(selector){
var count = _S.rules.length;
var n = new CSSRule({'selector':selector});
_S.rules.push(n);
return _S.rules[count];
}
try{
if(typeof options != 'undefined'){
_S.options = options;
//check for selectors and rules
Object.keys(options).forEach(function(key) { //expected format // {"selector":{"rule1":"value1","rule2":"value2"}}
var selector = key;
var nR = _S.addRule(selector);
var rules = options[key];
console.log("[debug] selector:"+selector);
Object.keys(rules).forEach(function(r){
var ar = rules[r];
console.log("[debug] "+r+":"+ar);
nR.addDeclaration(r,ar);
});
});
}
} catch (err){
console.log("[error] " + err);
}
_S.toString = function(inline = false){
var out = '';
if(_S.rules.length > 0){
for(i=0;i<_S.rules.length;i++){
var rule = _S.rules[i];
out += rule.toString(inline);
}
}
return out;
}
}
module.exports = HTMLStyle;