2015-01-08 17:52:42 +01:00
|
|
|
|
import JSON
|
|
|
|
|
|
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)
|
|
|
|
|
name = "$cache_dir/$(doc.basename).json"
|
|
|
|
|
open(name, "w") do io
|
|
|
|
|
write(io, JSON.json(doc))
|
|
|
|
|
end
|
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)
|
2015-01-08 17:52:42 +01:00
|
|
|
|
name = "$(doc.cwd)/$cache_path/$(doc.basename).json"
|
2015-01-07 15:37:02 +01:00
|
|
|
|
isfile(name) || return nothing
|
2015-01-08 17:52:42 +01:00
|
|
|
|
parsed = JSON.parsefile(name)
|
2015-01-07 11:20:48 +01:00
|
|
|
|
end
|
|
|
|
|
|
2015-01-08 17:52:42 +01:00
|
|
|
|
#read_cache returns a dictionary, parse to back to chunk
|
|
|
|
|
function restore_chunk(chunk::CodeChunk, cached, idx)
|
|
|
|
|
options = Dict{Symbol, Any}()
|
|
|
|
|
for (keys,vals) = cached["chunks"][idx]["options"]
|
|
|
|
|
options[symbol(keys)] = vals
|
|
|
|
|
end
|
|
|
|
|
haskey(options, :term_state) && (options[:term_state] = symbol(options[:term_state]))
|
|
|
|
|
|
|
|
|
|
chunk.options = options
|
|
|
|
|
chunk.content = cached["chunks"][idx]["content"]
|
|
|
|
|
chunk.output = cached["chunks"][idx]["output"]
|
|
|
|
|
chunk.figures = cached["chunks"][idx]["figures"]
|
2015-01-07 11:20:48 +01:00
|
|
|
|
|
2015-01-08 17:52:42 +01:00
|
|
|
|
return chunk
|
|
|
|
|
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
|
|
|
|
|
#function restore_chunk(chunk::DocChunk, cached, idx)
|
|
|
|
|
# chunk
|
|
|
|
|
#end
|