2014-12-08 09:25:57 +01:00
|
|
|
module Weave
|
2014-12-01 19:31:44 +01:00
|
|
|
using Compat
|
2014-11-24 23:08:25 +01:00
|
|
|
|
2014-11-25 00:10:48 +01:00
|
|
|
|
2016-04-19 14:23:48 +02:00
|
|
|
"""
|
2016-04-20 10:16:50 +02:00
|
|
|
`list_out_formats()`
|
2016-04-19 14:23:48 +02:00
|
|
|
|
|
|
|
List supported output formats
|
|
|
|
"""
|
2014-12-05 22:33:54 +01:00
|
|
|
function list_out_formats()
|
|
|
|
for format = keys(formats)
|
2016-04-12 16:35:12 +02:00
|
|
|
println(string(format,": ", formats[format].description))
|
2014-12-05 22:33:54 +01:00
|
|
|
end
|
|
|
|
end
|
2014-12-03 08:21:56 +01:00
|
|
|
|
2014-11-25 00:10:48 +01:00
|
|
|
|
2016-04-19 14:23:48 +02:00
|
|
|
"""
|
2016-04-20 10:16:50 +02:00
|
|
|
`tangle(source ; out_path=:doc, informat="noweb")`
|
2016-04-19 14:23:48 +02:00
|
|
|
|
|
|
|
Tangle source code from input document to .jl file.
|
2015-01-01 22:36:58 +01:00
|
|
|
|
|
|
|
* `informat`: `"noweb"` of `"markdown"`
|
2016-04-24 14:02:03 +02:00
|
|
|
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory, `"somepath"`, directory name as a string e.g `"/home/mpastell/weaveout"`
|
|
|
|
or filename as string e.g. ~/outpath/outfile.jl.
|
2016-04-19 14:23:48 +02:00
|
|
|
"""
|
2016-04-22 14:39:25 +02:00
|
|
|
function tangle(source ; out_path=:doc, informat=:auto)
|
2015-01-06 23:01:25 +01:00
|
|
|
doc = read_doc(source, informat)
|
2016-04-24 14:02:03 +02:00
|
|
|
doc.cwd = get_cwd(doc, out_path)
|
2015-01-01 22:36:58 +01:00
|
|
|
|
2016-04-24 14:02:03 +02:00
|
|
|
outname = get_outname(out_path, doc, ext = "jl")
|
2016-04-27 13:51:15 +02:00
|
|
|
|
2016-04-24 14:02:03 +02:00
|
|
|
open(outname, "w") do io
|
2016-04-22 08:26:27 +02:00
|
|
|
for chunk in doc.chunks
|
|
|
|
if typeof(chunk) == CodeChunk
|
|
|
|
options = merge(rcParams[:chunk_defaults], chunk.options)
|
|
|
|
if options[:tangle]
|
|
|
|
write(io, chunk.content*"\n")
|
|
|
|
end
|
|
|
|
end
|
2014-12-21 08:25:45 +01:00
|
|
|
end
|
2016-04-22 08:26:27 +02:00
|
|
|
end
|
2016-04-24 14:02:03 +02:00
|
|
|
doc.cwd == pwd() && (outname = basename(outname))
|
|
|
|
info("Writing to file $outname")
|
2014-12-21 08:25:45 +01:00
|
|
|
end
|
2014-12-03 08:21:56 +01:00
|
|
|
|
2016-04-24 14:02:03 +02:00
|
|
|
|
2016-04-19 14:23:48 +02:00
|
|
|
"""
|
2016-04-22 15:16:12 +02:00
|
|
|
`function weave(source ; doctype = :auto, plotlib="Gadfly",
|
|
|
|
informat=:auto, out_path=:doc, fig_path = "figures", fig_ext = nothing,
|
|
|
|
cache_path = "cache", cache=:off)`
|
2016-04-19 14:23:48 +02:00
|
|
|
|
|
|
|
Weave an input document to output file.
|
2015-01-01 22:32:15 +01:00
|
|
|
|
2016-04-22 15:16:12 +02:00
|
|
|
* `doctype`: :auto = set based on file extension or specify one of the supported formats.
|
|
|
|
See `list_out_formats()`
|
2016-04-19 15:38:03 +02:00
|
|
|
* `plotlib`: `"PyPlot"`, `"Gadfly"` or `nothing`
|
2016-04-22 15:16:12 +02:00
|
|
|
* `informat`: :auto = set based on file extension or set to `"noweb"`, `"markdown"` or `script`
|
2016-04-24 14:02:03 +02:00
|
|
|
* `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.
|
2015-01-01 22:32:15 +01:00
|
|
|
* `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`.
|
2015-01-08 17:52:42 +01:00
|
|
|
* `cache_path`: where of cached output will be saved.
|
|
|
|
* `cache`: controls caching of code: `:off` = no caching, `:all` = cache everything,
|
|
|
|
`:user` = cache based on chunk options, `:refresh`, run all code chunks and save new cache.
|
2015-01-01 22:32:15 +01:00
|
|
|
|
|
|
|
**Note:** Run Weave from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
|
2016-04-19 14:23:48 +02:00
|
|
|
"""
|
2016-04-22 15:16:12 +02:00
|
|
|
function weave(source ; doctype = :auto, plotlib="Gadfly",
|
2016-04-22 14:39:25 +02:00
|
|
|
informat=:auto, out_path=:doc, fig_path = "figures", fig_ext = nothing,
|
2015-01-08 17:52:42 +01:00
|
|
|
cache_path = "cache", cache=:off)
|
2014-11-26 22:29:25 +01:00
|
|
|
|
2016-04-20 10:16:50 +02:00
|
|
|
doc = read_doc(source, informat)
|
2015-01-06 23:01:25 +01:00
|
|
|
doc = run(doc, doctype = doctype, plotlib=plotlib,
|
2016-04-22 14:39:25 +02:00
|
|
|
out_path=out_path,
|
2015-01-08 17:52:42 +01:00
|
|
|
fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache)
|
2015-01-06 23:01:25 +01:00
|
|
|
formatted = format(doc)
|
2014-12-01 20:23:35 +01:00
|
|
|
|
2016-04-20 17:34:24 +02:00
|
|
|
formatted = join(formatted, "\n")
|
2016-04-20 14:41:54 +02:00
|
|
|
|
2016-04-24 14:02:03 +02:00
|
|
|
outname = get_outname(out_path, doc)
|
2016-04-20 17:34:24 +02:00
|
|
|
|
2014-12-02 19:42:12 +01:00
|
|
|
open(outname, "w") do io
|
2016-04-20 14:41:54 +02:00
|
|
|
write(io, formatted)
|
2014-12-02 19:42:12 +01:00
|
|
|
end
|
2014-12-03 14:41:53 +01:00
|
|
|
|
2016-04-20 17:34:24 +02:00
|
|
|
#Convert using pandoc
|
|
|
|
if doc.doctype == "md2html"
|
2016-04-24 14:02:03 +02:00
|
|
|
outname = get_outname(out_path, doc, ext = "html")
|
|
|
|
pandoc2html(formatted, doc, outname)
|
2016-04-20 17:34:24 +02:00
|
|
|
elseif doc.doctype == "md2pdf"
|
2016-04-24 14:02:03 +02:00
|
|
|
outname = get_outname(out_path, doc, ext = "pdf")
|
|
|
|
pandoc2pdf(formatted, doc, outname)
|
2016-04-20 17:34:24 +02:00
|
|
|
end
|
|
|
|
|
2016-04-24 14:02:03 +02:00
|
|
|
doc.cwd == pwd() && (outname = basename(outname))
|
|
|
|
|
|
|
|
info("Report weaved to $outname")
|
2014-11-25 00:10:48 +01:00
|
|
|
end
|
|
|
|
|
2014-12-03 14:41:53 +01:00
|
|
|
|
2016-04-11 17:40:18 +02:00
|
|
|
function weave(doc::AbstractString, doctype::AbstractString)
|
2015-01-08 23:05:46 +01:00
|
|
|
weave(doc, doctype=doctype)
|
|
|
|
end
|
2014-12-03 14:41:53 +01:00
|
|
|
|
2016-04-20 10:16:50 +02:00
|
|
|
export weave, list_out_formats, tangle,
|
|
|
|
set_chunk_defaults, get_chunk_defaults, restore_chunk_defaults
|
2015-01-04 14:45:41 +01:00
|
|
|
|
2014-11-26 22:29:25 +01:00
|
|
|
include("config.jl")
|
2015-01-07 15:37:02 +01:00
|
|
|
include("chunks.jl")
|
2016-04-27 13:51:15 +02:00
|
|
|
include("display_methods.jl")
|
2014-11-26 22:29:25 +01:00
|
|
|
include("readers.jl")
|
2015-01-07 15:37:02 +01:00
|
|
|
include("run.jl")
|
|
|
|
include("cache.jl")
|
2014-12-02 15:57:00 +01:00
|
|
|
include("formatters.jl")
|
2016-04-20 14:41:54 +02:00
|
|
|
include("pandoc.jl")
|
2014-11-25 00:10:48 +01:00
|
|
|
end
|