ember-scoped-css 0.2.2 → 0.2.4

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.2",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
@@ -1,5 +1,6 @@
1
- const getPostfix = require('./getPostfix');
2
-
3
- module.exports = function (className, projectCssPath) {
4
- return className + '_' + getPostfix(projectCssPath);
1
+ module.exports = function (className, postfix, classesInCss) {
2
+ const classes = className.split(/\s+/);
3
+ return classes
4
+ .map((c) => (!classesInCss || classesInCss.has(c) ? c + '_' + postfix : c))
5
+ .join(' ');
5
6
  };
@@ -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 projectCssPath = cssPath; // cssPath.replace(basePath, '');
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, projectCssPath)
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 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(' ');
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 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(' ');
16
+ const renamedClass = renameClass(part.chars, postfix, classes);
17
+ part.chars = renamedClass;
30
18
  }
31
19
  }
32
20
  }
@@ -47,6 +35,25 @@ module.exports = function rewriteHbs(hbs, classes, tags, postfix) {
47
35
  }
48
36
  }
49
37
  },
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
+ },
50
57
  });
51
58
 
52
59
  let result = recast.print(ast);