ember-scoped-css 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/renameClass.js +5 -4
- package/src/replaceScopedClass.js +5 -4
- package/src/rewriteHbs.js +17 -24
package/package.json
CHANGED
package/src/renameClass.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const getPostfix = require('./getPostfix');
|
|
2
|
+
|
|
3
|
+
module.exports = function (className, projectCssPath) {
|
|
2
4
|
const classes = className.split(/\s+/);
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
.join(' ');
|
|
5
|
+
const postfix = getPostfix(projectCssPath);
|
|
6
|
+
return classes.map((c) => c + '_' + postfix).join(' ');
|
|
6
7
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
const recast = require('ember-template-recast');
|
|
2
2
|
const renameClass = require('./renameClass');
|
|
3
|
-
const getPostfix = require('./getPostfix');
|
|
4
3
|
|
|
5
4
|
module.exports = function (hbs, templatePath, basePath) {
|
|
6
5
|
let ast = recast.parse(hbs);
|
|
7
6
|
let stack = [];
|
|
8
7
|
const cssPath = templatePath.replace(/(\.hbs)?\.js$/, '.css');
|
|
9
|
-
const
|
|
8
|
+
const projectCssPath = cssPath; // cssPath.replace(basePath, '');
|
|
10
9
|
|
|
11
10
|
recast.traverse(ast, {
|
|
12
11
|
All: {
|
|
@@ -37,7 +36,9 @@ module.exports = function (hbs, templatePath, basePath) {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
if (cssClass) {
|
|
40
|
-
const textNode = recast.builders.text(
|
|
39
|
+
const textNode = recast.builders.text(
|
|
40
|
+
renameClass(cssClass, projectCssPath)
|
|
41
|
+
);
|
|
41
42
|
const parent = stack[stack.length - 1];
|
|
42
43
|
if (parent.type === 'AttrNode') {
|
|
43
44
|
parent.quoteType = '"';
|
|
@@ -54,7 +55,7 @@ module.exports = function (hbs, templatePath, basePath) {
|
|
|
54
55
|
const cssClass = node.params[0].value;
|
|
55
56
|
const textNode = recast.builders.literal(
|
|
56
57
|
'StringLiteral',
|
|
57
|
-
renameClass(cssClass,
|
|
58
|
+
renameClass(cssClass, projectCssPath)
|
|
58
59
|
);
|
|
59
60
|
return textNode;
|
|
60
61
|
}
|
package/src/rewriteHbs.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const recast = require('ember-template-recast');
|
|
2
|
-
const renameClass = require('./renameClass');
|
|
3
2
|
|
|
4
3
|
module.exports = function rewriteHbs(hbs, classes, tags, postfix) {
|
|
5
4
|
let ast = recast.parse(hbs);
|
|
@@ -8,13 +7,26 @@ module.exports = function rewriteHbs(hbs, classes, tags, postfix) {
|
|
|
8
7
|
AttrNode(node) {
|
|
9
8
|
if (node.name === 'class') {
|
|
10
9
|
if (node.value.type === 'TextNode' && node.value.chars) {
|
|
11
|
-
const
|
|
12
|
-
|
|
10
|
+
const newClasses = node.value.chars.split(' ').map((c) => {
|
|
11
|
+
if (c.trim() && classes.has(c.trim())) {
|
|
12
|
+
return c.trim() + '_' + postfix;
|
|
13
|
+
} else {
|
|
14
|
+
return c;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
node.value.chars = newClasses.join(' ');
|
|
13
19
|
} else if (node.value.type === 'ConcatStatement') {
|
|
14
20
|
for (let part of node.value.parts) {
|
|
15
21
|
if (part.type === 'TextNode' && part.chars) {
|
|
16
|
-
const
|
|
17
|
-
|
|
22
|
+
const newClasses = part.chars.split(' ').map((c) => {
|
|
23
|
+
if (c.trim() && classes.has(c.trim())) {
|
|
24
|
+
return c.trim() + '_' + postfix;
|
|
25
|
+
} else {
|
|
26
|
+
return c;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
part.chars = newClasses.join(' ');
|
|
18
30
|
}
|
|
19
31
|
}
|
|
20
32
|
}
|
|
@@ -35,25 +47,6 @@ module.exports = function rewriteHbs(hbs, classes, tags, postfix) {
|
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
},
|
|
38
|
-
|
|
39
|
-
HashPair(node) {
|
|
40
|
-
if (node.key === 'class') {
|
|
41
|
-
if (
|
|
42
|
-
node.value.type === 'SubExpression' &&
|
|
43
|
-
node.value.path.original === 'concat'
|
|
44
|
-
) {
|
|
45
|
-
for (let part of node.value.params) {
|
|
46
|
-
if (part.type === 'StringLiteral') {
|
|
47
|
-
const renamedClass = renameClass(part.value, postfix, classes);
|
|
48
|
-
part.value = renamedClass;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} else if (node.value.type === 'StringLiteral') {
|
|
52
|
-
const renamedClass = renameClass(node.value.value, postfix, classes);
|
|
53
|
-
node.value.value = renamedClass;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
50
|
});
|
|
58
51
|
|
|
59
52
|
let result = recast.print(ast);
|