https://github.com/l1mey112/v-tmpl
Implementation of the compile time V template system for generic runtime use
https://github.com/l1mey112/v-tmpl
vlang vlang-module
Last synced: 4 months ago
JSON representation
Implementation of the compile time V template system for generic runtime use
- Host: GitHub
- URL: https://github.com/l1mey112/v-tmpl
- Owner: l1mey112
- License: mit
- Created: 2022-10-22T14:53:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-22T15:05:09.000Z (over 3 years ago)
- Last Synced: 2025-02-10T22:47:07.613Z (over 1 year ago)
- Topics: vlang, vlang-module
- Language: V
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# v-tmpl
An implementation of the compile time template system for generic use. Striving to be compatible with and to extend the existing V `$tmpl()` system.
This is highly experimental, most features are not properly implemented and there are some edge cases. Be warned.
PRs welcome!
# Basic Usage
```v
import tmpl
fn main() {
mut context := map[string]tmpl.Any
context = {
'name' : 'Peter'
'age' : 25
'numbers' : [tmpl.Any(1), 2, 3]
}
a :=
"name: @name
age: @age
numbers: @numbers
@for number in numbers
@number
@end
@include README.md"
b := tmpl.template_string(a, context) or {
panic(err)
}
assert b.split_into_lines()[0] == "name: Peter"
assert b.split_into_lines()[2] == "age: 25"
assert b.split_into_lines()[4] == "numbers: [1, 2, 3]"
}
```
```
(template error) file.tmpl:9:1: value not found in template context
(template error) file.tmpl:7:1: unhandled template statement
(template error) file.tmpl:11:1: file to include could not be opened
```