mirror of https://github.com/mpastell/Weave.jl
Changed readall to @compat readstring
parent
f62a315dc0
commit
54a9a79e98
|
@ -1,10 +1,9 @@
|
||||||
% Weave.jl example document: Embedding Gadfly plots
|
% Intro to Weave.jl with Gadfly
|
||||||
% Matti Pastell
|
% Matti Pastell
|
||||||
% 20th April 2016
|
% 20th April 2016
|
||||||
|
|
||||||
|
|
||||||
If you have Weave.jl installed you can run this document with output
|
|
||||||
to your working directory using:
|
|
||||||
|
|
||||||
```julia
|
```julia
|
||||||
using Weave
|
using Weave
|
||||||
|
|
|
@ -21,7 +21,7 @@ function pandoc2html(formatted::AbstractString, doc::WeaveDoc)
|
||||||
html =""
|
html =""
|
||||||
|
|
||||||
try
|
try
|
||||||
#html = readall(
|
#html = @compat readstring(
|
||||||
run(pipeline(`echo $formatted` ,
|
run(pipeline(`echo $formatted` ,
|
||||||
`pandoc -R -s --mathjax --self-contained --highlight-style=tango
|
`pandoc -R -s --mathjax --self-contained --highlight-style=tango
|
||||||
--template $html_template --include-in-header=$css_template
|
--template $html_template --include-in-header=$css_template
|
||||||
|
|
|
@ -15,14 +15,13 @@ const input_formats = @compat Dict{AbstractString, Any}(
|
||||||
|
|
||||||
"""Read and parse input document"""
|
"""Read and parse input document"""
|
||||||
function read_doc(source::AbstractString, format="noweb"::AbstractString)
|
function read_doc(source::AbstractString, format="noweb"::AbstractString)
|
||||||
document = readall(source)
|
document = @compat readstring(source)
|
||||||
parsed = parse_doc(document, format)
|
parsed = parse_doc(document, format)
|
||||||
doc = WeaveDoc(source, parsed)
|
doc = WeaveDoc(source, parsed)
|
||||||
end
|
end
|
||||||
|
|
||||||
"""Parse chunks from AbstractString"""
|
"""Parse chunks from AbstractString"""
|
||||||
function parse_doc(document::AbstractString, format="noweb"::AbstractString)
|
function parse_doc(document::AbstractString, format="noweb"::AbstractString)
|
||||||
#doctext = readall(open(document))
|
|
||||||
lines = split(document, "\n")
|
lines = split(document, "\n")
|
||||||
|
|
||||||
codestart = input_formats[format][:codestart]
|
codestart = input_formats[format][:codestart]
|
||||||
|
|
|
@ -130,7 +130,7 @@ function capture_output(expr::Expr, SandBox::Module, term, plotlib)
|
||||||
finally
|
finally
|
||||||
redirect_stdout(oldSTDOUT)
|
redirect_stdout(oldSTDOUT)
|
||||||
close(wr)
|
close(wr)
|
||||||
out = readall(rw)
|
out = @compat readstring(rw)
|
||||||
close(rw)
|
close(rw)
|
||||||
end
|
end
|
||||||
return (obj, out)
|
return (obj, out)
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
using Weave
|
using Weave, Compat
|
||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
#Test if running document with and without cache works
|
#Test if running document with and without cache works
|
||||||
isdir("documents/cache") && rm("documents/cache", recursive = true)
|
isdir("documents/cache") && rm("documents/cache", recursive = true)
|
||||||
weave("documents/chunk_options.noweb", plotlib=nothing, cache=:all)
|
weave("documents/chunk_options.noweb", plotlib=nothing, cache=:all)
|
||||||
result = readall(open("documents/chunk_options.md"))
|
result = @compat readstring(open("documents/chunk_options.md"))
|
||||||
rm("documents/chunk_options.md")
|
rm("documents/chunk_options.md")
|
||||||
weave("documents/chunk_options.noweb", plotlib=nothing, cache=:all)
|
weave("documents/chunk_options.noweb", plotlib=nothing, cache=:all)
|
||||||
cached_result = readall(open("documents/chunk_options.md"))
|
cached_result = @compat readstring(open("documents/chunk_options.md"))
|
||||||
@test result == cached_result
|
@test result == cached_result
|
||||||
|
|
||||||
# cache = :user
|
# cache = :user
|
||||||
isdir("documents/cache") && rm("documents/cache", recursive = true)
|
isdir("documents/cache") && rm("documents/cache", recursive = true)
|
||||||
out = "documents/chunk_cache.md"
|
out = "documents/chunk_cache.md"
|
||||||
Weave.weave("documents/chunk_cache.noweb", plotlib=nothing, cache=:user);
|
Weave.weave("documents/chunk_cache.noweb", plotlib=nothing, cache=:user);
|
||||||
result = readall(open(out))
|
result = @compat readstring(open(out))
|
||||||
rm(out)
|
rm(out)
|
||||||
Weave.weave("documents/chunk_cache.noweb", plotlib=nothing, cache=:user);
|
Weave.weave("documents/chunk_cache.noweb", plotlib=nothing, cache=:user);
|
||||||
cached_result = readall(open(out))
|
cached_result = @compat readstring(open(out))
|
||||||
@test result == cached_result
|
@test result == cached_result
|
||||||
|
|
||||||
if VERSION.minor == 3
|
if VERSION.minor == 3
|
||||||
|
@ -25,9 +25,9 @@ if VERSION.minor == 3
|
||||||
isdir("documents/cache") && rm("documents/cache", recursive = true)
|
isdir("documents/cache") && rm("documents/cache", recursive = true)
|
||||||
#Caching with Gadfly
|
#Caching with Gadfly
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="tex", plotlib="gadfly", cache=:all)
|
weave("documents/gadfly_formats_test.txt", doctype="tex", plotlib="gadfly", cache=:all)
|
||||||
result = readall(open("documents/gadfly_formats_test.tex"))
|
result = @compat readstring(open("documents/gadfly_formats_test.tex"))
|
||||||
rm("documents/gadfly_formats_test.tex")
|
rm("documents/gadfly_formats_test.tex")
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="tex", plotlib="gadfly", cache=:all)
|
weave("documents/gadfly_formats_test.txt", doctype="tex", plotlib="gadfly", cache=:all)
|
||||||
cached_result = readall(open("documents/gadfly_formats_test.tex"))
|
cached_result = @compat readstring(open("documents/gadfly_formats_test.tex"))
|
||||||
@test result == cached_result
|
@test result == cached_result
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
using Weave
|
using Weave, Compat
|
||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
cleanup = true
|
cleanup = true
|
||||||
|
|
||||||
#Test chunk options and output formats
|
#Test chunk options and output formats
|
||||||
weave("documents/chunk_options.noweb", plotlib=nothing)
|
weave("documents/chunk_options.noweb", plotlib=nothing)
|
||||||
result = readall(open("documents/chunk_options.md"))
|
result = @compat readstring(open("documents/chunk_options.md"))
|
||||||
ref = readall(open("documents/chunk_options_ref.md"))
|
ref = @compat readstring(open("documents/chunk_options_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/chunk_options.md")
|
cleanup && rm("documents/chunk_options.md")
|
||||||
|
|
||||||
weave("documents/chunk_options.noweb", doctype="tex", plotlib=nothing)
|
weave("documents/chunk_options.noweb", doctype="tex", plotlib=nothing)
|
||||||
result = readall(open("documents/chunk_options.tex"))
|
result = @compat readstring(open("documents/chunk_options.tex"))
|
||||||
ref = readall(open("documents/chunk_options_ref.tex"))
|
ref = @compat readstring(open("documents/chunk_options_ref.tex"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/chunk_options.tex")
|
cleanup && rm("documents/chunk_options.tex")
|
||||||
|
|
||||||
weave("documents/chunk_options.noweb", doctype="texminted", plotlib=nothing)
|
weave("documents/chunk_options.noweb", doctype="texminted", plotlib=nothing)
|
||||||
result = readall(open("documents/chunk_options.tex"))
|
result = @compat readstring(open("documents/chunk_options.tex"))
|
||||||
ref = readall(open("documents/chunk_options_ref.texminted"))
|
ref = @compat readstring(open("documents/chunk_options_ref.texminted"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/chunk_options.tex")
|
cleanup && rm("documents/chunk_options.tex")
|
||||||
|
|
||||||
weave("documents/chunk_options.noweb", doctype="rst", plotlib=nothing)
|
weave("documents/chunk_options.noweb", doctype="rst", plotlib=nothing)
|
||||||
result = readall(open("documents/chunk_options.rst"))
|
result = @compat readstring(open("documents/chunk_options.rst"))
|
||||||
ref = readall(open("documents/chunk_options_ref.rst"))
|
ref = @compat readstring(open("documents/chunk_options_ref.rst"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/chunk_options.rst")
|
cleanup && rm("documents/chunk_options.rst")
|
||||||
|
|
||||||
tangle("documents/chunk_options.noweb")
|
tangle("documents/chunk_options.noweb")
|
||||||
result = readall(open("documents/chunk_options.jl"))
|
result = @compat readstring(open("documents/chunk_options.jl"))
|
||||||
ref = readall(open("documents/chunk_options_ref.jl"))
|
ref = @compat readstring(open("documents/chunk_options_ref.jl"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/chunk_options.jl")
|
cleanup && rm("documents/chunk_options.jl")
|
||||||
|
|
||||||
#Test functions and sandbox clearing
|
#Test functions and sandbox clearing
|
||||||
weave("documents/chunk_func.noweb", plotlib=nothing)
|
weave("documents/chunk_func.noweb", plotlib=nothing)
|
||||||
result = readall(open("documents/chunk_func.md"))
|
result = @compat readstring(open("documents/chunk_func.md"))
|
||||||
ref = readall(open("documents/chunk_func_ref.md"))
|
ref = @compat readstring(open("documents/chunk_func_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/chunk_func.md")
|
cleanup && rm("documents/chunk_func.md")
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
using Weave
|
using Weave, Compat
|
||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
cleanup = true
|
cleanup = true
|
||||||
|
|
||||||
#Test hold and term options
|
#Test hold and term options
|
||||||
weave("documents/test_hold.mdw", doctype="pandoc", plotlib="Gadfly")
|
weave("documents/test_hold.mdw", doctype="pandoc", plotlib="Gadfly")
|
||||||
result = readall(open("documents/test_hold.md"))
|
result = @compat readstring(open("documents/test_hold.md"))
|
||||||
ref = readall(open("documents/test_hold_ref.md"))
|
ref = @compat readstring(open("documents/test_hold_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/test_hold.md")
|
cleanup && rm("documents/test_hold.md")
|
||||||
|
|
||||||
#Test setting and restoring chunk options
|
#Test setting and restoring chunk options
|
||||||
Weave.weave("documents/default_opts.noweb", doctype = "tex")
|
Weave.weave("documents/default_opts.noweb", doctype = "tex")
|
||||||
result = readall(open("documents/default_opts.tex"))
|
result = @compat readstring(open("documents/default_opts.tex"))
|
||||||
ref = readall(open("documents/default_opts_ref.tex"))
|
ref = @compat readstring(open("documents/default_opts_ref.tex"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
cleanup && rm("documents/default_opts.tex")
|
cleanup && rm("documents/default_opts.tex")
|
||||||
|
|
|
@ -1,51 +1,51 @@
|
||||||
#Test for Gadfly with different chunk options and figure formats
|
#Test for Gadfly with different chunk options and figure formatsusing Weave
|
||||||
using Weave
|
using Weave, Compat
|
||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", "tex")
|
weave("documents/gadfly_formats_test.txt", "tex")
|
||||||
result = readall(open("documents/gadfly_formats_test.tex"))
|
result = @compat readstring(open("documents/gadfly_formats_test.tex"))
|
||||||
ref = readall(open("documents/gadfly_formats_test_ref.tex"))
|
ref = @compat readstring(open("documents/gadfly_formats_test_ref.tex"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".tex", plotlib="gadfly")
|
weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".tex", plotlib="gadfly")
|
||||||
result = readall(open("documents/gadfly_formats_test.tex"))
|
result = @compat readstring(open("documents/gadfly_formats_test.tex"))
|
||||||
ref = readall(open("documents/gadfly_formats_test_tikz_ref.tex"))
|
ref = @compat readstring(open("documents/gadfly_formats_test_tikz_ref.tex"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".ps", plotlib="gadfly")
|
weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".ps", plotlib="gadfly")
|
||||||
result = readall(open("documents/gadfly_formats_test.tex"))
|
result = @compat readstring(open("documents/gadfly_formats_test.tex"))
|
||||||
ref = readall(open("documents/gadfly_formats_test_ps_ref.tex"))
|
ref = @compat readstring(open("documents/gadfly_formats_test_ps_ref.tex"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly")
|
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly")
|
||||||
result = readall(open("documents/gadfly_formats_test.md"))
|
result = @compat readstring(open("documents/gadfly_formats_test.md"))
|
||||||
ref = readall(open("documents/gadfly_formats_test_pandoc_ref.md"))
|
ref = @compat readstring(open("documents/gadfly_formats_test_pandoc_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg")
|
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg")
|
||||||
result = readall(open("documents/gadfly_formats_test.md"))
|
result = @compat readstring(open("documents/gadfly_formats_test.md"))
|
||||||
ref = readall(open("documents/gadfly_formats_test_svg_ref.md"))
|
ref = @compat readstring(open("documents/gadfly_formats_test_svg_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg")
|
weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg")
|
||||||
result = readall(open("documents/gadfly_formats_test.md"))
|
result = @compat readstring(open("documents/gadfly_formats_test.md"))
|
||||||
ref = readall(open("documents/gadfly_formats_test_jssvg_ref.md"))
|
ref = @compat readstring(open("documents/gadfly_formats_test_jssvg_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly")
|
weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly")
|
||||||
result = readall(open("documents/gadfly_formats_test.rst"))
|
result = @compat readstring(open("documents/gadfly_formats_test.rst"))
|
||||||
ref = readall(open("documents/gadfly_formats_test_ref.rst"))
|
ref = @compat readstring(open("documents/gadfly_formats_test_ref.rst"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/gadfly_formats_test.txt", doctype="asciidoc", plotlib="gadfly",
|
weave("documents/gadfly_formats_test.txt", doctype="asciidoc", plotlib="gadfly",
|
||||||
out_path="documents/output")
|
out_path="documents/output")
|
||||||
result = readall(open("documents/output/gadfly_formats_test.txt"))
|
result = @compat readstring(open("documents/output/gadfly_formats_test.txt"))
|
||||||
ref = readall(open("documents/output/gadfly_formats_test_ref.txt"))
|
ref = @compat readstring(open("documents/output/gadfly_formats_test_ref.txt"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown")
|
weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown")
|
||||||
result = readall(open("documents/gadfly_markdown_test.md"))
|
result = @compat readstring(open("documents/gadfly_markdown_test.md"))
|
||||||
ref = readall(open("documents/gadfly_markdown_test_ref.md"))
|
ref = @compat readstring(open("documents/gadfly_markdown_test_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
using Weave
|
using Weave, Compat
|
||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
cleanup = true
|
cleanup = true
|
||||||
|
|
||||||
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="tex")
|
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="tex")
|
||||||
result = readall(open("documents/pyplot_formats.tex"))
|
result = @compat readstring(open("documents/pyplot_formats.tex"))
|
||||||
ref = readall(open("documents/pyplot_formats_ref.tex"))
|
ref = @compat readstring(open("documents/pyplot_formats_ref.tex"))
|
||||||
result = replace(result, r"\s*PyObject.*\n", "\n") #Remove PyObjects, because they change
|
result = replace(result, r"\s*PyObject.*\n", "\n") #Remove PyObjects, because they change
|
||||||
ref = replace(ref, r"\s*PyObject.*\n", "\n")
|
ref = replace(ref, r"\s*PyObject.*\n", "\n")
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="github")
|
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="github")
|
||||||
result = readall(open("documents/pyplot_formats.md"))
|
result = @compat readstring(open("documents/pyplot_formats.md"))
|
||||||
ref = readall(open("documents/pyplot_formats_ref.md"))
|
ref = @compat readstring(open("documents/pyplot_formats_ref.md"))
|
||||||
result = replace(result, r"\s*PyObject.*\n", "")
|
result = replace(result, r"\s*PyObject.*\n", "")
|
||||||
ref = replace(ref, r"\s*PyObject.*\n", "")
|
ref = replace(ref, r"\s*PyObject.*\n", "")
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
|
|
||||||
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="rst", fig_ext=".svg")
|
weave("documents/pyplot_formats.txt", plotlib="pyplot", doctype="rst", fig_ext=".svg")
|
||||||
result = readall(open("documents/pyplot_formats.rst"))
|
result = @compat readstring(open("documents/pyplot_formats.rst"))
|
||||||
ref = readall(open("documents/pyplot_formats_ref.rst"))
|
ref = @compat readstring(open("documents/pyplot_formats_ref.rst"))
|
||||||
result = replace(result, r"\s*PyObject.*\n", "")
|
result = replace(result, r"\s*PyObject.*\n", "")
|
||||||
ref = replace(ref, r"\s*PyObject.*\n", "")
|
ref = replace(ref, r"\s*PyObject.*\n", "")
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
using Weave
|
using Weave, Compat
|
||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
weave("documents/winston_formats.txt", plotlib="Winston", doctype="tex")
|
weave("documents/winston_formats.txt", plotlib="Winston", doctype="tex")
|
||||||
result = readall(open("documents/winston_formats.tex"))
|
result = @compat readstring(open("documents/winston_formats.tex"))
|
||||||
ref = readall(open("documents/winston_formats_ref.tex"))
|
ref = @compat readstring(open("documents/winston_formats_ref.tex"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
|
|
||||||
weave("documents/winston_formats.txt", plotlib="Winston", doctype="github")
|
weave("documents/winston_formats.txt", plotlib="Winston", doctype="github")
|
||||||
result = readall(open("documents/winston_formats.md"))
|
result = @compat readstring(open("documents/winston_formats.md"))
|
||||||
ref = readall(open("documents/winston_formats_ref.md"))
|
ref = @compat readstring(open("documents/winston_formats_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/winston_formats.txt", plotlib="Winston", doctype="pandoc", fig_ext=".svg")
|
weave("documents/winston_formats.txt", plotlib="Winston", doctype="pandoc", fig_ext=".svg")
|
||||||
result = readall(open("documents/winston_formats.md"))
|
result = @compat readstring(open("documents/winston_formats.md"))
|
||||||
ref = readall(open("documents/winston_formats_svg_ref.md"))
|
ref = @compat readstring(open("documents/winston_formats_svg_ref.md"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
||||||
weave("documents/winston_formats.txt", plotlib="Winston", doctype="rst")
|
weave("documents/winston_formats.txt", plotlib="Winston", doctype="rst")
|
||||||
result = readall(open("documents/winston_formats.rst"))
|
result = @compat readstring(open("documents/winston_formats.rst"))
|
||||||
ref = readall(open("documents/winston_formats_ref.rst"))
|
ref = @compat readstring(open("documents/winston_formats_ref.rst"))
|
||||||
@test result == ref
|
@test result == ref
|
||||||
|
|
Loading…
Reference in New Issue