Skip to content

Commit

Permalink
trying to use artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
ig-or committed May 8, 2024
1 parent 64435fe commit 60cae56
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 22 deletions.
9 changes: 9 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -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"




1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Picture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/write.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import DefaultApplication
using Artifacts

function write_presentation!(w::ZipWriter, p::Presentation)
xml = make_presentation(p)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test/testArtifacts.jl
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 4 additions & 4 deletions test/testConstructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/testPresentationState.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/testSlideXML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/testTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions test/testWriting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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

@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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 60cae56

Please sign in to comment.