main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | function cssToTree (tree, css, selector, prelude) {
|
---|
2 | var declarations = {};
|
---|
3 | var hasDeclarations = false;
|
---|
4 | var key, value;
|
---|
5 |
|
---|
6 | for (key in css) {
|
---|
7 | value = css[key];
|
---|
8 | if (typeof value !== 'object') {
|
---|
9 | hasDeclarations = true;
|
---|
10 | declarations[key] = value;
|
---|
11 | }
|
---|
12 | }
|
---|
13 |
|
---|
14 | if (hasDeclarations) {
|
---|
15 | if (!tree[prelude]) tree[prelude] = {};
|
---|
16 | tree[prelude][selector] = declarations;
|
---|
17 | }
|
---|
18 |
|
---|
19 | for (key in css) {
|
---|
20 | value = css[key];
|
---|
21 | if (typeof value === 'object') {
|
---|
22 | if (key[0] === '@') {
|
---|
23 | cssToTree(tree, value, selector, key);
|
---|
24 | } else {
|
---|
25 | var hasCurrentSymbol = key.indexOf('&') > -1;
|
---|
26 | var selectorParts = selector.split(',');
|
---|
27 | if (hasCurrentSymbol) {
|
---|
28 | for (var i = 0; i < selectorParts.length; i++) {
|
---|
29 | selectorParts[i] = key.replace(/&/g, selectorParts[i]);
|
---|
30 | }
|
---|
31 | } else {
|
---|
32 | for (var i = 0; i < selectorParts.length; i++) {
|
---|
33 | selectorParts[i] = selectorParts[i] + ' ' + key;
|
---|
34 | }
|
---|
35 | }
|
---|
36 | cssToTree(tree, value, selectorParts.join(','), prelude);
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 | };
|
---|
41 |
|
---|
42 | exports.cssToTree = cssToTree;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.