Crates.io | gtmpl_helpers |
lib.rs | gtmpl_helpers |
version | 0.1.3 |
source | src |
created_at | 2020-04-15 12:15:11.104416 |
updated_at | 2020-05-22 09:55:51.996491 |
description | A set of helper functions for the templates to work with gtmpl template system |
homepage | |
repository | https://github.com/storyfeet/gtmpl_helpers |
max_upload_size | |
id | 230459 |
size | 27,704 |
The point in this Library is to provide useful helper methods for cases where you really do need the templates to be capable of more than just printing exactly what it's given.
My personal use case was to be able to generate specific svg layouts from numbers in cards which meant multiplying those numbers by the size of the card. files. This meant doing more maths in the template than is common. I've broken up the helpers roughly by subject so it should be easy to find the ones you need.
The simplest way to use this is to import the trait and call with_all()
on a template.
use gtmpl::{Template,Context};
use gtmpl_value::{Value,Number};
use gtmpl_helpers::THelper;
let mut t = Template::default().with_all();
t.parse(r#"<rect {{xywh (mul . 5) (add . 11) 40 20 "px"}}/>"#);
let s = t.q_render(4).unwrap();
assert_eq!(s,r#"<rect x="20px" y="15px" width="40px" height="20px" />"#.to_string())
I should note that this library is in no way endorsed by the Gtmpl team. However I hope you find it helpful.
I wanted to keep the demo function simple, but q_render
works with anything that impls
Into for Value And these can of course be Gtmpl Derived like most things.
However that is tricky to demo in a doctest.
If you wish to add more helpers send me a PR and I'll be happy to add them, as long as your happy with the MIT licence for everything you contribute.
Now has "sub, div and has" methods also "wrap" added, for performing linewraps on string.