Metadata-Version: 2.4
Name: renderix
Version: 1.0.1
Summary: Simple templating engine
Author: Arne Van Looveren
Author-email: Arne Van Looveren <arne@vanlooveren.dev>
License-Expression: MIT
Requires-Python: >=3.11
Project-URL: Source, https://codeberg.org/nietarne/renderix
Description-Content-Type: text/markdown

# renderix
![PyPI - Version](https://img.shields.io/pypi/v/renderix?color=%23a6e3a1)

Simple templating engine.

`renderix` renders a template file by replacing placeholders with values loaded from a TOML file named `renderix.toml` in the current working directory.

---

## Features

- Tiny, no-dependency templating
- Variables loaded from `renderix.toml`
- Placeholders: `[- name -]`
- For loops over arrays of tables
- Conditionals (`if` / `elif` / `else`)
- Output to stdout by default, or write to a file

---

## Installation
```bash
uv tool install renderix
```

Or:

```bash
git clone https://codeberg.org/nietarne/renderix.git
cd renderix
uv tool install .
```

---

## Quick start

1. Create a `renderix.toml` in your working directory:
```toml
name = "John Doe"
```
2. Create a template file, e.g. `template.txt`:
```
Hello [- name -]
```
3. Render it to stdout:
```bash
renderix -t template.txt
```

---

## Syntax

All tags use `[- ... -]` delimiters. Whitespace inside is flexible: `[- name -]` and `[-name-]` are both valid.

### Variables

```
Hello, [- name -]!
```

### For loops

```toml
# renderix.toml
[[employees]]
name = "John"
age = 40

[[employees]]
name = "Jane"
age = 42
```

```
[- for employee in employees -]
- [- employee.name -] is [- employee.age -] years old
[- endfor -]
```

### Conditionals

```
[- if status == "active" -]
Active user
[- elif status == "pending" -]
Pending approval
[- else -]
Inactive
[- endif -]
```

Supported condition forms:

| Form               | Example                          |
|--------------------|----------------------------------|
| Truthy/falsy check | `[- if user -]`                  |
| Equality           | `[- if status == "active" -]`    |
| Inequality         | `[- if count != 0 -]`            |
| Comparison         | `[- if score >= 10 -]`           |

---

## Programmatic use

```python
from renderix import render

result = render("Hello, [- name -]!", {"name": "World"})
```

The `render` function accepts any template string and a plain dict as context — no files involved. It raises `RenderixSyntaxError` for malformed templates and `RenderixRenderError` for missing variables or type mismatches.

```python
from renderix import render, RenderixSyntaxError, RenderixRenderError

try:
    result = render(template_string, context_dict)
except (RenderixSyntaxError, RenderixRenderError) as e:
    ...
```

---

## CLI options

```
  -t, --template    Template file to process (required)
  -o, --output      File to write output to (defaults to stdout)
  -v, --version     Print version and exit
```
