summaryrefslogtreecommitdiff
path: root/morphology-img/src/template.rs
diff options
context:
space:
mode:
authorjacksonfu14 <jackson@fashionunited.com>2025-11-18 20:34:56 +0100
committerJackson Moore <jacksonmoore@tuta.io>2025-11-18 20:34:56 +0100
commit53aca050d78bcda82bd3f2c22b672df91bba23e6 (patch)
treee26f1c6ad09731884fb96fcc946a8a315df828e1 /morphology-img/src/template.rs
parent38fe4c04137b92ddd15fa50d484b4b4630bf4544 (diff)
scale staves to fit notes
Diffstat (limited to 'morphology-img/src/template.rs')
-rw-r--r--morphology-img/src/template.rs30
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)
}