# so/ctl

Static template generator for C

## Installation

```
sudo make install
```

## Usage

```html
% #include "macro.h" %

% TEMPLDEF(
  sample,
  char *message;
) %

<h1>% STRING($(message)) %</h1>
<ul>
  % for (size_t i = 0; i < 10; i++) { %
    <li>% NUMBER(i) %</li>
  % } %
</ul>

% ENDTEMPL %
```

```c
#define SO_STR_IMPL
#include <so/str.h>

#define CTL_OUT (str_t *) ctl->out

#define CTL_WRITE($str) { \
  str_append(CTL_OUT, $str); \
}

#define $($var) ctx->$var

#define STRING CTL_WRITE

#define NUMBER($num) { str_appendf(CTL_OUT, "%%d", $num); }
```

```c
#include <stdio.h>

#define SO_CTL_IMPL
#include <so/ctl.h>
#define SO_STR_IMPL
#include <so/str.h>

#include "../sample.h"

int main(void) {
  str_t out = STR_NULL;
  ctl_t *ctl = ctl_init(&out);
  sample_t data = {
    .message = "It works!",
  };
  sample_render(ctl, &data, "./sample.so");
  printf("%s", str_get(&out));
  str_free(&out);
  ctl_cleanup(ctl);
  return 0;
}
```

```bash
ctl -h sample.html > sample.h
ctl -o sample.html > sample.so
```
