diff options
| author | jacksonfu14 <jackson@fashionunited.com> | 2025-11-17 06:56:09 +0100 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2025-11-17 06:56:09 +0100 |
| commit | a20f9a327c4d9e5ac8f42db4e2e9fb29770c3d37 (patch) | |
| tree | 568c2650e8bf015b896f86297176a485b9bb5c08 /morphology-img/src/template.rs | |
| parent | 3077c7af770b055804d5cf48994a4e4cf6d31146 (diff) | |
feature: generate and process ly files
Diffstat (limited to 'morphology-img/src/template.rs')
| -rw-r--r-- | morphology-img/src/template.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/morphology-img/src/template.rs b/morphology-img/src/template.rs index afa091b..15a47d5 100644 --- a/morphology-img/src/template.rs +++ b/morphology-img/src/template.rs @@ -1 +1,53 @@ // 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<String, RenderError> { + let template = get_template(); + + if !template.contains(PLACEHOLDER) { + return Err(RenderError::Template( + "Template does not contain placeholder '%%%'".to_string() + )); + } + + Ok(template.replace(PLACEHOLDER, markup)) +} |