ember-scoped-css 0.2.5 → 0.2.6
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 +12 -5
- package/src/replaceScopedClass.js +4 -5
- package/src/rewriteHbs.js +5 -17
package/package.json
CHANGED
package/src/renameClass.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = function (className, projectCssPath) {
|
|
1
|
+
module.exports = function (className, postfix, classesInCss) {
|
|
4
2
|
const classes = className.split(/\s+/);
|
|
5
|
-
const
|
|
6
|
-
|
|
3
|
+
const renamedClasses = classes
|
|
4
|
+
.filter((c) => c)
|
|
5
|
+
.map((c) => c.trim())
|
|
6
|
+
.map((c) => (!classesInCss || classesInCss.has(c) ? c + '_' + postfix : c))
|
|
7
|
+
.join(' ');
|
|
8
|
+
|
|
9
|
+
const renamedWithPreservedSpaces = className.replace(
|
|
10
|
+
className.trimStart().trimEnd(),
|
|
11
|
+
renamedClasses
|
|
12
|
+
);
|
|
13
|
+
return renamedWithPreservedSpaces;
|
|
7
14
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const recast = require('ember-template-recast');
|
|
2
2
|
const renameClass = require('./renameClass');
|
|
3
|
+
const getPostfix = require('./getPostfix');
|
|
3
4
|
|
|
4
5
|
module.exports = function (hbs, templatePath, basePath) {
|
|
5
6
|
let ast = recast.parse(hbs);
|
|
6
7
|
let stack = [];
|
|
7
8
|
const cssPath = templatePath.replace(/(\.hbs)?\.js$/, '.css');
|
|
8
|
-
const
|
|
9
|
+
const postfix = getPostfix(cssPath);
|
|
9
10
|
|
|
10
11
|
recast.traverse(ast, {
|
|
11
12
|
All: {
|
|
@@ -36,9 +37,7 @@ module.exports = function (hbs, templatePath, basePath) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
if (cssClass) {
|
|
39
|
-
const textNode = recast.builders.text(
|
|
40
|
-
renameClass(cssClass, projectCssPath)
|
|
41
|
-
);
|
|
40
|
+
const textNode = recast.builders.text(renameClass(cssClass, postfix));
|
|
42
41
|
const parent = stack[stack.length - 1];
|
|
43
42
|
if (parent.type === 'AttrNode') {
|
|
44
43
|
parent.quoteType = '"';
|
|
@@ -55,7 +54,7 @@ module.exports = function (hbs, templatePath, basePath) {
|
|
|
55
54
|
const cssClass = node.params[0].value;
|
|
56
55
|
const textNode = recast.builders.literal(
|
|
57
56
|
'StringLiteral',
|
|
58
|
-
renameClass(cssClass,
|
|
57
|
+
renameClass(cssClass, postfix)
|
|
59
58
|
);
|
|
60
59
|
return textNode;
|
|
61
60
|
}
|
package/src/rewriteHbs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const recast = require('ember-template-recast');
|
|
2
|
+
const renameClass = require('./renameClass');
|
|
2
3
|
|
|
3
4
|
module.exports = function rewriteHbs(hbs, classes, tags, postfix) {
|
|
4
5
|
let ast = recast.parse(hbs);
|
|
@@ -7,26 +8,13 @@ module.exports = function rewriteHbs(hbs, classes, tags, postfix) {
|
|
|
7
8
|
AttrNode(node) {
|
|
8
9
|
if (node.name === 'class') {
|
|
9
10
|
if (node.value.type === 'TextNode' && node.value.chars) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
return c.trim() + '_' + postfix;
|
|
13
|
-
} else {
|
|
14
|
-
return c;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
node.value.chars = newClasses.join(' ');
|
|
11
|
+
const renamedClass = renameClass(node.value.chars, postfix, classes);
|
|
12
|
+
node.value.chars = renamedClass;
|
|
19
13
|
} else if (node.value.type === 'ConcatStatement') {
|
|
20
14
|
for (let part of node.value.parts) {
|
|
21
15
|
if (part.type === 'TextNode' && part.chars) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
return c.trim() + '_' + postfix;
|
|
25
|
-
} else {
|
|
26
|
-
return c;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
part.chars = newClasses.join(' ');
|
|
16
|
+
const renamedClass = renameClass(part.chars, postfix, classes);
|
|
17
|
+
part.chars = renamedClass;
|
|
30
18
|
}
|
|
31
19
|
}
|
|
32
20
|
}
|