From 4a89b047596a612f8cc9f623d40b26f36ac4b6e3 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sat, 13 Jun 2020 20:45:06 +0900 Subject: [PATCH] fix `get_cwd` --- src/run.jl | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/run.jl b/src/run.jl index d956e84..82fbd87 100644 --- a/src/run.jl +++ b/src/run.jl @@ -21,7 +21,7 @@ function run_doc( doc.format = deepcopy(FORMATS[doctype]) cwd = doc.cwd = get_cwd(doc, out_path) - isdir(cwd) || mkpath(cwd) + isdir(cwd) || mkdir(cwd) if isnothing(fig_path) fig_path = if (endswith(doctype, "2pdf") && cache === :off) || endswith(doctype, "2html") @@ -114,6 +114,21 @@ function detect_doctype(path) return "pandoc" end +function get_cwd(doc, out_path) + return if out_path === :doc + dirname(doc.path) + elseif out_path === :pwd + pwd() + else + path, ext = splitext(out_path) + if isempty(ext) # directory given + path + else # file given + dirname(path) + end + end |> abspath +end + function run_chunk(chunk::CodeChunk, doc, report, mod) result = eval_chunk(doc, chunk, report, mod) occursin("2html", doc.doctype) && (embed_figures!(result, report.cwd)) @@ -329,24 +344,6 @@ function get_figname(report::Report, chunk; fignum = nothing, ext = nothing) return full_name, rel_name end -function get_cwd(doc::WeaveDoc, out_path) - # Set the output directory - if out_path === :doc - cwd = dirname(doc.path) - elseif out_path === :pwd - cwd = pwd() - else - # If there is no extension, use as path - splitted = splitext(out_path) - if splitted[2] == "" - cwd = expanduser(out_path) - else - cwd = splitdir(expanduser(out_path))[1] - end - end - return cwd -end - """Get output file name based on out_path""" function get_outname(out_path::Symbol, doc::WeaveDoc; ext = nothing) isnothing(ext) && (ext = doc.format.extension)