From 75103b4bb510743de55e89dc4ee66c9b47b5a650 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Fri, 9 Sep 2011 14:56:50 -0500 Subject: [PATCH] Bugfix in recent changes. * The generators originally had two phases, *parse* and *emit*. The *parse* phase allowed the generator to walk the AST for every document noting things it would need when emitting output. So the *parse* phase looked over every input document before the *emit* phase ran. During the refactor this changed and for each file the *emit* phase was running immediately after the *parse* phase, when it should have been run only after all inputs had been through the *parse* phase. * Fixed a type in the ``LiterateMarkdownGenerator``: an extra '`/`' was being inserted into the url for link targets. --- project.properties | 4 ++-- src/main/com/jdblabs/jlp/JLPBaseGenerator.groovy | 8 -------- .../jdblabs/jlp/LiterateMarkdownGenerator.groovy | 10 +++++----- src/main/com/jdblabs/jlp/Processor.groovy | 13 +++++++++++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/project.properties b/project.properties index d4e378d..d7c14df 100644 --- a/project.properties +++ b/project.properties @@ -1,6 +1,6 @@ -#Fri, 09 Sep 2011 14:26:03 -0500 +#Fri, 09 Sep 2011 14:55:32 -0500 name=jlp version=0.3 -build.number=1 +build.number=7 lib.local=true release.dir=release diff --git a/src/main/com/jdblabs/jlp/JLPBaseGenerator.groovy b/src/main/com/jdblabs/jlp/JLPBaseGenerator.groovy index 91f0697..320fb17 100644 --- a/src/main/com/jdblabs/jlp/JLPBaseGenerator.groovy +++ b/src/main/com/jdblabs/jlp/JLPBaseGenerator.groovy @@ -11,14 +11,6 @@ public abstract class JLPBaseGenerator { protected JLPBaseGenerator(Processor processor) { this.processor = processor } - protected String generate(SourceFile source) { - - // run the parse phase - parse(source) - - // run the emit phase - return emit(source) } - protected void parse(SourceFile sourceFile) { sourceFile.blocks.each { block -> parse(block) } } diff --git a/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy b/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy index ae4d2a2..054e950 100644 --- a/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy +++ b/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy @@ -199,17 +199,17 @@ public class LiterateMarkdownGenerator extends JLPBaseGenerator { // The link should point to a different document. else { - thisDoc = processor.currentDoc - linkDoc = processor.docs[link.sourceDocId] + TargetDoc thisDoc = processor.currentDoc + TargetDoc linkDoc = processor.docs[link.sourceDocId] - pathToLinkedDoc = processor.getRelativePath( + String pathToLinkedDoc = processor.getRelativeFilepath( thisDoc.sourceFile.parentFile, - thatDoc.sourceFile) + linkDoc.sourceFile) // The target document may not be in the same directory // as us, backtrack to the (relative) top of our directory // structure. - newLink = pathToLinkedDoc + "/" + ".html#${linkId}" } + newLink = pathToLinkedDoc + ".html#${linkId}" } return newLink } diff --git a/src/main/com/jdblabs/jlp/Processor.groovy b/src/main/com/jdblabs/jlp/Processor.groovy index 82ec9c5..958a3e6 100644 --- a/src/main/com/jdblabs/jlp/Processor.groovy +++ b/src/main/com/jdblabs/jlp/Processor.groovy @@ -66,13 +66,22 @@ public class Processor { currentDoc.sourceAST = parseRunner.run( currentDoc.sourceFile.text).resultValue } - // generate output + // run our generator parse phase (first pass over the ASTs) processDocs { // TODO: add logic to configure or autodetect the correct generator // for each file def generator = getGenerator(LiterateMarkdownGenerator) - currentDoc.output = generator.generate(currentDoc.sourceAST) } + generator.parse(currentDoc.sourceAST) } + + + // Second pass by the generators, create output. + processDocs { + + // TODO: add logic to configure or autodetect the correct generator + // for each file + def generator = getGenerator(LiterateMarkdownGenerator) + currentDoc.output = generator.emit(currentDoc.sourceAST) } // Write the output to the output directory processDocs {