Crates.io | variable-resolver |
lib.rs | variable-resolver |
version | 1.1.0 |
source | src |
created_at | 2024-11-17 19:43:42.366842 |
updated_at | 2024-11-18 19:56:10.562727 |
description | The aim of this package is to easily replace variables inside a given template. |
homepage | |
repository | https://github.com/bytifex/variable-resolver.git |
max_upload_size | |
id | 1451516 |
size | 28,009 |
The aim of this package is to easily replace variables inside a given template.
The package contains a library and a cli application (repvar).
The package is capable of finding variable names inside double curly braces.
Example template:
Hello, {{name}}
Escaping double curly braces happens by using triple curly braces. Examples:
Hello, {{{name}}}
will resolve to Hello, {{name}}
Hello, {{{{name}}}}
will resolve to Hello, {{{name}}}
Hello, {{{{{name}}}}}
will resolve to Hello, {{Jane}}
Hello, {{{{{{name}}}}}}
will resolve to Hello, {{{{name}}}}
The following example demonstrates how every occurence of a variable is replaced with a value. In the following case every {{name}} is replaced with Jane:
echo "Hello, {{name}}" | repvar -v name=Jane
Templates inside files can be handled by piping the file into repvar. Example:
cat greeting.txt | repvar -v name=Jane
Be aware that writing to the same file as the source is not safe. Example:
cat greeting.txt | repvar -v name=Jane > greeting.txt