From 60cae56a16ac69701cb7998e8556e9b4ac70d747 Mon Sep 17 00:00:00 2001 From: ig-or <19777752+ig-or@users.noreply.github.com> Date: Wed, 8 May 2024 12:58:28 -0700 Subject: [PATCH] trying to use artifacts --- Artifacts.toml | 9 +++++++++ Project.toml | 1 + docs/src/index.md | 4 ++-- src/Picture.jl | 4 ++-- src/constants.jl | 2 -- src/write.jl | 5 +++-- test/testArtifacts.jl | 10 ++++++++++ test/testConstructors.jl | 8 ++++---- test/testPresentationState.jl | 2 +- test/testSlideXML.jl | 2 +- test/testTables.jl | 4 ++-- test/testWriting.jl | 12 ++++++------ 12 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 Artifacts.toml create mode 100644 test/testArtifacts.jl diff --git a/Artifacts.toml b/Artifacts.toml new file mode 100644 index 0000000..e849972 --- /dev/null +++ b/Artifacts.toml @@ -0,0 +1,9 @@ +[pptx_data] +git-tree-sha1 = "02f90f83af29c5c2e4b81721ba96ce9efc98741f" + [[pptx_data.download]] + url = "https://github.com/ig-or/PPTX.jl/releases/download/v0.7.0/data.tar.gz" + sha256 = "4e61f7667dbed4f96542401d67d09c78678271ca802613c1ba9c97c988031fb3" + + + + diff --git a/Project.toml b/Project.toml index 223fe1c..4e28126 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Xander de Vries", "Matthijs Cox"] version = "0.7.0" [deps] +Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85" EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615" diff --git a/docs/src/index.md b/docs/src/index.md index 67ffeb6..1d372d2 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -31,14 +31,14 @@ push!(s2, text2) push!(pres, s2) # Now lets add a picture and some text -cauli_pic = Picture(joinpath(PPTX.ASSETS_DIR,"cauliflower.jpg")) +cauli_pic = Picture(joinpath(artifact"pptx_data", "assets","cauliflower.jpg")) text = TextBox(content="Look its a vegetable!") s3 = Slide() push!(s3, cauli_pic) push!(s3, text) # move picture 100 mm down and 100 mm right -julia_logo = Picture(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"), offset_x=100, offset_y=100) +julia_logo = Picture(joinpath(artifact"pptx_data", "assets","julia_logo.png"), offset_x=100, offset_y=100) push!(s3, julia_logo) push!(pres, s3) diff --git a/src/Picture.jl b/src/Picture.jl index 624b6ae..ff67469 100644 --- a/src/Picture.jl +++ b/src/Picture.jl @@ -15,7 +15,7 @@ Internally the sizes are converted EMUs. ```julia julia> using PPTX -julia> img = Picture(joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg")) +julia> img = Picture(joinpath(artifact"pptx_data", "assets", "cauliflower.jpg")) Picture source is "./cauliflower.jpg" offset_x is 0 EMUs @@ -29,7 +29,7 @@ Optionally, you can set the `size_x` and `size_y` manually for filetypes not sup ```julia julia> using PPTX -julia> img = Picture(joinpath(PPTX.ASSETS_DIR, "julia_logo.svg"); size_x=40, size_y=30) +julia> img = Picture(joinpath(artifact"pptx_data", "assets", "julia_logo.svg"); size_x=40, size_y=30) Picture source is "./julia_logo.svg" offset_x is 0 EMUs diff --git a/src/constants.jl b/src/constants.jl index b9db5ea..69dafeb 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -4,8 +4,6 @@ const _EMUS_PER_CM = 360000 const _EMUS_PER_MM = 36000 const _EMUS_PER_PT = 12700 -const TEMPLATE_DIR = abspath(joinpath(@__DIR__, "..", "templates")) -const ASSETS_DIR = abspath(joinpath(@__DIR__, "..", "assets")) const TESTDATA_DIR = abspath(joinpath(@__DIR__, "..", "test/testdata")) # we use layoutSlide1 for the first title slide, and layoutSlide2 for all other slides diff --git a/src/write.jl b/src/write.jl index c149b3c..84e60ca 100644 --- a/src/write.jl +++ b/src/write.jl @@ -1,4 +1,5 @@ import DefaultApplication +using Artifacts function write_presentation!(w::ZipWriter, p::Presentation) xml = make_presentation(p) @@ -67,7 +68,7 @@ function update_table_style!(w::ZipWriter, template::ZipBufferReader) table_style_doc = EzXML.parsexml(zip_readentry(template, table_style_path)) if has_empty_table_list(table_style_doc) table_style_filename = "tableStyles.xml" - default_table_style_file = joinpath(TEMPLATE_DIR, table_style_filename) + default_table_style_file = joinpath(artifact"pptx_data", "templates", table_style_filename) open(default_table_style_file) do io zip_newfile(w, table_style_path; compress=true) write(w, io) @@ -141,7 +142,7 @@ function Base.write( p::Presentation; overwrite::Bool=false, open_ppt::Bool=true, - template_path::String=joinpath(TEMPLATE_DIR, "no-slides.pptx"), + template_path::String=joinpath(artifact"pptx_data", "templates", "no-slides.pptx"), ) template_path = abspath(template_path) diff --git a/test/testArtifacts.jl b/test/testArtifacts.jl new file mode 100644 index 0000000..3cd1b18 --- /dev/null +++ b/test/testArtifacts.jl @@ -0,0 +1,10 @@ +using PPTX +using Test +using Artifacts + +dark_template_name = "no-slides-dark.pptx" +dark_template_path = joinpath(artifact"pptx_data", "templates", dark_template_name) +isfile(dark_template_path) +pres = Presentation(;title="My Presentation") +s = Slide() +push!(pres, s) \ No newline at end of file diff --git a/test/testConstructors.jl b/test/testConstructors.jl index fde5184..45227b3 100644 --- a/test/testConstructors.jl +++ b/test/testConstructors.jl @@ -22,7 +22,7 @@ using Test @test_throws ArgumentError pic = Picture("path") fnames = ["julia_logo.png", "julia_logo.svg", "julia_logo.emf", "julia_dots.wmf"] for fname in fnames - logo_path = joinpath(PPTX.ASSETS_DIR, fname) + logo_path = joinpath(artifact"pptx_data", "assets", fname) pic = Picture(logo_path) @test pic.offset_x == 0 width = 150 @@ -47,7 +47,7 @@ using Test end end @testset "Picture - custom aspect ratio" begin - logo_path = joinpath(PPTX.ASSETS_DIR,"julia_logo.svg") + logo_path = joinpath(artifact"pptx_data", "assets","julia_logo.svg") pic = Picture(logo_path; size_x=40, size_y=30) @test pic.size_x == 1440000 @test pic.size_y == 1080000 @@ -64,14 +64,14 @@ using Test @testset "first slide" begin p = Presentation() @test rid(p.slides[1]) == 6 - picture_path = joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg") + picture_path = joinpath(artifact"pptx_data", "assets", "cauliflower.jpg") p = Presentation([Slide([TextBox(),Picture(picture_path)])]) @test rid(p.slides[1].shapes[1]) == 0 @test rid(p.slides[1].shapes[2]) == 1 end @testset "Slide" begin slide = Slide() - picture_path = joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg") + picture_path = joinpath(artifact"pptx_data", "assets", "cauliflower.jpg") push!(slide, Picture(picture_path)) end end diff --git a/test/testPresentationState.jl b/test/testPresentationState.jl index 1128eab..ff7da30 100644 --- a/test/testPresentationState.jl +++ b/test/testPresentationState.jl @@ -2,7 +2,7 @@ using Test using PPTX @testset "Presentation Size" begin - template_folder = abspath(joinpath(PPTX.TEMPLATE_DIR,"no-slides")) + template_folder = abspath(joinpath(artifact"pptx_data", "templates","no-slides")) p = Presentation() ppt_dir = joinpath(template_folder, "ppt") PPTX.update_presentation_state!(p, ppt_dir) diff --git a/test/testSlideXML.jl b/test/testSlideXML.jl index 35ab19c..220a97b 100644 --- a/test/testSlideXML.jl +++ b/test/testSlideXML.jl @@ -34,7 +34,7 @@ end end @testset "update title in XML" begin - template = ZipBufferReader(read(joinpath(PPTX.TEMPLATE_DIR,"no-slides.pptx"))) + template = ZipBufferReader(read(joinpath(artifact"pptx_data", "templates","no-slides.pptx"))) @testset "slideLayout1.xml" begin slide = Slide(;layout=1) diff --git a/test/testTables.jl b/test/testTables.jl index 9e0e7e8..8ccd0f7 100644 --- a/test/testTables.jl +++ b/test/testTables.jl @@ -51,11 +51,11 @@ using ZipArchives: ZipBufferReader, zip_readentry end @testset "check empty table style list" begin - tableStyles_path = abspath(joinpath(PPTX.TEMPLATE_DIR, "tableStyles.xml")) + tableStyles_path = abspath(joinpath(artifact"pptx_data", "templates", "tableStyles.xml")) table_style_doc = EzXML.parsexml(read(tableStyles_path)) @test !PPTX.has_empty_table_list(table_style_doc) - no_slides_template = ZipBufferReader(read(joinpath(PPTX.TEMPLATE_DIR, "no-slides.pptx"))) + no_slides_template = ZipBufferReader(read(joinpath(artifact"pptx_data", "templates", "no-slides.pptx"))) table_style_doc = EzXML.parsexml(zip_readentry(no_slides_template, "ppt/tableStyles.xml")) @test PPTX.has_empty_table_list(table_style_doc) end \ No newline at end of file diff --git a/test/testWriting.jl b/test/testWriting.jl index dc559e0..3357a2c 100644 --- a/test/testWriting.jl +++ b/test/testWriting.jl @@ -25,7 +25,7 @@ end @testset "writing" begin @testset "push same picture" begin - picture_path = joinpath(PPTX.ASSETS_DIR, "cauliflower.jpg") + picture_path = joinpath(artifact"pptx_data", "assets", "cauliflower.jpg") p = Presentation([Slide([Picture(picture_path)]), Slide([Picture(picture_path)])]) @test write_and_remove("test.pptx", p) end @@ -33,7 +33,7 @@ end @testset "pushing same picture twice" begin pres = Presentation() s1 = Slide() - julia_logo = Picture(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"), top = 110, left = 110) + julia_logo = Picture(joinpath(artifact"pptx_data", "assets","julia_logo.png"), top = 110, left = 110) push!(s1, julia_logo) push!(pres, s1) s2 = Slide() @@ -48,7 +48,7 @@ end # TODO: what if the .pptx template already has slides? @testset "custom template" begin dark_template_name = "no-slides-dark.pptx" - dark_template_path = joinpath(PPTX.TEMPLATE_DIR, dark_template_name) + dark_template_path = joinpath(artifact"pptx_data", "templates", dark_template_name) pres = Presentation(;title="My Presentation") s = Slide() push!(pres, s) @@ -90,18 +90,18 @@ end # test for issue https://github.com/ASML-Labs/PPTX.jl/issues/20 mktempdir() do tmpdir template_name = "no-slides.pptx" - original_template_path = joinpath(PPTX.TEMPLATE_DIR, template_name) + original_template_path = joinpath(artifact"pptx_data", "templates", template_name) edited_template_path = joinpath(tmpdir, template_name) cp(original_template_path, edited_template_path) zip_append_archive(edited_template_path) do w # add an existing media directory zip_newfile(w, "ppt/media/foo.png") - write(w, read(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"))) + write(w, read(joinpath(artifact"pptx_data", "assets","julia_logo.png"))) end pres = Presentation(;title="My Presentation") s1 = Slide() - julia_logo = Picture(joinpath(PPTX.ASSETS_DIR,"julia_logo.png"), top = 110, left = 110) + julia_logo = Picture(joinpath(artifact"pptx_data", "assets","julia_logo.png"), top = 110, left = 110) push!(s1, julia_logo) push!(pres, s1)