akari/
lib.rs

1use std::collections::HashMap;
2
3// Include all your existing modules
4mod object;
5mod parse;
6mod compile;
7mod template_manager; 
8mod templates; 
9mod test; 
10
11// Export public APIs
12pub use object::Object; 
13pub use parse::Token;
14pub use compile::compile;
15pub use template_manager::TemplateManager; 
16pub use akari_macro::object; 
17
18/// Renders a template string with provided data
19///
20/// # Arguments
21/// * `template_str` - The template string to render
22/// * `data` - Template variables
23///
24/// # Returns
25/// * Result containing the rendered output or an error
26pub fn render(template_str: &str, data: &HashMap<String, Object>) -> Result<String, String> {
27    let tokens = parse::tokenize(template_str); 
28    compile::compile(tokens, data.clone())
29}
30
31/// Renders a template file with provided data
32///
33/// # Arguments
34/// * `template_path` - Path to the template file
35/// * `data` - Template variables
36///
37/// # Returns
38/// * Result containing the rendered output or an error
39pub fn render_file(template_path: &str, data: &HashMap<String, Object>) -> Result<String, String> {
40    use std::fs;
41    let content = fs::read_to_string(template_path)
42        .map_err(|e| format!("Failed to read template file: {}", e))?;
43    render(&content, data)
44}