// Template handling and substitution use crate::error::RenderError; /// Template files embedded at compile time const TEMPLATE_LY: &str = include_str!("../static/template.ly"); const FORMAT_ILY: &str = include_str!("../static/format.ily"); const ENTRY_ILY: &str = include_str!("../static/entry.ily"); const ELEMENTS_ILY: &str = include_str!("../static/elements.ily"); const PLACEHOLDER: &str = "%%%"; /// Returns the template .ly content pub fn get_template() -> &'static str { TEMPLATE_LY } /// Returns the format.ily content pub fn get_format_ily() -> &'static str { FORMAT_ILY } /// Returns the entry.ily content pub fn get_entry_ily() -> &'static str { ENTRY_ILY } /// Returns the elements.ily content pub fn get_elements_ily() -> &'static str { ELEMENTS_ILY } /// Substitutes the placeholder in the template with the provided markup. /// /// # Arguments /// - `markup`: The LilyPond markup to substitute into the template /// /// # Returns /// The complete .ly file content with substitution applied /// /// # Errors /// Returns `RenderError::Template` if the placeholder is not found pub fn substitute_template(markup: &str) -> Result { let template = get_template(); if !template.contains(PLACEHOLDER) { return Err(RenderError::Template( "Template does not contain placeholder '%%%'".to_string() )); } Ok(template.replace(PLACEHOLDER, markup)) }