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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-scoped-css",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
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
- // if (cssFileName.includes('/')) {
5
- // throw new Error('cssFileName should not contain /');
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
  };
@@ -1,5 +1,7 @@
1
1
  const getPostfix = require('./getPostfix');
2
2
 
3
3
  module.exports = function (className, projectCssPath) {
4
- return className + '_' + getPostfix(projectCssPath);
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' && node.value.chars) {
9
- const newClasses = node.value.chars.split(' ').map((c) => {
10
- if (c.trim() && classes.has(c.trim())) {
11
- return c.trim() + '_' + postfix;
12
- } else {
13
- return c;
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
- node.value.chars = newClasses.join(' ');
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