Permalink
Browse files

elementClass tests pass

  • Loading branch information...
1 parent f9af82e commit e49045033752f488786f1a4c62efd8352ecd3696 @substack committed May 28, 2012
Showing with 17 additions and 4 deletions.
  1. +16 −3 index.js
  2. +1 −1 test/tags_dst.css
View
@@ -1,16 +1,29 @@
var cssp = require('cssp');
var traverse = require('traverse');
-module.exports = function (prefix, src) {
+module.exports = function (opts, src) {
+ if (typeof opts === 'string') {
+ opts = { prefix : opts };
+ }
+
var tree = cssp.parse(src);
traverse(tree).forEach(function (node) {
if (!Array.isArray(node)) return;
if (node[0] === 'clazz' && node[1][0] === 'ident') {
- node[1][1] = prefix + node[1][1];
+ if (node[1][1] !== opts.elementClass) {
+ node[1][1] = opts.prefix + node[1][1];
+ }
}
else if (node[0] === 'shash') {
- node[1] = prefix + node[1];
+ node[1] = opts.prefix + node[1];
+ }
+ else if (opts.elementClass && node[0] === 'ident'
+ && this.parent && Array.isArray(this.parent.node)
+ && this.parent.node[0] === 'simpleselector') {
+ var ix = parseInt(this.key, 10) + 1;
+ var cz = [ 'clazz', [ 'ident', opts.elementClass ] ];
+ this.parent.node.splice(ix, 0, cz);
}
});
View
@@ -4,4 +4,4 @@ h1.xxx, h2.xxx { font-weight: bold; }
.zzz-bleep b.xxx .zzz-foo { color: black; }
-h1.zzz-beep.xxx { text-decoration: underline; }
+h1.xxx.zzz-beep { text-decoration: underline; }

0 comments on commit e490450

Please sign in to comment.