2016-04-23 18:18:44 +02:00
|
|
|
|
import JLD
|
2015-01-08 17:52:42 +01:00
|
|
|
|
|
2015-01-07 15:37:02 +01:00
|
|
|
|
function write_cache(doc::WeaveDoc, cache_path)
|
2015-01-08 17:52:42 +01:00
|
|
|
|
cache_dir = "$(doc.cwd)/$cache_path"
|
|
|
|
|
isdir(cache_dir) || mkpath(cache_dir)
|
2016-04-23 17:15:59 +02:00
|
|
|
|
JLD.save("$cache_dir/$(doc.basename).jld", Dict("doc" => doc))
|
2015-01-07 15:37:02 +01:00
|
|
|
|
return nothing
|
|
|
|
|
end
|
2015-01-07 11:20:48 +01:00
|
|
|
|
|
2015-01-07 15:37:02 +01:00
|
|
|
|
function read_cache(doc::WeaveDoc, cache_path)
|
2016-04-23 17:15:59 +02:00
|
|
|
|
name = "$(doc.cwd)/$cache_path/$(doc.basename).jld"
|
2015-01-07 15:37:02 +01:00
|
|
|
|
isfile(name) || return nothing
|
2016-04-23 17:15:59 +02:00
|
|
|
|
return JLD.load(name)["doc"]
|
2015-01-07 11:20:48 +01:00
|
|
|
|
end
|
|
|
|
|
|
2016-04-23 18:18:44 +02:00
|
|
|
|
|
2016-04-23 17:15:59 +02:00
|
|
|
|
function restore_chunk(chunk::CodeChunk, cached)
|
|
|
|
|
chunks = filter(x -> x.number == chunk.number &&
|
|
|
|
|
string(typeof(x)) == "Weave.CodeChunk", cached.chunks)
|
2015-01-08 17:52:42 +01:00
|
|
|
|
|
2016-04-23 18:18:44 +02:00
|
|
|
|
#Chunk types, don't match after loading. Fix by constructing chunks
|
|
|
|
|
#from loaded content
|
2016-04-23 17:15:59 +02:00
|
|
|
|
new_chunks = Any[]
|
|
|
|
|
for c in chunks
|
|
|
|
|
newc = CodeChunk(c.content, c.number, c.start_line, c.optionstring, c.options)
|
|
|
|
|
newc.result_no = c.result_no
|
|
|
|
|
newc.figures = c.figures
|
|
|
|
|
newc.result = c.result
|
2016-04-23 18:18:44 +02:00
|
|
|
|
newc.output = c.output
|
2016-05-02 22:21:34 +02:00
|
|
|
|
newc.rich_output = c.rich_output
|
2016-04-23 17:15:59 +02:00
|
|
|
|
push!(new_chunks, newc)
|
|
|
|
|
end
|
|
|
|
|
return new_chunks
|
2015-01-08 17:52:42 +01:00
|
|
|
|
end
|
2015-01-07 15:37:02 +01:00
|
|
|
|
|
2015-01-08 18:35:47 +01:00
|
|
|
|
#Could be used to restore inline code in future
|
2016-04-23 17:15:59 +02:00
|
|
|
|
function restore_chunk(chunk::DocChunk, cached)
|
|
|
|
|
return chunk
|
|
|
|
|
end
|