Merge pull request #23 from wildart/tangle

Code extraction into an Julia source file
pull/29/head
Matti Pastell 2014-12-21 09:56:22 +02:00
commit fa1691b511
3 changed files with 48 additions and 1 deletions

View File

@ -47,6 +47,28 @@ end
#module ReportSandBox
#end
function tangle(source ; out_path=:doc, informat="noweb")
cwd, fname = splitdir(abspath(source))
basename = splitext(fname)[1]
#Set the output directory
if out_path == :pwd
cwd = pwd()
elseif out_path != :doc
cwd = out_path
end
outname = "$(cwd)/$(basename).jl"
open(outname, "w") do io
for chunk in read_document(source, informat)
if chunk[:type] == "code"
write(io, chunk[:content]*"\n")
end
end
end
info("Writing to file $(basename).jl")
end
function weave(source ; doctype = "pandoc", plotlib="Gadfly", informat="noweb", out_path=:doc, fig_path = "figures", fig_ext = nothing)
@ -275,7 +297,7 @@ function get_figname(report::Report, chunk; fignum = nothing)
return full_name, rel_name
end
export weave, list_out_formats
export weave, list_out_formats, tangle
include("config.jl")
include("readers.jl")

View File

@ -21,3 +21,8 @@ weave("documents/chunk_options.noweb", doctype="rst", plotlib=nothing)
result = readall(open("documents/chunk_options.rst"))
ref = readall(open("documents/chunk_options_ref.rst"))
@test result == ref
tangle("documents/chunk_options.noweb")
result = readall(open("documents/chunk_options.jl"))
ref = readall(open("documents/chunk_options_ref.jl"))
@test result == ref

View File

@ -0,0 +1,20 @@
y= [2, 5, 12]
x = [12, 10]
println(y)
println(x)
println("Results without code")
println(x)
y = randn(5)
println("Don't eval, but show code")
y = 1:5
println(y)
a = "Don't print me"
println(a)
println("No markup for results.")