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
1 parent
a5cd2d7
commit 9678037
Showing
5 changed files
with
68 additions
and
53 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use strict"; | ||
const PostCssRoot = require("postcss/lib/root"); | ||
const stringify = require("./stringify"); | ||
|
||
class Document extends PostCssRoot { | ||
toString (stringifier) { | ||
return super.toString(stringifier || { | ||
stringify: stringify, | ||
}); | ||
} | ||
|
||
each (callback) { | ||
let wasBreak, lastResult; | ||
this.nodes.forEach(node => { | ||
const result = node.each(callback); | ||
if (result === false) { | ||
wasBreak = true; | ||
} else { | ||
lastResult = result; | ||
} | ||
}); | ||
if (wasBreak) { | ||
return false; | ||
} else { | ||
return lastResult; | ||
} | ||
} | ||
|
||
append () { | ||
this.last.append.apply( | ||
this.last, | ||
Array.from(arguments) | ||
); | ||
return this; | ||
} | ||
|
||
prepend () { | ||
this.first.prepend.apply( | ||
this.first, | ||
Array.from(arguments) | ||
); | ||
return this; | ||
} | ||
|
||
insertBefore (exist, add) { | ||
exist.prepend(add); | ||
return this; | ||
} | ||
|
||
insertAfter (exist, add) { | ||
exist.append(add); | ||
return this; | ||
} | ||
} | ||
module.exports = Document; |
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