Skip to content

Commit

Permalink
Support symbol and string for the st+... functions to get variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Atreyagaurav committed Jan 6, 2024
1 parent 414d3b1 commit ccf6f5a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ To access the values in lisp you can use the following functions:
- `st+num` the value as a number, and
- `st+has` true if value is present else false.
You need to quote the symbol to pass to the functions (e.g. (st+num 'total).
You need to quote the symbol to pass to the functions (e.g. (st+num
'total) or (st+num "total").
Else, you can just write the variables in braces like normal as well.
there are two use cases.
- Standalone use case: in the format of `=()` that'll be replaced with the results.
- Inside the `{}` that can be used as alternative to a variable, or with a transformer.
- Standalone use case: in the format of `=()` that'll be replaced with
the results.
- Inside the `{}` that can be used as alternative to a variable, or
with a transformer.
```rust
# use std::error::Error;
Expand All @@ -112,7 +115,7 @@ there are two use cases.
# use string_template_plus::{Render, RenderOptions, Template};
#
# fn main() -> Result<(), Box<dyn Error>> {
let templ = Template::parse_template("hello {nickname?name}. You've done =(/ (st+num 'task_done) (st+num 'task_total)) work. {=(- 1 (/ (st+num 'task_done) (st+num 'task_total))):calc(*100):f(1)}% remains.").unwrap();
let templ = Template::parse_template("hello {nickname?name}. You've done =(/ (st+num 'task_done) (st+num 'task_total)) work. {=(- 1 (/ (st+num \"task_done\") (st+num 'task_total))):calc(*100):f(1)}% remains.").unwrap();
let mut vars: HashMap<String, String> = HashMap::new();
vars.insert("name".into(), "world".into());
vars.insert("task_done".into(), "1".into());
Expand Down

0 comments on commit ccf6f5a

Please sign in to comment.