Fix `include_weave`. Closes #152.

pull/202/head
Matti Pastell 2019-03-11 14:05:06 +02:00
parent 83e2e0ae20
commit 8194c8a1b8
3 changed files with 37 additions and 3 deletions

View File

@ -198,19 +198,19 @@ function notebook(source::String, out_path=:pwd, timeout=-1, nbconvert_options=[
end end
""" """
include_weave(doc, informat=:auto) include_weave(m::Module, doc, informat=:auto)
Include code from Weave document calling `include_string` on Include code from Weave document calling `include_string` on
all code from doc. Code is run in the path of the include document. all code from doc. Code is run in the path of the include document.
""" """
function include_weave(source, informat=:auto) function include_weave(m::Module, source, informat=:auto)
old_path = pwd() old_path = pwd()
doc = read_doc(source, informat) doc = read_doc(source, informat)
cd(doc.path) cd(doc.path)
try try
code = join([x.content for x in code = join([x.content for x in
filter(x -> isa(x,Weave.CodeChunk), doc.chunks)], "\n") filter(x -> isa(x,Weave.CodeChunk), doc.chunks)], "\n")
include_string(code) include_string(m, code)
catch e catch e
cd(old_path) cd(old_path)
throw(e) throw(e)

View File

@ -0,0 +1,27 @@
---
title : Someheader
---
```julia
module Test1
x = 10
y = 20
function testing(x)
return x
end
end
```
Some random text in between
```julia
module Test2
d = Dict("a" => "α")
doc = read("header_test.jmd", String)
end
```

View File

@ -33,3 +33,10 @@ wdoc = weavestring(smod)
sdoc = weavestring(smod, mod=:sandbox) sdoc = weavestring(smod, mod=:sandbox)
@test occursin(r"Main.WeaveSandBox[0-9]*.TestMod\n", sdoc.chunks[1].output) @test occursin(r"Main.WeaveSandBox[0-9]*.TestMod\n", sdoc.chunks[1].output)
@test sdoc.chunks[2].output == "x" @test sdoc.chunks[2].output == "x"
include_weave(Main, joinpath(@__DIR__, "documents/include_test.jmd"))
@test Test1.x == 10
@test Test1.y == 20
@test Test1.testing("weave") == "weave"
@test Test2.d["a"] == "α"
@test split(Test2.doc, r"\r\n|\n")[1] == "---"