Pass data to documents #78

pull/80/head
Matti Pastell 2016-12-26 13:26:36 +02:00
parent 458ef30e90
commit 7c5fcd24c6
2 changed files with 14 additions and 7 deletions

View File

@ -46,7 +46,8 @@ end
"""
weave(source ; doctype = :auto, plotlib=:auto,
informat=:auto, out_path=:doc, fig_path = "figures", fig_ext = nothing,
informat=:auto, out_path=:doc, args = Dict(),
fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache=:off,
template = nothing, highlight_theme = nothing, css = nothing
latex_cmd = "pdflatex")
@ -57,7 +58,10 @@ Weave an input document to output file.
See `list_out_formats()`
* `plotlib`: `"PyPlot"`, `"Gadfly"` or `nothing`
* `informat`: :auto = set based on file extension or set to `"noweb"`, `"markdown"` or `script`
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory, `"somepath"`: output directory as a String e.g `"/home/mpastell/weaveout"` or filename as string e.g. ~/outpath/outfile.tex.
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`:
Julia working directory, `"somepath"`: output directory as a String e.g `"/home/mpastell/weaveout"` or filename as
string e.g. ~/outpath/outfile.tex.
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS
* `fig_path`: where figures will be generated, relative to out_path
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
* `cache_path`: where of cached output will be saved.
@ -71,7 +75,8 @@ Weave an input document to output file.
**Note:** Run Weave from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
"""
function weave(source ; doctype = :auto, plotlib=:auto,
informat=:auto, out_path=:doc, fig_path = "figures", fig_ext = nothing,
informat=:auto, out_path=:doc, args = Dict(),
fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache=:off,
template = nothing, highlight_theme = nothing, css = nothing,
latex_cmd = "pdflatex")
@ -84,7 +89,7 @@ function weave(source ; doctype = :auto, plotlib=:auto,
doc = run(doc, doctype = doctype, plotlib=plotlib,
out_path=out_path,
out_path=out_path, args = args,
fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache)
formatted = format(doc)

View File

@ -10,6 +10,7 @@ Run code chunks and capture output from parsed document.
* `plotlib`: `"PyPlot"`, `"Gadfly"`, or `"Winston"`
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS.
* `fig_path`: where figures will be generated, relative to out_path
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
* `cache_path`: where of cached output will be saved.
@ -19,7 +20,7 @@ Run code chunks and capture output from parsed document.
**Note:** Run command from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
"""
function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
out_path=:doc, fig_path = "figures", fig_ext = nothing,
out_path=:doc, args=Dict(), fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache = :off)
#cache :all, :user, :off, :refresh
@ -39,10 +40,11 @@ function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
doc.fig_path = fig_path
set_rc_params(doc.format.formatdict, fig_path, fig_ext)
#New sandbox for each document
#New sandbox for each document with args exposed
sandbox = "ReportSandBox$(rcParams[:doc_number])"
eval(parse("module $sandbox\nend"))
eval(parse("module $sandbox\nWEAVE_ARGS=Dict()\nend"))
SandBox = eval(parse(sandbox))
merge!(SandBox.WEAVE_ARGS, args)
rcParams[:doc_number] += 1
if haskey(doc.format.formatdict, :mimetypes)