Skip to content

Commit

Permalink
Merge pull request #53 from nhz2/bake-in-templates
Browse files Browse the repository at this point in the history
Bake in default template to improve PackageCompiler support
  • Loading branch information
matthijscox-asml authored Jul 8, 2024
2 parents 3186c61 + 404f984 commit 100de63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
5 changes: 4 additions & 1 deletion src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ const TITLE_SLIDE_LAYOUT = 1
const DEFAULT_SLIDE_LAYOUT = 2

include_dependency(joinpath(TEMPLATE_DIR, "tableStyles.xml"))
const DEFAULT_TABLE_STYLE_DATA = read(joinpath(TEMPLATE_DIR, "tableStyles.xml"))
const DEFAULT_TABLE_STYLE_DATA = read(joinpath(TEMPLATE_DIR, "tableStyles.xml"))

include_dependency(joinpath(TEMPLATE_DIR, "no-slides.pptx"))
const DEFAULT_TEMPLATE_DATA = read(joinpath(TEMPLATE_DIR, "no-slides.pptx"))
26 changes: 15 additions & 11 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ function add_contenttypes!(w::ZipWriter, template::ZipBufferReader)
zip_commitfile(w)
end

# Support reading a template from file path or from pre-read file data.
function read_template(template_path::AbstractString)
template_path = abspath(template_path)
template_isfile = isfile(template_path)
if !template_isfile
error(
"No file found at template path: $(repr(template_path))",
)
end
read(template_path)
end
read_template(template_data::AbstractVector{UInt8}) = template_data

"""
```julia
Base.write(
Expand Down Expand Up @@ -137,18 +150,9 @@ function Base.write(
p::Presentation;
overwrite::Bool=false,
open_ppt::Bool=true,
template_path::String=joinpath(TEMPLATE_DIR, "no-slides.pptx"),
template_path::Union{String, Vector{UInt8}}=DEFAULT_TEMPLATE_DATA,
)

template_path = abspath(template_path)
template_isfile = isfile(template_path)

if !template_isfile
error(
"No file found at template path: $(repr(template_path))",
)
end
template_reader = ZipBufferReader(read(template_path))
template_reader = ZipBufferReader(read_template(template_path))

if !endswith(filepath, ".pptx")
filepath *= ".pptx"
Expand Down

0 comments on commit 100de63

Please sign in to comment.