# Unja
A template engine for C, inspired by Jinja and Liquid.
Forked from https://github.com/dannyvankooten/unja
## Example
File `base.tmpl`:
```html+jinja
{% block title %}Default title{% endblock %}
{% block content %}
{% endblock %}
```
File `child.tmpl`:
```html+jinja
{% extends "base.html" %}
{% block title %}Users{% endblock %}
{% block content %}
{% endblock %}
```
File: `example.c`
```c
int main() {
// parse all templates in the given directory
struct env *env = env_new("./");
// create a hashmap for storing template variables
struct hashmap *vars = hashmap_new();
hashmap_insert(vars, "name", "John Doe");
// execute the template
char *output = template(env, "child.tmpl", vars);
printf("%s", output);
// clean-up allocated memory
free(output);
hashmap_free(vars);
env_free(env);
}
```
## Changes from upstream
### Done
* Use FNV1a as hashmap hashing algorithm.
* Hashmap capacity can be set programmatically and it grows/shrinks in size
when the load increases/decreases to avoid collisions/save memory.
* Include guards.
* Fix heap corruption on buffer growth.
* Define as static functions that are not used outside a TU.
### TODO
* Handle empty/non-existent variables
* Handle non-existent templates
* Let the library user decide how to handle errors, instead of just aborting the
program.
* Do not print anything to stdout/stderr. It should be up to the library user to
decide what and when to print a message.
## License
MIT