Static template generator for C
git clone git://soophie.de/ductape
blob: 8a25b5f26b7990a060c8950f221bdf0a9f94fe5c (1032 bytes)[doc][blame][raw]
1
# so/ctl3
Static template generator for C5
## Installation7
```8
sudo make install9
```11
## Usage13
```html14
% #include "macro.h" %16
% TEMPLDEF(17
sample,18
char *message;19
) %21
<h1>% STRING($(message)) %</h1>22
<ul>23
% for (size_t i = 0; i < 10; i++) { %24
<li>% NUMBER(i) %</li>25
% } %26
</ul>28
% ENDTEMPL %29
```31
```c32
#define SO_STR_IMPL33
#include <so/str.h>35
#define CTL_OUT (str_t *) ctl->out37
#define CTL_WRITE($str) { \38
str_append(CTL_OUT, $str); \39
}41
#define $($var) ctx->$var43
#define STRING CTL_WRITE45
#define NUMBER($num) { str_appendf(CTL_OUT, "%%d", $num); }46
```48
```c49
#include <stdio.h>51
#define SO_CTL_IMPL52
#include <so/ctl.h>53
#define SO_STR_IMPL54
#include <so/str.h>56
#include "../sample.h"58
int main(void) {59
str_t out = STR_NULL;60
ctl_t *ctl = ctl_init(&out);61
sample_t data = {62
.message = "It works!",63
};64
sample_render(ctl, &data, "./sample.so");65
printf("%s", str_get(&out));66
str_free(&out);67
ctl_cleanup(ctl);68
return 0;69
}70
```72
```bash73
ctl -h sample.html > sample.h74
ctl -o sample.html > sample.so75
```