diff --git a/jlp b/jlp new file mode 100755 index 0000000..5b0198c --- /dev/null +++ b/jlp @@ -0,0 +1 @@ +ng com.jdblabs.jlp.JLPMain "$@" diff --git a/lib/runtime/jar/commons-cli-1.2.jar b/lib/runtime/jar/commons-cli-1.2.jar new file mode 100644 index 0000000..ce4b9ff Binary files /dev/null and b/lib/runtime/jar/commons-cli-1.2.jar differ diff --git a/lib/runtime/jar/groovy-all-1.7.10.jar b/lib/runtime/jar/groovy-all-1.7.10.jar new file mode 100644 index 0000000..b4f77c9 Binary files /dev/null and b/lib/runtime/jar/groovy-all-1.7.10.jar differ diff --git a/project.properties b/project.properties index 7500dab..3592935 100644 --- a/project.properties +++ b/project.properties @@ -1,4 +1,5 @@ +#Tue, 06 Sep 2011 17:09:38 -0500 name=jlp version=alpha1 -build.number=0 +build.number=6 lib.local=true diff --git a/resources/main/jlp.css b/resources/main/jlp.css index bcff1ad..ed78184 100644 --- a/resources/main/jlp.css +++ b/resources/main/jlp.css @@ -50,7 +50,7 @@ td.docs, th.docs { .docs table { border: thin solid #dedede; - margin-left: 30px; } + margin-left: 60px; } td.code, th.code { padding: 14px 15px 16px 25px; diff --git a/src/main/com/jdblabs/jlp/JLPMain.groovy b/src/main/com/jdblabs/jlp/JLPMain.groovy index 147cbaa..8f69855 100644 --- a/src/main/com/jdblabs/jlp/JLPMain.groovy +++ b/src/main/com/jdblabs/jlp/JLPMain.groovy @@ -1,6 +1,7 @@ package com.jdblabs.jlp import com.jdblabs.jlp.ast.ASTNode +import com.jdblabs.jlp.ast.SourceFile import org.parboiled.Parboiled import org.parboiled.parserunners.ReportingParseRunner @@ -18,6 +19,8 @@ public class JLPMain { // define options cli.h('Print this help information.', longOpt: 'help', required: false) + cli.o("Output directory (defaults to 'jlp-docs').", + longOpt: 'output-dir', required: false) // parse options def opts = cli.parse(args) @@ -27,31 +30,62 @@ public class JLPMain { cli.usage() return } + // get the output directory and create it if necessary + def outputDir = opts.o ? new File(opts.o) : new File("jlp-docs") + if (!outputDir.exists()) outputDir.mkdirs() + + // get the CSS theme to use + def css = JLPMain.class.getResourceAsStream("/jlp.css") // TODO: make an option + css = css.text + // get files passed in def filenames = opts.getArgs() - def files = filenames.collect { new File(it) } // -------- parse input -------- // - Map parsedFiles = files.inject([:]) { acc, file -> - def parsed = inst.parse(new File(file)) - acc[file.canonicalPath] = parsed + Map parsedFiles = filenames.inject([:]) { acc, filename -> + acc[filename] = inst.parse(new File(filename)) return acc } // -------- generate output -------- // + Map htmlDocs = LiterateMarkdownGenerator.generateDocuments(parsedFiles) + + // -------- write output files ------- // + htmlDocs.each { filename, html -> + // split the path into parts + def fileParts = filename.split(/[\.\/]/) + + File subDir = new File('.') + + if (fileParts.length > 2) { + // find the relative subdirectory of this file + subDir = new File(outputDir, fileParts[0..-3].join('/')) + if (!subDir.exists()) subDir.mkdirs() + } + + // recreate the output filename + def outputFilename = fileParts[-2] + ".html" + + // write the HTML to the file + new File(subDir, outputFilename).withWriter { fileOut -> + + // write the CSS if it is not present + File cssFile = new File(subDir, "jlp.css") + if (!cssFile.exists()) cssFile.withWriter { cssOut -> + cssOut.println css } + + + // write the file + fileOut.println html } } } public JLPMain() { parser = Parboiled.createParser(JLPPegParser.class) } - public Map parse(File inputFile) { + public SourceFile parse(File inputFile) { def parseRunner = new ReportingParseRunner(parser.SourceFile()) // parse the file - return parseRunner.run(inputFile).resultValue - } - - public def generate(def emitter, List blocks) { - // second pass, semantics + return parseRunner.run(inputFile.text).resultValue } } diff --git a/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy b/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy index 0422f86..db45fd8 100644 --- a/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy +++ b/src/main/com/jdblabs/jlp/LiterateMarkdownGenerator.groovy @@ -50,7 +50,7 @@ public class LiterateMarkdownGenerator extends JLPBaseGenerator { ${docState.currentDocId} - +