From 9b620e4a67b954f0a4f3114120cb367acda6448e Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Sat, 20 Dec 2014 16:41:37 +0200 Subject: [PATCH] Added command line script for weaving: bin/weave.jl. Closes #19 --- REQUIRE | 1 + bin/weave.jl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Weave.jl | 2 -- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 bin/weave.jl diff --git a/REQUIRE b/REQUIRE index fc54a59..d7b7d48 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,4 @@ julia 0.3 Compat TextWrap +ArgParse diff --git a/bin/weave.jl b/bin/weave.jl new file mode 100755 index 0000000..6c28ca3 --- /dev/null +++ b/bin/weave.jl @@ -0,0 +1,59 @@ +#!/usr/bin/env julia + + +using Weave +using ArgParse + +ap = ArgParseSettings("Weave Julia documents using Weave.jl", + version = string(Pkg.installed("Weave")), + add_version = true) + +@add_arg_table ap begin + "source" + nargs = '+' + help = "source document" + required = true + "--doctype" + arg_type = String + default = "pandoc" + help = "output format" + "--plotlib" + arg_type = String + default = "Gadfly" + help = "output format" + "--informat" + arg_type = String + default = "noweb" + help = "output format" + "--out_path" + arg_type = String + default = ":doc" + help = "output directory" + "--fig_path" + arg_type = String + default = "figures" + help = "figure output directory" + "--fig_ext" + default = nothing + help = "figure file format" +end + +args = ArgParse.parse_args(ap) +source = args["source"] +delete!(args, "source") +args_col = {} + +#Check for special values of out_path +if args["out_path"] == ":doc" + args["out_path"] = :doc +elseif args["out_path"] == ":pwd" + args["out_path"] = :pwd +end + +for (key, val) in args + push!(args_col, (parse(key), val)) +end + +for s=source + weave(s; args_col...) +end diff --git a/src/Weave.jl b/src/Weave.jl index d667e49..79ada73 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -50,8 +50,6 @@ end function weave(source ; doctype = "pandoc", plotlib="Gadfly", informat="noweb", out_path=:doc, fig_path = "figures", fig_ext = nothing) - - cwd, fname = splitdir(abspath(source)) basename = splitext(fname)[1] formatdict = formats[doctype].formatdict