Created
December 11, 2016 17:09
-
-
Save uchidev/94989cca5be1d4858520caccd9a28ae5 to your computer and use it in GitHub Desktop.
ReadMeMaker
This file contains hidden or 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
| package com.uchidev.kotlin_ex.app2 | |
| import java.io.BufferedReader | |
| import java.io.InputStreamReader | |
| import com.uchidev.kotlin_ex.tool.DirNode | |
| class ReadMeMaker(node: DirNode) { | |
| val dirNode = node | |
| fun process() { | |
| dirNode.updateContentNode("README.md", buildReadMeContent()) | |
| dirNode.eachChildrenDirNode { dir -> | |
| ReadMeMaker(dir).process() | |
| } | |
| } | |
| private fun buildReadMeContent() : CharSequence { | |
| val readMeContent = StringBuilder() | |
| dirNode.onContent("index.md") { bodyReader: InputStreamReader? -> | |
| if (bodyReader != null) { | |
| val br = BufferedReader(bodyReader) | |
| val line = br.readLine() | |
| // if (line == "# *.") | |
| readMeContent.append(line) | |
| } else { | |
| readMeContent.append("# ").append(dirNode.getDirName()) | |
| } | |
| } | |
| dirNode.eachContentNode { name, bodyReader -> | |
| readMeContent.append(name) | |
| readMeContent.append(bodyReader.readLines()) | |
| } | |
| return readMeContent | |
| } | |
| } |
This file contains hidden or 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
| package com.uchidev.kotlin_ex.tool | |
| import java.io.Closeable | |
| import java.io.InputStreamReader | |
| interface DirNode: Closeable { | |
| fun getDirName(): CharSequence | |
| fun onContent(name: CharSequence, operation: (bodyReader: InputStreamReader?) -> Unit) | |
| fun eachContentNode(operation: ((name: CharSequence, bodyReader: InputStreamReader) -> Unit)) | |
| fun eachChildrenDirNode(operation: ((DirNode) -> Unit)) | |
| fun updateContentNode(contentName: CharSequence, contentBuffer: CharSequence) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment