diff --git a/Artifacts.toml b/Artifacts.toml new file mode 100644 index 0000000..1dc9142 --- /dev/null +++ b/Artifacts.toml @@ -0,0 +1,9 @@ +[pptx_data] +git-tree-sha1 = "4609b3887be7359885a405f7c14a53c56776d366" + [[pptx_data.download]] + url = "https://github.com/ig-or/PPTX.jl/releases/download/v0.7.0/pptx_data.tar.gz" + sha256 = "0e159a2792e49a74ff14c742b056098122f5c445ecb1191cc2be461727428a6a" + + + + diff --git a/Project.toml b/Project.toml index 223fe1c..e35c7ae 100644 --- a/Project.toml +++ b/Project.toml @@ -1,9 +1,10 @@ name = "PPTX" uuid = "14a86994-10a4-4a7d-b9ad-ef6f3b1fac6a" authors = ["Xander de Vries", "Matthijs Cox"] -version = "0.7.0" +version = "0.7.1" [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..54f9b58 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -17,6 +17,7 @@ You can build a presentation inside Julia: ```jldoctest using PPTX, DataFrames +using Artifacts # Lets make a presentation # note: this already adds a first slide with the title @@ -31,14 +32,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..e5bb8b7 100644 --- a/src/Picture.jl +++ b/src/Picture.jl @@ -14,8 +14,9 @@ Internally the sizes are converted EMUs. # Examples ```julia julia> using PPTX +julia> using Artifacts -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 @@ -28,8 +29,9 @@ Picture Optionally, you can set the `size_x` and `size_y` manually for filetypes not supported by FileIO, such as SVG. ```julia julia> using PPTX +julia> using Artifacts -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 2d66413..c77bcd9 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -5,7 +5,6 @@ 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 7b3c71b..fa22c21 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) @@ -137,7 +138,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..84547fa 100644 --- a/test/testConstructors.jl +++ b/test/testConstructors.jl @@ -1,5 +1,6 @@ using PPTX using Test +using Artifacts @testset "constructors" begin @testset "TextBox" begin @@ -22,7 +23,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 +48,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 +65,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..fefc534 100644 --- a/test/testPresentationState.jl +++ b/test/testPresentationState.jl @@ -1,8 +1,9 @@ using Test using PPTX +using Artifacts @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..8c3ece1 100644 --- a/test/testSlideXML.jl +++ b/test/testSlideXML.jl @@ -2,6 +2,7 @@ using Test using PPTX using EzXML using ZipArchives: ZipBufferReader, zip_readentry +using Artifacts @testset "Slide XML structure" begin s = Slide() @@ -34,7 +35,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..0eb4ed6 100644 --- a/test/testTables.jl +++ b/test/testTables.jl @@ -3,6 +3,7 @@ using Test using DataFrames using EzXML using ZipArchives: ZipBufferReader, zip_readentry +using Artifacts @testset "PPTX Tables from a DataFrame" begin df = DataFrame(a = [1,2], b = [3,4], c = [5,6]) @@ -51,11 +52,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 0dc129b..e07e6d8 100644 --- a/test/testWriting.jl +++ b/test/testWriting.jl @@ -1,5 +1,7 @@ using ZipArchives: ZipBufferReader, zip_readentry, zip_names, zip_append_archive, zip_newfile + +using Artifacts function bincompare(path::String, ref::String) bin1 = read(path) @@ -25,7 +27,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 +35,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 +50,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) @@ -93,18 +95,19 @@ 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) write(edited_template_path, read(original_template_path)) + chmod(edited_template_path, 0o0100664) 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)