ember-scoped-css 0.2.0 → 0.2.2

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.0",
3
+ "version": "0.2.2",
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
  };
@@ -4,9 +4,7 @@ const renameClass = require('./renameClass');
4
4
  module.exports = function (hbs, templatePath, basePath) {
5
5
  let ast = recast.parse(hbs);
6
6
  let stack = [];
7
- const cssPath = templatePath
8
- .replace(basePath, '')
9
- .replace(/(\.hbs)?(\.js)?/, '.css');
7
+ const cssPath = templatePath.replace(/(\.hbs)?\.js$/, '.css');
10
8
  const projectCssPath = cssPath; // cssPath.replace(basePath, '');
11
9
 
12
10
  recast.traverse(ast, {
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