ppt_rs/
api.rs

1//! Directly exposed API classes, Presentation for now.
2
3use crate::error::Result;
4use crate::presentation::Presentation as PresentationImpl;
5use std::fs::File;
6use std::io::BufReader;
7use std::path::Path;
8
9/// Return a Presentation object loaded from `pptx`, where `pptx` can be
10/// either a path to a `.pptx` file or a file-like object. If `pptx` is missing
11/// or `None`, the built-in default presentation "template" is loaded.
12pub fn Presentation(pptx: Option<&str>) -> Result<PresentationImpl> {
13    let path = pptx.unwrap_or_else(|| {
14        // TODO: Return path to built-in default template
15        "templates/default.pptx"
16    });
17
18    if Path::new(path).exists() {
19        let file = File::open(path)?;
20        let reader = BufReader::new(file);
21        PresentationImpl::open(reader)
22    } else {
23        // Create new presentation
24        PresentationImpl::new()
25    }
26}
27
28/// Create a new empty presentation
29pub fn new_presentation() -> Result<PresentationImpl> {
30    PresentationImpl::new()
31}
32
33/// Open a presentation from a file path
34pub fn open_presentation<P: AsRef<Path>>(path: P) -> Result<PresentationImpl> {
35    let file = File::open(path)?;
36    let reader = BufReader::new(file);
37    PresentationImpl::open(reader)
38}
39