diff options
Diffstat (limited to 'morphology-img/src/template.rs')
| -rw-r--r-- | morphology-img/src/template.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/morphology-img/src/template.rs b/morphology-img/src/template.rs index 15a47d5..e552843 100644 --- a/morphology-img/src/template.rs +++ b/morphology-img/src/template.rs @@ -8,7 +8,8 @@ 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 = "%%%"; +const MORPHEME_PLACEHOLDER: &str = "%MORPHEME%"; +const RUNGS_PLACEHOLDER: &str = "%RUNGS%"; /// Returns the template .ly content pub fn get_template() -> &'static str { @@ -30,24 +31,35 @@ pub fn get_elements_ily() -> &'static str { ELEMENTS_ILY } -/// Substitutes the placeholder in the template with the provided markup. +/// Substitutes placeholders in the template with the provided values. /// /// # Arguments -/// - `markup`: The LilyPond markup to substitute into the template +/// - `morpheme`: The LilyPond morpheme markup to substitute +/// - `rungs`: The Scheme list string for staff line positions /// /// # Returns -/// The complete .ly file content with substitution applied +/// The complete .ly file content with substitutions applied /// /// # Errors -/// Returns `RenderError::Template` if the placeholder is not found -pub fn substitute_template(markup: &str) -> Result<String, RenderError> { +/// Returns `RenderError::Template` if placeholders are not found +pub fn substitute_template(morpheme: &str, rungs: &str) -> Result<String, RenderError> { let template = get_template(); - if !template.contains(PLACEHOLDER) { + if !template.contains(MORPHEME_PLACEHOLDER) { return Err(RenderError::Template( - "Template does not contain placeholder '%%%'".to_string() + "Template does not contain placeholder '%MORPHEME%'".to_string() )); } - Ok(template.replace(PLACEHOLDER, markup)) + if !template.contains(RUNGS_PLACEHOLDER) { + return Err(RenderError::Template( + "Template does not contain placeholder '%RUNGS%'".to_string() + )); + } + + let result = template + .replace(MORPHEME_PLACEHOLDER, morpheme) + .replace(RUNGS_PLACEHOLDER, rungs); + + Ok(result) } |