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        // Return path to built-in default template
15        // For now, return None which will create a new presentation
16        // In full implementation, would return path to bundled template
17        return "";
18    });
19
20    if path.is_empty() {
21        // Create new presentation when no path provided
22        return PresentationImpl::new();
23    }
24
25    if Path::new(path).exists() {
26        let file = File::open(path)?;
27        let reader = BufReader::new(file);
28        PresentationImpl::open(reader)
29    } else {
30        // Create new presentation if file doesn't exist
31        PresentationImpl::new()
32    }
33}
34
35/// Create a new empty presentation
36pub fn new_presentation() -> Result<PresentationImpl> {
37    PresentationImpl::new()
38}
39
40/// Open a presentation from a file path
41pub fn open_presentation<P: AsRef<Path>>(path: P) -> Result<PresentationImpl> {
42    let file = File::open(path)?;
43    let reader = BufReader::new(file);
44    PresentationImpl::open(reader)
45}
46