Metadata-Version: 2.4
Name: nyxa-minijinja
Version: 0.0.1
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
License-File: LICENSE
Summary: MiniJinja-backed template engine for Nyxa (opt-in view engine)
Author-email: Al-Amin Islam Nerob <alamin@aincoder.com>
License-Expression: MIT
Requires-Python: >=3.13
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://github.com/NyxaDev/Nyxa

# nyxa-minijinja

Rust (PyO3) MiniJinja backend for `nyxa-view` — renders translated
`.pyt` templates at native speed while preserving the Python reference
engine's exact semantics. Bundled with `nyxa` and the default backend —
`view.engine = "nyxa"` opts back to the pure-Python engine.

## Features

- **`Engine` pyclass** — a MiniJinja environment holding translated
  templates: `add_template`, `remove_template`, `has_template`,
  `render`. Default `nyxa-view` backend when installed — selected
  automatically through the backend registry (`MinijinjaBackend`);
  `view.engine = "nyxa"` pins the pure-Python engine instead.
- **Python-faithful semantics** — templates are rendered through
  `__nyxa_*__` leaf hooks (escaping, truthiness, attribute/subscript
  access, binary/unary ops, calls, iteration, f-strings) so `{{ }}`
  semantics match the reference compiler — including Python's
  `html.escape` quoting and `None` printing rules.
- **`PyObj` bridging** — arbitrary Python objects cross the boundary
  lazily: attribute access, method calls, truthiness, and iteration
  delegate back to Python under the GIL; scalars/str-keyed
  dicts/sequences convert eagerly with a bounded depth (deep
  structures raise instead of overflowing).
- **Leaf-hook safety** — the `__nyxa_*__` machinery is re-asserted
  after user context each render, so a context key can never shadow
  escaping or other runtime behavior.
- **Re-entrant render** — `unsendable` engine; parent/include hooks
  may re-enter `render`/`add_template` recursively without borrow
  conflicts.
- **`RenderError`** — template and render failures surface as a
  dedicated exception type.

## Install

```bash
pip install nyxa            # nyxa-minijinja is bundled by default
# standalone: nyxa add nyxa-minijinja
```

Requires a compiled wheel (maturin build) — when unavailable, the
`nyxa-view` backend factory returns `None` and rendering uses the
pure-Python compiler path.

## Usage

No config needed — with the wheel installed, `nyxa-view` uses the Rust
backend by default:

```python
# config/view.py
config = {
    "paths": ["resources/views"],
    "cache": "build/views",
    # "engine": "nyxa",    # opt out — pin the pure-Python engine
}
```

`NYXA_NO_NATIVE_TEMPLATES`/`NYXA_NO_SPEEDUPS` env vars also force the
Python engine.

Direct use (rare — `nyxa-view` drives it for you):

```python
import nyxa_minijinja

engine = nyxa_minijinja.Engine()
engine.add_template("hello", "Hello, {{ name }}!")
out = engine.render("hello", {"name": "Ain"}, {})
```

## Public API

- **`Engine`** — `Engine(builtins=None)`; `builtins` is a dict of
  Python callables exposed as template globals.
  - `engine.add_template(name, source)` — register (or replace) a
    translated Jinja source.
  - `engine.remove_template(name)` — drop a template.
  - `engine.has_template(name) -> bool` — whether `name` is
    registered.
  - `engine.render(name, ctx, hooks) -> str` — render with a context
    dict plus per-render `hooks` (callables used by the translator's
    emitted code). Raises `RenderError`.
- **`RenderError`** — exception raised for template registration and
  render failures.

## Configuration

Selected via `nyxa-view`'s `view.engine` config (see
`nyxa-view` README). No config of its own.

## License

MIT

