Version 0.2: Adds relative-path-root option.

* `relative-path-root` option added. This facilitates situations where the
  current directory of the invocation context is different than the working
  directory of the program. This is required to use `jlp` with tools like
  *Nailgun*, which keeps a persistant `java` process running and proxies new
  invocations to the existing process.
This commit is contained in:
Jonathan Bernard 2011-09-08 12:30:09 -05:00
parent 5858c4552b
commit e6d515fc96
3 changed files with 40 additions and 9 deletions

2
jlp
View File

@ -1 +1 @@
ng com.jdblabs.jlp.JLPMain "$@" ng com.jdblabs.jlp.JLPMain --relative-path-root "`pwd`" "$@"

View File

@ -1,6 +1,6 @@
#Tue, 06 Sep 2011 17:17:39 -0500 #Thu, 08 Sep 2011 12:27:26 -0500
name=jlp name=jlp
version=0.1 version=0.2
build.number=2 build.number=1
lib.local=true lib.local=true
release.dir=release release.dir=release

View File

@ -21,6 +21,8 @@ public class JLPMain {
cli.h('Print this help information.', longOpt: 'help', required: false) cli.h('Print this help information.', longOpt: 'help', required: false)
cli.o("Output directory (defaults to 'jlp-docs').", cli.o("Output directory (defaults to 'jlp-docs').",
longOpt: 'output-dir', required: false) longOpt: 'output-dir', required: false)
cli._(longOpt: 'relative-path-root', args: 1, required: false,
'Resolve all relative paths against this root.')
// parse options // parse options
def opts = cli.parse(args) def opts = cli.parse(args)
@ -30,8 +32,22 @@ public class JLPMain {
cli.usage() cli.usage()
return } return }
// get the relative path root (or set to current directory if not given)
def pathRoot = new File(opts."relative-path-root" ?: ".")
// fail if our root is non-existant
if (!pathRoot.exists() || !pathRoot.isDirectory()) {
System.err.println "'${pathRoot.path}' is not a valid directory."
System.exit(1) }
// get the output directory and create it if necessary // get the output directory and create it if necessary
def outputDir = opts.o ? new File(opts.o) : new File("jlp-docs") def outputDir = opts.o ? new File(opts.o) : new File("jlp-docs")
// resolve the output directory against our relative root
if (!outputDir.isAbsolute()) {
outputDir = new File(pathRoot, outputDir.path) }
// create the output directory if it does not exist
if (!outputDir.exists()) outputDir.mkdirs() if (!outputDir.exists()) outputDir.mkdirs()
// get the CSS theme to use // get the CSS theme to use
@ -41,24 +57,39 @@ public class JLPMain {
// get files passed in // get files passed in
def filenames = opts.getArgs() def filenames = opts.getArgs()
// -------- parse input -------- // // parse input
Map parsedFiles = filenames.inject([:]) { acc, filename -> Map parsedFiles = filenames.inject([:]) { acc, filename ->
acc[filename] = inst.parse(new File(filename))
// create the File object
File file = new File(filename)
// if this is a relative path, resolve it against our root path
if (!file.isAbsolute()) { file = new File(pathRoot, filename) }
// parse the file, store the result
acc[filename] = inst.parse(file)
return acc } return acc }
// -------- generate output -------- // // generate output
Map htmlDocs = LiterateMarkdownGenerator.generateDocuments(parsedFiles) Map htmlDocs = LiterateMarkdownGenerator.generateDocuments(parsedFiles)
// -------- write output files ------- // // write output files
htmlDocs.each { filename, html -> htmlDocs.each { filename, html ->
// split the path into parts // split the path into parts
def fileParts = filename.split(/[\.\/]/) def fileParts = filename.split(/[\.\/]/)
File subDir = new File('.') // default the subdirectory to the output directory
File subDir = outputDir
// if the input file was in a subdirectory, we want to mirror that
// structure here.
if (fileParts.length > 2) { if (fileParts.length > 2) {
// find the relative subdirectory of this file // find the relative subdirectory of this file
subDir = new File(outputDir, fileParts[0..-3].join('/')) subDir = new File(outputDir, fileParts[0..-3].join('/'))
// create that directory if needed
if (!subDir.exists()) subDir.mkdirs() if (!subDir.exists()) subDir.mkdirs()
} }