mirror of https://github.com/mpastell/Weave.jl
Added setting and restoring chunk options
parent
f7e18f45a3
commit
a1de2c64e2
13
src/Weave.jl
13
src/Weave.jl
|
@ -35,7 +35,7 @@ function Base.display(doc::Report, data)
|
|||
end
|
||||
|
||||
"""
|
||||
list_out_formats()
|
||||
`list_out_formats()`
|
||||
|
||||
List supported output formats
|
||||
"""
|
||||
|
@ -47,7 +47,7 @@ end
|
|||
|
||||
|
||||
"""
|
||||
tangle(source ; out_path=:doc, informat="noweb")
|
||||
`tangle(source ; out_path=:doc, informat="noweb")`
|
||||
|
||||
Tangle source code from input document to .jl file.
|
||||
|
||||
|
@ -73,8 +73,8 @@ function tangle(source ; out_path=:doc, informat="noweb")
|
|||
end
|
||||
|
||||
"""
|
||||
weave(source ; doctype = "pandoc", plotlib="Gadfly",
|
||||
informat="noweb", out_path=:doc, fig_path = "figures", fig_ext = nothing)
|
||||
`weave(source ; doctype = "pandoc", plotlib="Gadfly",
|
||||
informat="noweb", out_path=:doc, fig_path = "figures", fig_ext = nothing)`
|
||||
|
||||
Weave an input document to output file.
|
||||
|
||||
|
@ -95,7 +95,7 @@ function weave(source ; doctype = "pandoc", plotlib="Gadfly",
|
|||
informat="noweb", out_path=:doc, fig_path = "figures", fig_ext = nothing,
|
||||
cache_path = "cache", cache=:off)
|
||||
|
||||
doc = read_doc(source, informat) #Reader toimii, muuten kesken...
|
||||
doc = read_doc(source, informat)
|
||||
doc = run(doc, doctype = doctype, plotlib=plotlib,
|
||||
informat = informat, out_path=out_path,
|
||||
fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache)
|
||||
|
@ -120,7 +120,8 @@ function weave(doc::AbstractString, doctype::AbstractString)
|
|||
weave(doc, doctype=doctype)
|
||||
end
|
||||
|
||||
export weave, list_out_formats, tangle
|
||||
export weave, list_out_formats, tangle,
|
||||
set_chunk_defaults, get_chunk_defaults, restore_chunk_defaults
|
||||
|
||||
include("config.jl")
|
||||
include("chunks.jl")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
const rcParams =
|
||||
|
||||
#Default options
|
||||
const defaultParams =
|
||||
@compat Dict{Symbol,Any}(:plotlib => "Gadfly",
|
||||
:storeresults => false,
|
||||
:doc_number => 0,
|
||||
|
@ -32,51 +34,50 @@ const rcParams =
|
|||
:out_height=> nothing,
|
||||
)
|
||||
)
|
||||
#This one can be changed at runtime, initially a copy of defaults
|
||||
const rcParams = deepcopy(defaultParams)
|
||||
|
||||
#Parameters set per document
|
||||
const docParams =Dict{Symbol,Any}(
|
||||
:fig_path=> nothing,
|
||||
:fig_ext => nothing,
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
`set_chunk_defaults(opts::Dict{Symbol, Any})`
|
||||
|
||||
# Working towards Knitr compatible options, implemented options are
|
||||
# added to defaultoptions dictionary above and work in progress stays here,
|
||||
# options from https://github.com/yihui/knitr/blob/master/R/defaults.R
|
||||
# If you need a particular options, consider implementing it and making a
|
||||
# pull request.
|
||||
Set default options for code chunks, use get_chunk_defaults
|
||||
to see the current values.
|
||||
|
||||
#tidy = FALSE,
|
||||
#tidy.opts = NULL,
|
||||
#collapse = FALSE
|
||||
#prompt = FALSE
|
||||
#highlight = TRUE
|
||||
#strip.white = TRUE
|
||||
#size = 'normalsize'
|
||||
#background = '#F7F7F7',
|
||||
#cache = FALSE
|
||||
#cache.path = 'cache/'
|
||||
#cache.vars = NULL
|
||||
#cache.lazy = TRUE,
|
||||
#dependson = NULL
|
||||
#autodep = FALSE,
|
||||
#fig.keep = 'high'
|
||||
#fig.show = 'asis'
|
||||
#fig.align = 'default'
|
||||
#dev = NULL
|
||||
#dev.args = NULL
|
||||
#fig.ext = NULL
|
||||
#fig.scap = NULL
|
||||
#fig.lp = 'fig:'
|
||||
#fig.subcap = NULL,
|
||||
#out.extra = NULL
|
||||
#fig.retina = 1,
|
||||
#external = TRUE
|
||||
#sanitize = FALSE
|
||||
#interval = 1
|
||||
#aniopts = 'controls,loop',
|
||||
#warning = TRUE
|
||||
#error = TRUE
|
||||
#message = TRUE,
|
||||
#render = NULL,
|
||||
#ref.label = NULL
|
||||
#child = NULL
|
||||
#split = FALSE
|
||||
#purl = TRUE
|
||||
e.g. set default dpi to 200 and fig_width to 8
|
||||
|
||||
```
|
||||
julia> set_chunk_defaults(Dict{Symbol, Any}(:dpi => 200, fig_width => 8))
|
||||
```
|
||||
"""
|
||||
function set_chunk_defaults(opts::Dict{Symbol, Any})
|
||||
merge!(rcParams[:chunk_defaults], opts)
|
||||
end
|
||||
|
||||
"""
|
||||
`get_chunk_defaults()`
|
||||
|
||||
Get default options used for code chunks.
|
||||
"""
|
||||
function get_chunk_defaults()
|
||||
return(rcParams[:chunk_defaults])
|
||||
end
|
||||
|
||||
"""
|
||||
`restore_chunk_defaults()`
|
||||
|
||||
Restore Weave.jl default chunk options
|
||||
"""
|
||||
function restore_chunk_defaults()
|
||||
rcParams[:chunk_defaults] = defaultParams[:chunk_defaults]
|
||||
merge!(rcParams[:chunk_defaults], docParams)
|
||||
return nothing
|
||||
end
|
||||
|
|
|
@ -248,10 +248,13 @@ end
|
|||
function set_rc_params(formatdict, fig_path, fig_ext)
|
||||
if fig_ext == nothing
|
||||
rcParams[:chunk_defaults][:fig_ext] = formatdict[:fig_ext]
|
||||
docParams[:fig_ext] = formatdict[:fig_ext]
|
||||
else
|
||||
rcParams[:chunk_defaults][:fig_ext] = fig_ext
|
||||
docParams[:fig_ext] = fig_ext
|
||||
end
|
||||
rcParams[:chunk_defaults][:fig_path] = fig_path
|
||||
rcParams[:chunk_defaults][:fig_path] = fig_path
|
||||
docParams[:fig_path] = fig_path
|
||||
return nothing
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue