Skip to content

Commit

Permalink
Refactor: using the do-block with cd
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijscox-asml committed Feb 10, 2023
1 parent c697a0e commit 2a2b816
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,33 +141,25 @@ function Base.write(
end
end

origin = pwd()
try
mktempdir() do tmpdir
cd(tmpdir)
mktempdir() do tmpdir
cd(tmpdir) do
cp(template_path, template_name)
unzipped_dir = template_name
if template_isfile
unzip(template_name)
unzipped_dir = first(splitext(template_name)) # remove .pptx
end
ppt_dir = joinpath(unzipped_dir, "ppt")
cd(ppt_dir)
write_relationships!(p)
write_presentation!(p)
write_slides!(p)
write_shapes!(p)
update_table_style!()
cd(tmpdir)
cd(ppt_dir) do
write_relationships!(p)
write_presentation!(p)
write_slides!(p)
write_shapes!(p)
update_table_style!()
end
zip(unzipped_dir, filename)
cp(filename, filepath)
# need to cd out of folder, else mktempdir cannot cleanup
cd(origin)
end
catch e
rethrow(e)
finally
cd(origin)
end
if open_ppt
try
Expand Down Expand Up @@ -197,12 +189,13 @@ end
function zip(folder::String, filename::String)
zip_ext_filename = split(filename, ".")[begin] * ".zip"
origin = pwd()
cd(folder)
for f in readdir(".")
run_silent_pipeline(`$(exe7z()) a $zip_ext_filename $f`)
cd(folder) do
for f in readdir(".")
run_silent_pipeline(`$(exe7z()) a $zip_ext_filename $f`)
end
mv(zip_ext_filename, joinpath(origin, filename))
end
mv(zip_ext_filename, joinpath(origin, filename))
return cd(origin)
return nothing
end

# silent, unless we error
Expand Down

0 comments on commit 2a2b816

Please sign in to comment.