ember-scoped-css 0.2.1 → 0.2.3
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/getPostfix.js +3 -5
- package/src/renameClass.js +3 -1
- package/src/rewriteHbs.js +24 -9
package/package.json
CHANGED
package/src/getPostfix.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const md5 = require('blueimp-md5');
|
|
2
|
+
const path = require('path');
|
|
2
3
|
|
|
3
4
|
module.exports = function (cssFileName) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// }
|
|
7
|
-
|
|
8
|
-
return 'e' + md5(cssFileName).substring(0, 8);
|
|
5
|
+
const relativePath = path.relative(process.cwd(), cssFileName);
|
|
6
|
+
return 'e' + md5(relativePath).substring(0, 8);
|
|
9
7
|
};
|
package/src/renameClass.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const getPostfix = require('./getPostfix');
|
|
2
2
|
|
|
3
3
|
module.exports = function (className, projectCssPath) {
|
|
4
|
-
|
|
4
|
+
const classes = className.split(/\s+/);
|
|
5
|
+
const postfix = getPostfix(projectCssPath);
|
|
6
|
+
return classes.map((c) => c + '_' + postfix).join(' ');
|
|
5
7
|
};
|
package/src/rewriteHbs.js
CHANGED
|
@@ -5,16 +5,31 @@ module.exports = function rewriteHbs(hbs, classes, tags, postfix) {
|
|
|
5
5
|
|
|
6
6
|
recast.traverse(ast, {
|
|
7
7
|
AttrNode(node) {
|
|
8
|
-
if (node.name === 'class'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
if (node.name === 'class') {
|
|
9
|
+
if (node.value.type === 'TextNode' && node.value.chars) {
|
|
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
|
+
});
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
node.value.chars = newClasses.join(' ');
|
|
19
|
+
} else if (node.value.type === 'ConcatStatement') {
|
|
20
|
+
for (let part of node.value.parts) {
|
|
21
|
+
if (part.type === 'TextNode' && part.chars) {
|
|
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(' ');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
18
33
|
}
|
|
19
34
|
},
|
|
20
35
|
|