[from now] 2014/06/17 01:33:44

diff --git a/src/main/groovy/gaiden/kai/GaidenConfig.groovy b/src/main/groovy/gaiden/kai/GaidenConfig.groovy
index 67de3e2..9d58a9a 100644
--- a/src/main/groovy/gaiden/kai/GaidenConfig.groovy
+++ b/src/main/groovy/gaiden/kai/GaidenConfig.groovy
@@ -18,6 +18,8 @@

     Path outputDirectory = Paths.get("build")

+    Path tocFile = Paths.get("pages/toc.groovy")
+
     String inputEncoding = "UTF-8"

     @PostConstruct
diff --git a/src/main/groovy/gaiden/kai/TocNode.groovy b/src/main/groovy/gaiden/kai/TocNode.groovy
new file mode 100644
index 0000000..759bbee
--- /dev/null
+++ b/src/main/groovy/gaiden/kai/TocNode.groovy
@@ -0,0 +1,17 @@
+package gaiden.kai
+
+import groovy.transform.CompileStatic
+import groovy.transform.ToString
+
+import java.nio.file.Path
+
+@CompileStatic
+@ToString
+class TocNode {
+
+    String title
+    Path path
+//    List<TocNode> children
+    List<Map> children
+
+}
diff --git a/src/main/groovy/gaiden/kai/TocSource.groovy b/src/main/groovy/gaiden/kai/TocSource.groovy
new file mode 100644
index 0000000..3ab142e
--- /dev/null
+++ b/src/main/groovy/gaiden/kai/TocSource.groovy
@@ -0,0 +1,39 @@
+package gaiden.kai
+
+import groovy.json.JsonBuilder
+import groovy.transform.CompileStatic
+import groovy.transform.TypeCheckingMode
+
+import java.nio.file.Path
+import java.nio.file.Paths
+
+@CompileStatic
+class TocSource {
+
+//    List<TocNode> nodes
+    List<Map> nodes
+
+    @CompileStatic(TypeCheckingMode.SKIP)
+    TocSource(Path tocFile, String inputEncoding) {
+        def tocBuilder = new NodeBuilder()
+        def rootNode = tocBuilder.toc(new GroovyShell().evaluate("{ -> ${tocFile.getText(inputEncoding)} }"))
+        nodes = buildNodes(rootNode.children())
+    }
+
+//    private List<TocNode> buildNodes(List<Node> nodes) {
+    private List<Map> buildNodes(List<Node> nodes) {
+        nodes.collect { Node node ->
+//            def tocNode = new TocNode()
+            def tocNode = [:]
+//            tocNode.path = Paths.get(node.name() as String)
+            tocNode.path = node.name() as String
+            tocNode.title = node.attributes().title
+            tocNode.children = buildNodes(node.children())
+            tocNode
+        }
+    }
+
+    String toJson() {
+        new JsonBuilder(nodes).toPrettyString()
+    }
+}
diff --git a/src/main/groovy/gaiden/kai/command/VersionCommand.groovy b/src/main/groovy/gaiden/kai/command/VersionCommand.groovy
new file mode 100644
index 0000000..aa4c9bb
--- /dev/null
+++ b/src/main/groovy/gaiden/kai/command/VersionCommand.groovy
@@ -0,0 +1,37 @@
+package gaiden.kai.command
+
+import groovy.transform.CompileStatic
+import org.springframework.stereotype.Component
+
+@Component
+@CompileStatic
+class VersionCommand implements GaidenCommnad {
+
+    final String name = "version"
+
+    @Override
+    void execute(List<String> options) {
+        def properties = new Properties()
+        getClass().getResourceAsStream("/build-receipt.properties").withStream { InputStream stream ->
+            properties.load(stream)
+        }
+        println """\
+             _     _
+            (_)   | |
+  __ _  __ _ _  __| | ___ _ __
+ / _` |/ _` | |/ _` |/ _ \\ '_ \\
+| (_| | (_| | | (_| |  __/ | | |
+ \\__, |\\__,_|_|\\__,_|\\___|_| |_|
+  __/ |
+ |___/
+
+Version:    ${properties.version}
+Revision:   ${properties.revision}
+Build date: ${properties.buildDate}
+
+OS:         ${System.properties["os.name"]} ${System.properties["os.version"]}
+JVM:        ${System.properties["java.version"]}
+Groovy:     ${GroovySystem.getVersion()}\
+"""
+    }
+}
diff --git a/src/test/groovy/gaiden/GaidenMainSpec.groovy b/src/test/groovy/gaiden/GaidenMainSpec.groovy
index 439e23d..2e10921 100644
--- a/src/test/groovy/gaiden/GaidenMainSpec.groovy
+++ b/src/test/groovy/gaiden/GaidenMainSpec.groovy
@@ -19,7 +19,6 @@
 import gaiden.command.CommandFactory
 import gaiden.command.GaidenCommand
 import gaiden.exception.GaidenException
-import gaiden.kai.exception.IllegalOperationException
 import gaiden.message.MessageSource
 import spock.lang.Specification

diff --git a/src/test/groovy/gaiden/kai/GaidenSpec.groovy b/src/test/groovy/gaiden/kai/GaidenSpec.groovy
index c91ab7f..be750a8 100644
--- a/src/test/groovy/gaiden/kai/GaidenSpec.groovy
+++ b/src/test/groovy/gaiden/kai/GaidenSpec.groovy
@@ -16,15 +16,19 @@
     @AutoCleanup("deleteDir")
     Path outputDirectory

+    Path tocFile
+
     GaidenConfig gaidenConfig

     def setup() {
         pagesDirectory = Files.createTempDirectory("pages")
         outputDirectory = Files.createTempDirectory("output")
+        tocFile = pagesDirectory.resolve("toc.groovy")

         gaidenConfig = new GaidenConfig()
         gaidenConfig.pagesDirectory = pagesDirectory
         gaidenConfig.outputDirectory = outputDirectory
+        gaidenConfig.tocFile = tocFile
     }

     Path createFile(String path, Closure closure = { "# Test Page" }) {
diff --git a/src/test/groovy/gaiden/kai/TocSourceSpec.groovy b/src/test/groovy/gaiden/kai/TocSourceSpec.groovy
new file mode 100644
index 0000000..03775bb
--- /dev/null
+++ b/src/test/groovy/gaiden/kai/TocSourceSpec.groovy
@@ -0,0 +1,27 @@
+package gaiden.kai
+
+import java.lang.Void as Should
+
+class TocSourceSpec extends GaidenSpec {
+
+    Should "build a toc source"() {
+        given:
+            tocFile.write '''\
+"introduction.md"(title: "Introduction") {
+    "introduction/whatis.md"(title: "What is Gaiden?")
+    "introduction/install.md"(title: "Install")
+}
+"quickstart/quickstart.md"(title: "Quick Start") {
+    "quickstart/addingcontent.md"(title: "Adding content")
+}
+'''
+
+        when:
+            def tocSource = new TocSource(tocFile, "UTF-8")
+
+        then:
+//            tocSource.nodes == []
+//
+            tocSource.toJson() == ""
+    }
+}