mirror of https://github.com/mpastell/Weave.jl
allow arbitrary runtime argument
parent
3e8200c2f8
commit
c24a262135
|
@ -165,29 +165,12 @@ See [Header Configuration](@ref) section for more details.
|
||||||
|
|
||||||
## Passing Runtime Arguments to Documents
|
## Passing Runtime Arguments to Documents
|
||||||
|
|
||||||
You can pass arguments as `Dict` to the weaved document using the `args` argument
|
You can pass arbitrary object to the weaved document using [`weave`](@ref)'s optional argument `args`.
|
||||||
to `weave`. The arguments will be available as `WEAVE_ARGS` variable in the document.
|
It will be available as `WEAVE_ARGS` variable in the `weave`d document.
|
||||||
|
|
||||||
This makes it possible to create the same report easily for e.g. different
|
This makes it possible to create the same report easily for e.g. different date ranges of input data from a database or from files with similar format giving the filename as input.
|
||||||
date ranges of input data from a database or from files with similar format giving the
|
|
||||||
filename as input.
|
|
||||||
|
|
||||||
In order to pass a filename to a document you need call `weave` using:
|
E.g. if you call `weave("weavefile.jmd", args = (datalocation = "somedata.h5",))`, and then you can retrieve `datalocation` in `weavefile.jmd` as follows: `WEAVE_ARGS.datalocation`
|
||||||
|
|
||||||
```julia
|
|
||||||
weave("mydoc.jmd", args = Dict("filename" => "somedata.h5"))
|
|
||||||
```
|
|
||||||
|
|
||||||
and you can access the filename from document as follows:
|
|
||||||
|
|
||||||
```
|
|
||||||
```julia
|
|
||||||
print(WEAVE_ARGS["filename"])
|
|
||||||
```
|
|
||||||
```
|
|
||||||
|
|
||||||
You can use the `out_path` argument to control the name of the
|
|
||||||
output document.
|
|
||||||
|
|
||||||
|
|
||||||
## `include_weave`
|
## `include_weave`
|
||||||
|
|
|
@ -102,7 +102,7 @@ Weave an input document to output file.
|
||||||
* `:doc`: Path of the source document (default)
|
* `:doc`: Path of the source document (default)
|
||||||
* `:pwd`: Julia working directory
|
* `:pwd`: Julia working directory
|
||||||
* `"somepath"`: `String` of output directory e.g. `"~/outdir"`, or of filename e.g. `"~/outdir/outfile.tex"`
|
* `"somepath"`: `String` of output directory e.g. `"~/outdir"`, or of filename e.g. `"~/outdir/outfile.tex"`
|
||||||
- `args::Dict = Dict()`: Arguments to be passed to the weaved document; will be available as `WEAVE_ARGS` in the document
|
- `args::Any = Dict()`: A runtime object that is available as `WEAVE_ARGS` while `weave`ing
|
||||||
- `mod::Union{Module,Nothing} = nothing`: Module where Weave `eval`s code. You can pass a `Module` object, otherwise create an new sandbox module.
|
- `mod::Union{Module,Nothing} = nothing`: Module where Weave `eval`s code. You can pass a `Module` object, otherwise create an new sandbox module.
|
||||||
- `fig_path::Union{Nothing,AbstractString} = nothing`: Where figures will be generated, relative to `out_path`. By default (i.e. given `nothing`), Weave will automatically create `$(DEFAULT_FIG_PATH)` directory.
|
- `fig_path::Union{Nothing,AbstractString} = nothing`: Where figures will be generated, relative to `out_path`. By default (i.e. given `nothing`), Weave will automatically create `$(DEFAULT_FIG_PATH)` directory.
|
||||||
- `fig_ext::Union{Nothing,AbstractString} = nothing`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`
|
- `fig_ext::Union{Nothing,AbstractString} = nothing`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`
|
||||||
|
@ -127,7 +127,7 @@ function weave(
|
||||||
doctype::Union{Nothing,AbstractString} = nothing,
|
doctype::Union{Nothing,AbstractString} = nothing,
|
||||||
informat::Union{Nothing,AbstractString} = nothing,
|
informat::Union{Nothing,AbstractString} = nothing,
|
||||||
out_path::Union{Symbol,AbstractString} = :doc,
|
out_path::Union{Symbol,AbstractString} = :doc,
|
||||||
args::Dict = Dict(),
|
args::Any = Dict(),
|
||||||
mod::Union{Module,Nothing} = nothing,
|
mod::Union{Module,Nothing} = nothing,
|
||||||
fig_path::Union{Nothing,AbstractString} = nothing,
|
fig_path::Union{Nothing,AbstractString} = nothing,
|
||||||
fig_ext::Union{Nothing,AbstractString} = nothing,
|
fig_ext::Union{Nothing,AbstractString} = nothing,
|
||||||
|
|
|
@ -7,7 +7,7 @@ function run_doc(
|
||||||
doc::WeaveDoc;
|
doc::WeaveDoc;
|
||||||
doctype::Union{Nothing,AbstractString} = nothing,
|
doctype::Union{Nothing,AbstractString} = nothing,
|
||||||
out_path::Union{Symbol,AbstractString} = :doc,
|
out_path::Union{Symbol,AbstractString} = :doc,
|
||||||
args::Dict = Dict(),
|
args::Any = Dict(),
|
||||||
mod::Union{Module,Nothing} = nothing,
|
mod::Union{Module,Nothing} = nothing,
|
||||||
fig_path::Union{Nothing,AbstractString} = nothing,
|
fig_path::Union{Nothing,AbstractString} = nothing,
|
||||||
fig_ext::Union{Nothing,AbstractString} = nothing,
|
fig_ext::Union{Nothing,AbstractString} = nothing,
|
||||||
|
@ -39,7 +39,7 @@ function run_doc(
|
||||||
|
|
||||||
# New sandbox for each document with args exposed
|
# New sandbox for each document with args exposed
|
||||||
isnothing(mod) && (mod = sandbox = Core.eval(Main, :(module $(gensym(:WeaveSandBox)) end))::Module)
|
isnothing(mod) && (mod = sandbox = Core.eval(Main, :(module $(gensym(:WeaveSandBox)) end))::Module)
|
||||||
@eval mod WEAVE_ARGS = $args
|
Core.eval(mod, :(const WEAVE_ARGS = $(args)))
|
||||||
|
|
||||||
mimetypes = doc.format.mimetypes
|
mimetypes = doc.format.mimetypes
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue