[from now] 2014/08/04 02:05:18

diff --git a/src/main/groovy/gaiden/DocumentSource.groovy b/src/main/groovy/gaiden/DocumentSource.groovy
index 872c94e..6a6d225 100644
--- a/src/main/groovy/gaiden/DocumentSource.groovy
+++ b/src/main/groovy/gaiden/DocumentSource.groovy
@@ -36,7 +36,9 @@
      */
     PageSource findPageSource(PageReference pageReference) {
         pageSources.find {
-            pageReference.path in [it.path, it.outputPath]
+            if (pageReference.path in [it.path, it.outputPath]) {
+                return true
+            }
         }
     }
 }
diff --git a/src/main/groovy/gaiden/PageReferenceFactory.groovy b/src/main/groovy/gaiden/PageReferenceFactory.groovy
index e3f7941..affdde0 100644
--- a/src/main/groovy/gaiden/PageReferenceFactory.groovy
+++ b/src/main/groovy/gaiden/PageReferenceFactory.groovy
@@ -28,7 +28,8 @@ private Path getPath(Path original, PageSource basePageSource) {
         def path = removeHash(original)

         if (PathUtils.getExtension(path) && !(PathUtils.getExtension(path) in SourceCollector.PAGE_SOURCE_EXTENSIONS)) {
-            return path.absolute ? Paths.get(path.toString().substring(1)) : path
+//            return path.absolute ? Paths.get(path.toString().substring(1)) : path
+            return gaidenConfig.outputDirectory.resolve(path.absolute ? Paths.get(path.toString().substring(1)) : path)
         }

         if (path.absolute) {
diff --git a/src/main/groovy/gaiden/Toc.groovy b/src/main/groovy/gaiden/Toc.groovy
index b22a46a..5cc983a 100644
--- a/src/main/groovy/gaiden/Toc.groovy
+++ b/src/main/groovy/gaiden/Toc.groovy
@@ -48,6 +48,8 @@
      * @return TOC node found
      */
     TocNode findTocNode(Path path) {
-        tocNodes.find { it.pageSource?.path == path }
+        tocNodes.find {
+            it.pageSource?.path == path
+        }
     }
 }
diff --git a/src/test/groovy/gaiden/GaidenSpec.groovy b/src/test/groovy/gaiden/GaidenSpec.groovy
index 2e4c957..f78e3d3 100644
--- a/src/test/groovy/gaiden/GaidenSpec.groovy
+++ b/src/test/groovy/gaiden/GaidenSpec.groovy
@@ -23,6 +23,7 @@
 import spock.lang.Specification

 import java.nio.file.Files
+import java.nio.file.attribute.FileAttribute

 abstract class GaidenSpec extends Specification {

@@ -45,8 +46,8 @@ def cleanup() {
         restoreSystemProperties()
     }

-    BuildContext createBuildContext(List<Map> pageSourceMaps) {
-        def pageSources = pageSourceMaps.collect { new PageSource(it) }
+    BuildContext createBuildContext(List<Map<String, String>> pageSourceMaps) {
+        def pageSources = pageSourceMaps.collect { Map<String, String> params -> createPageSource(params.path) }
         def documentSource = new DocumentSource(pageSources: pageSources)
         new BuildContext(documentSource: documentSource)
     }
@@ -59,6 +60,9 @@ PageSource createPageSource(String path, String content = null) {
             Files.createDirectories(pageSource.path.parent)

         }
+        if (Files.exists(pageSource.path)) {
+            Files.delete(pageSource.path)
+        }
         Files.createFile(pageSource.path)
         if (content) {
             pageSource.path.write(content)
diff --git a/src/test/groovy/gaiden/PrevNextLinkSpec.groovy b/src/test/groovy/gaiden/PrevNextLinkSpec.groovy
index 87e9194..665d8bf 100644
--- a/src/test/groovy/gaiden/PrevNextLinkSpec.groovy
+++ b/src/test/groovy/gaiden/PrevNextLinkSpec.groovy
@@ -24,29 +24,30 @@

 class PrevNextLinkSpec extends GaidenSpec {

-    GaidenConfig gaidenConfig
-
     Path tocFile
     Path prevLinkTemplateFile
     Path nextLinkTemplateFile

-    def prevLinkTemplateEngine
-    def nextLinkTemplateEngine
+    TemplateEngine prevLinkTemplateEngine
+    TemplateEngine nextLinkTemplateEngine

     def setup() {
-        tocFile = Files.createTempFile("toc", "groovy")
+        tocFile = gaidenConfig.tocFile
+        if (Files.notExists(tocFile.parent)) {
+            Files.createDirectories(tocFile.parent)
+        }

         prevLinkTemplateEngine = new TemplateEngine()
         prevLinkTemplateFile = Files.createTempFile("prevLinkTemplate", "html")
-        prevLinkTemplateFile << '$prevLink'
+        prevLinkTemplateFile << '<a href=\'${prevPage.path}\'>${prevPage.title}</a>'

         prevLinkTemplateEngine.gaidenConfig = new GaidenConfig()
         prevLinkTemplateEngine.gaidenConfig.templateFilePath = prevLinkTemplateFile
-        prevLinkTemplateEngine.gaidenConfig.tocFilePath = tocFile
+        prevLinkTemplateEngine.gaidenConfig.tocFilePath = gaidenConfig

         nextLinkTemplateEngine = new TemplateEngine()
         nextLinkTemplateFile = Files.createTempFile("nextLinkTemplate", "html")
-        nextLinkTemplateFile << '$nextLink'
+        nextLinkTemplateFile << '<a href=\'${nextPage.path}\'>${nextPage.title}</a>'

         nextLinkTemplateEngine.gaidenConfig = new GaidenConfig()
         nextLinkTemplateEngine.gaidenConfig.templateFilePath = nextLinkTemplateFile
@@ -70,13 +71,13 @@ def cleanup() {
             def firstContent = prevLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == ""
+            firstContent == "<a href=''></a>"

         when:
             def secondContent = prevLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == "<a href='first.html' class='prev'>&lt;&lt; first title</a>"
+            secondContent == "<a href='first.html'>first title</a>"
     }

     def "make a previous link with a TOC which file an extension is not specified"() {
@@ -90,13 +91,13 @@ def cleanup() {
             def firstContent = prevLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == ""
+            firstContent == "<a href=''></a>"

         when:
             def secondContent = prevLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == "<a href='first.html' class='prev'>&lt;&lt; first title</a>"
+            secondContent == "<a href='first.html'>first title</a>"
     }

     def "make a previous link with a TOC which an output file path is specified"() {
@@ -110,13 +111,13 @@ def cleanup() {
             def firstContent = prevLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == ""
+            firstContent == "<a href=''></a>"

         when:
             def secondContent = prevLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == "<a href='first.html' class='prev'>&lt;&lt; first title</a>"
+            secondContent == "<a href='first.html'>first title</a>"
     }

     def "make a previous link with TOC which a missing file is specified"() {
@@ -130,13 +131,13 @@ def cleanup() {
             def firstContent = prevLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == ""
+            firstContent == "<a href=''></a>"

         when:
             def secondContent = prevLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == "&lt;&lt; first title"
+            secondContent == "first title"
     }

     def "make a previous link with TOC which a fragment is specified"() {
@@ -150,13 +151,13 @@ def cleanup() {
             def firstContent = prevLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == ""
+            firstContent == "<a href=''></a>"

         when:
             def secondContent = prevLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == "<a href='first.html#fragment' class='prev'>&lt;&lt; first title</a>"
+            secondContent == "<a href='first.html#fragment'>first title</a>"
     }

     def "make a previous link with TOC which a nested pages is specified"() {
@@ -171,13 +172,13 @@ def cleanup() {
             def firstContent = prevLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == ""
+            firstContent == "<a href=''></a>"

         when:
             def secondContent = prevLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == "<a href='first.html' class='prev'>&lt;&lt; first title</a>"
+            secondContent == "<a href='first.html'>first title</a>"
     }

     def "make a next link"() {
@@ -197,7 +198,7 @@ def cleanup() {
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == ""
+            secondContent == "<a href=''></a>"
     }

     def "make a next link with a TOC which file an extension is not specified"() {
@@ -217,7 +218,7 @@ def cleanup() {
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == ""
+            secondContent == "<a href=''></a>"
     }

     def "make a next link with a TOC which an output file path is specified"() {
@@ -237,7 +238,7 @@ def cleanup() {
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == ""
+            secondContent == "<a href=''></a>"
     }

     def "make a next link with TOC which a missing file is specified"() {
@@ -257,7 +258,7 @@ def cleanup() {
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == ""
+            secondContent == "<a href=''></a>"
     }

     def "make a next link with TOC which a fragment is specified"() {
@@ -277,7 +278,7 @@ def cleanup() {
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == ""
+            secondContent == "<a href=''></a>"
     }

     def "make a next link with TOC which a nested pages is specified"() {
@@ -298,27 +299,28 @@ def cleanup() {
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == ""
+            secondContent == "<a href=''></a>"
     }

     private Map<String, Object> bindingOf(String sourcePath) {
         def context = createBuildContext([[path: "first.md"], [path: "second.md"]])
+        def pageReferenceFactory = new PageReferenceFactory(gaidenConfig: gaidenConfig)

         def tocBuilder = new TocBuilder()
         tocBuilder.templateEngine = prevLinkTemplateEngine
-        tocBuilder.gaidenConfig = prevLinkTemplateEngine.gaidenConfig
+        tocBuilder.gaidenConfig = gaidenConfig
         tocBuilder.messageSource = messageSource
+        tocBuilder.pageReferenceFactory = pageReferenceFactory
         def toc = tocBuilder.build(context)

         def pageBuildContext = new PageBuildContext()
         pageBuildContext.toc = toc
         pageBuildContext.documentSource = context.documentSource

-        new BindingBuilder("Test title", "toc.html")
-            .setSourcePath(sourcePath)
+        new BindingBuilder("Test title", gaidenConfig.outputDirectory, gaidenConfig.tocOutputFile, pageReferenceFactory)
+            .setSourcePath(gaidenConfig.pagesDirectory.resolve(sourcePath))
             .setPageBuildContext(pageBuildContext)
-            .setOutputPath(FileUtils.replaceExtension(sourcePath, "html"))
+            .setOutputPath(gaidenConfig.outputDirectory.resolve(FileUtils.removeExtension(sourcePath) + ".html"))
             .build()
     }
-
 }
[from now] 2014/08/04 02:08:13

diff --git a/src/test/groovy/gaiden/PrevNextLinkSpec.groovy b/src/test/groovy/gaiden/PrevNextLinkSpec.groovy
index 665d8bf..681cff6 100644
--- a/src/test/groovy/gaiden/PrevNextLinkSpec.groovy
+++ b/src/test/groovy/gaiden/PrevNextLinkSpec.groovy
@@ -137,7 +137,7 @@ def cleanup() {
             def secondContent = prevLinkTemplateEngine.make(bindingOf("second.md"))

         then:
-            secondContent == "first title"
+            secondContent == "<a href=''>first title</a>"
     }

     def "make a previous link with TOC which a fragment is specified"() {
@@ -192,7 +192,7 @@ def cleanup() {
             def firstContent = nextLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == "<a href='second.html' class='next'>second title &gt;&gt;</a>"
+            firstContent == "<a href='second.html'>second title</a>"

         when:
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))
@@ -212,7 +212,7 @@ def cleanup() {
             def firstContent = nextLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == "<a href='second.html' class='next'>second title &gt;&gt;</a>"
+            firstContent == "<a href='second.html'>second title</a>"

         when:
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))
@@ -232,7 +232,7 @@ def cleanup() {
             def firstContent = nextLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == "<a href='second.html' class='next'>second title &gt;&gt;</a>"
+            firstContent == "<a href='second.html'>second title</a>"

         when:
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))
@@ -252,7 +252,7 @@ def cleanup() {
             def firstContent = nextLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == "second title &gt;&gt;"
+            firstContent == "<a href=''>second title</a>"

         when:
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))
@@ -272,7 +272,7 @@ def cleanup() {
             def firstContent = nextLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == "<a href='second.html#fragment' class='next'>second title &gt;&gt;</a>"
+            firstContent == "<a href='second.html#fragment'>second title</a>"

         when:
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))
@@ -293,7 +293,7 @@ def cleanup() {
             def firstContent = nextLinkTemplateEngine.make(bindingOf("first.md"))

         then:
-            firstContent == "<a href='second.html' class='next'>second title &gt;&gt;</a>"
+            firstContent == "<a href='second.html'>second title</a>"

         when:
             def secondContent = nextLinkTemplateEngine.make(bindingOf("second.md"))