diff options
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) } |