diff options
| author | jacksonfu14 <jackson@fashionunited.com> | 2025-11-18 21:47:55 +0100 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2025-11-18 21:47:55 +0100 |
| commit | f4380758ee94fc137073471f52bf8a20fda34f1b (patch) | |
| tree | c34aa85e2aa89be9cd062eb3deb2b07c27cb6388 /morphology-img/src/template.rs | |
| parent | 53aca050d78bcda82bd3f2c22b672df91bba23e6 (diff) | |
Diffstat (limited to 'morphology-img/src/template.rs')
| -rw-r--r-- | morphology-img/src/template.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/morphology-img/src/template.rs b/morphology-img/src/template.rs index e552843..9a66000 100644 --- a/morphology-img/src/template.rs +++ b/morphology-img/src/template.rs @@ -10,6 +10,7 @@ const ELEMENTS_ILY: &str = include_str!("../static/elements.ily"); const MORPHEME_PLACEHOLDER: &str = "%MORPHEME%"; const RUNGS_PLACEHOLDER: &str = "%RUNGS%"; +const LEDGERS_PLACEHOLDER: &str = "%LEDGERS%"; /// Returns the template .ly content pub fn get_template() -> &'static str { @@ -36,13 +37,14 @@ pub fn get_elements_ily() -> &'static str { /// # Arguments /// - `morpheme`: The LilyPond morpheme markup to substitute /// - `rungs`: The Scheme list string for staff line positions +/// - `ledgers`: The Scheme list string for ledger line positions /// /// # Returns /// The complete .ly file content with substitutions applied /// /// # Errors /// Returns `RenderError::Template` if placeholders are not found -pub fn substitute_template(morpheme: &str, rungs: &str) -> Result<String, RenderError> { +pub fn substitute_template(morpheme: &str, rungs: &str, ledgers: &str) -> Result<String, RenderError> { let template = get_template(); if !template.contains(MORPHEME_PLACEHOLDER) { @@ -57,9 +59,16 @@ pub fn substitute_template(morpheme: &str, rungs: &str) -> Result<String, Render )); } + if !template.contains(LEDGERS_PLACEHOLDER) { + return Err(RenderError::Template( + "Template does not contain placeholder '%LEDGERS%'".to_string() + )); + } + let result = template .replace(MORPHEME_PLACEHOLDER, morpheme) - .replace(RUNGS_PLACEHOLDER, rungs); + .replace(RUNGS_PLACEHOLDER, rungs) + .replace(LEDGERS_PLACEHOLDER, ledgers); Ok(result) } |