@@ -11,15 +11,8 @@ class FileTreeDsl() : FileTreeNode() {
1111 return this
1212 }
1313
14- operator fun FileTreeNode.invoke (block : FileTreeDsl .() -> Unit ): FileTreeNode {
15- block()
16- return this
17- }
18-
19- constructor (parent: FileTreeDsl ? , name: String , isDir: Boolean ) : this () {
20- this .name = name
21- this .parent = parent
22- this .isDir = isDir
14+ operator fun FileTreeNode.invoke (block : FileTreeNode .() -> Unit ){
15+ block(this )
2316 }
2417
2518 /* *
@@ -28,7 +21,7 @@ class FileTreeDsl() : FileTreeNode() {
2821 * @param path The dir path
2922 * @param block The child node domain
3023 */
31- fun dir (path : String , block : FileTreeDsl .() -> Unit = {}) {
24+ fun FileTreeNode. dir (path : String , block : FileTreeNode .() -> Unit = {}) {
3225 if (! isDir) {
3326 this (block)
3427 return
@@ -37,30 +30,29 @@ class FileTreeDsl() : FileTreeNode() {
3730 path.contains(" ." ) -> path.split(" ." )
3831 path.contains(" /" ) -> path.split(" /" )
3932 else -> {
40- val newNode = FileTreeDsl (this , path, true )
33+ val newNode = FileTreeNode (this , path, true )
4134 if (addChild(newNode)) {
4235 newNode(block)
4336 }
4437 return
4538 }
4639 }
47- dirs = dirs
48- .filter {
40+ dirs = dirs.filter {
4941 it.isNotBlank()
5042 }.toMutableList()
51- createDirs(dirs, this )(block)
43+ val domain = createDirs(dirs, this )
44+ domain.invoke(block)
5245 }
5346
54- fun file (name : String ) {
47+ fun FileTreeNode. file (name : String ) {
5548 if (! isDir) return
5649 addChild(FileTreeNode (this , name, false ))
5750 }
5851
59- fun fileTemplate (fileName : String , template : String ) {
52+ fun FileTreeNode. fileTemplate (fileName : String , template : String ) {
6053 if (this .fileTemplates == null ) {
6154 this .fileTemplates = mutableMapOf ()
6255 }
6356 fileTemplates!! [fileName] = template
6457 }
65-
6658}
0 commit comments