๐Ÿ“ฆ SergioRibera / srtemplate

A string template system

โ˜… 7 stars โ‘‚ 2 forks ๐Ÿ‘ 7 watching โš–๏ธ Apache License 2.0
rustrust-langrustlangtemplate-engine
๐Ÿ“ฅ Clone https://github.com/SergioRibera/srtemplate.git
HTTPS git clone https://github.com/SergioRibera/srtemplate.git
SSH git clone git@github.com:SergioRibera/srtemplate.git
CLI gh repo clone SergioRibera/srtemplate
Sergio Ribera Sergio Ribera chore: Release version {{version}} 59fce06 9 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ benches
๐Ÿ“ examples
๐Ÿ“ helper_macros
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ Cargo.lock
๐Ÿ“„ Cargo.toml
๐Ÿ“„ LICENSE-APACHE
๐Ÿ“„ LICENSE-MIT
๐Ÿ“„ README.md
๐Ÿ“„ release.toml
๐Ÿ“„ rustfmt.toml
๐Ÿ“„ README.md

srtemplate

GitHub Workflow Status (with event) Crates.io docs.rs

SrTemplate

Mr. strings template is a library that allows you to render just text templates.

Links

  • You can see a real example here, it is a real time template renderer.
  • Documentation here
  • Wiki

Features

  • Super fast
  • Efficient
  • Renders variables of all types
  • Function system
  • Easy implementation of custom functions
  • Minimum possible dependencies
  • Feature-based implementations, use only what you need
  • Using the same variables renders multiple times

Basic example

[!NOTE]
See more examples here

use srtemplate::SrTemplate;

fn main() {
    let mut ctx = SrTemplate::default();
    ctx.add_variable("var", &"World");
    ctx.add_variable("otherVar", &"Other");
    ctx.add_variable("number", &85u8);
    
    let template = "Hello {{ var }}! This is {{ otherVar }} and this is number: {{number}}";
    println!("Rendered: {}", ctx.render(template).unwrap());
}

[!NOTE]
For more information about the functions implemented by default or how to use the library in depth, see the wiki

TODO's

  • I would like to change the way custom functions are implemented.
  • Macros to create custom functions
  • Better add_variable function to make more easy and performance managing Cow