Skip to content

Conversation

@lalvarezt
Copy link
Owner

Structured Templates (Advanced)

NEW in v0.13.0: Apply multiple inputs to different template sections with individual separators.
This enables powerful scenarios like batch processing, command construction, and data transformation.

use string_pipeline::Template;

// Multiple inputs per template section with different separators
let template = Template::parse("Users: {upper} | Files: {lower}").unwrap();
let result = template.format_with_inputs(&[
    &["john doe", "jane smith"],  // Multiple users for first section
    &["FILE1.TXT", "FILE2.TXT"]   // Multiple files for second section
], &[" ", ","]).unwrap();         // Space separator for users, comma for files
assert_eq!(result, "Users: JOHN DOE JANE SMITH | Files: file1.txt,file2.txt");

// Template introspection
let sections = template.get_template_sections(); // Get template section info
assert_eq!(sections.len(), 2); // Two template sections: {strip_ansi|lower} and {}

Key Features:

  • 🎯 Flexible Input: Each template section can receive multiple input values
  • ⚙️ Custom Separators: Individual separator for each template section
  • 🔍 Introspection: Examine template structure before processing
  • 🏗️ Batch Processing: Perfect for processing multiple items per section

gives the option to pass different arguments to the different sections
inside a MultiTemplate
@lalvarezt lalvarezt self-assigned this Aug 18, 2025
@lalvarezt lalvarezt added the enhancement New feature or request label Aug 18, 2025
@lalvarezt
Copy link
Owner Author

@alexpasmantier care to have a look, this solves some of the issues related to multiple selection in television

@lalvarezt lalvarezt changed the title qfeat(lib): introduce structured templates feat(lib): introduce structured templates Aug 18, 2025
@lalvarezt lalvarezt force-pushed the structured-templates branch from 7446662 to 0e3cecf Compare August 18, 2025 20:18
@lalvarezt lalvarezt merged commit b140f58 into main Aug 21, 2025
6 checks passed
lalvarezt added a commit that referenced this pull request Nov 4, 2025
* feat(lib): introduce structured templates

gives the option to pass different arguments to the different sections
inside a MultiTemplate

* fix(lib): remove interior mutability issue from OnceCell that prevented stable use in HashMaps/Sets

* fix(lib): fix logic error where we join first then processed intead of processing then joining
lalvarezt added a commit that referenced this pull request Nov 4, 2025
* feat(lib): introduce structured templates

gives the option to pass different arguments to the different sections
inside a MultiTemplate

* fix(lib): remove interior mutability issue from OnceCell that prevented stable use in HashMaps/Sets

* fix(lib): fix logic error where we join first then processed intead of processing then joining
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants