Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
1,035 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
"use strict"; | ||
|
||
const get = require("lodash/get"), | ||
set = require("lodash/set"), | ||
const get = require("lodash/get"), | ||
set = require("lodash/set"), | ||
uniq = require("lodash/uniq"), | ||
concat = require("lodash/concat"); | ||
|
||
pseudoRegexp = require("./pseudoRegexp"); | ||
|
||
module.exports = function(node, className) { | ||
if(get(node, [ "attrs", "class" ])) { | ||
node.attrs.class = `${node.attrs.class} ${className}` | ||
.split(" ") | ||
.sort((class1, class2) => { | ||
let class1Test = pseudoRegexp.test(class1); | ||
module.exports = function(node) { | ||
let classes, | ||
pseudoClasses; | ||
|
||
if(class1Test ? pseudoRegexp.test(class2) : !pseudoRegexp.test(class2)) { | ||
return class1 > class2; | ||
} | ||
if(!node.pseudo || !node.pseudo.length) { | ||
return node; | ||
} | ||
|
||
classes = (get(node, [ "attrs", "class" ]) || "").split(" "); | ||
|
||
pseudoClasses = uniq(node.pseudo) | ||
.filter((pseudo) => { | ||
// don't add undefined classes, or if already present | ||
if(!pseudo || classes.indexOf(pseudo) !== -1) { | ||
return false; | ||
} | ||
|
||
if(pseudoRegexp.test(class2)) { | ||
return -1; | ||
} | ||
return true; | ||
}) | ||
.sort(); | ||
|
||
return 1; | ||
}) | ||
.join(" "); | ||
delete node.pseudo; | ||
|
||
if(!pseudoClasses.length) { | ||
return node; | ||
} | ||
|
||
set(node, [ "attrs", "class" ], className); | ||
set(node, [ "attrs", "class" ], concat(classes, pseudoClasses).join(" ").trim()); | ||
|
||
return node; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
module.exports = function(node, className) { | ||
node.pseudo ? | ||
node.pseudo.push(className) : | ||
node.pseudo = [ className ]; | ||
|
||
return node; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
"use strict"; | ||
|
||
const addClassNameToNode = require("../addClassNameToNode"), | ||
|
||
className = ":empty", | ||
|
||
const className = ":empty", | ||
ineligibleTags = [ | ||
"html" | ||
]; | ||
], | ||
|
||
addPseudoToNode = require("../addPseudoToNode"); | ||
|
||
module.exports = function(node) { | ||
module.exports = function(classNamer, node) { | ||
if(!node.tag || node.content || ineligibleTags.indexOf(node.tag) >= 0) { | ||
return node; | ||
} | ||
|
||
addClassNameToNode(node, className); | ||
addPseudoToNode(node, classNamer(className)); | ||
|
||
return node; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.