Crate string_template_plus
source ·Expand description
Introduction
This is a simple template tool that works with variable names and
HashMap of String. The Template can be parsed from
str and then you can render it using the variables in
HashMap and any shell commands running through Exec.
Features
- Parse the template from a
strthat’s easy to write, - Support for alternatives in case some variables are not present,
- Support for literal strings inside the alternative options,
- Support for the date time format using
chrono, - Support for any arbitrary commands, etc.
Limitations
- You cannot use positional arguments in this template system, only named ones.
{}will be replaced with empty string. Although you can use"0","1", etc as variable names in the template and the render options variables. - I haven’t tested variety of names, although they should work try to keep the names identifier friendly.
- Currently doesn’t have format specifiers, for now you can use the command options with
printfbash command to format things the way you want. Like a templatethis is $(printf "%.2f" {weight}) kg.should be rendered with the correct float formatting.
Structs
Enums
- Parts that make up a
Template. You can have literal strings, variables, time date format, command, or optional format withOPTIONAL_RENDER_CHAR.
Statics
- Quote characters to use to make a value literal instead of a variable. In combination with
OPTIONAL_RENDER_CHARit can be used as a default value when variable(s) is/are not present. - Character to separate the variables. If the first variable is not present it’ll use the one behind it and so on. Keep it at the end, if you want a empty string instead of error on missing variable.
- Character that should be in the beginning of the variable to determine it as datetime format.
Traits
Functions
- Parses the template from string and makes a
Template. Which you can render later./// Main Template that get’s passed around, consists of[Vec] ofTemplatePart
Type Aliases
- Main Template that get’s passed around, consists of
[Vec] ofTemplatePart