oxblade 0.2.0

Laravel Blade templates for Rust: Blade's markup and directives with Rust expressions, rendering the same HTML as Laravel. Community package, not affiliated with Laravel.
Documentation
# oxblade

<!-- kit:badges -->
[![CI](https://img.shields.io/github/actions/workflow/status/bowerbird-si/oxblade/ci.yml?branch=main&style=flat&logo=githubactions&logoColor=white&label=CI)](https://github.com/bowerbird-si/oxblade/actions/workflows/ci.yml) [![status: alpha](https://img.shields.io/badge/status-alpha-orange?style=flat)](#status-and-licence) [![crates.io](https://img.shields.io/crates/v/oxblade?style=flat&logo=rust&label=crates.io)](https://crates.io/crates/oxblade) [![docs.rs](https://img.shields.io/docsrs/oxblade?style=flat&logo=docsdotrs&label=docs.rs)](https://docs.rs/oxblade) [![MSRV 1.99](https://img.shields.io/badge/MSRV-1.99-blue?style=flat&logo=rust)](#compatibility) [![Licence: MIT](https://img.shields.io/badge/licence-MIT-blue?style=flat)](LICENSE)
<!-- /kit:badges -->

Oxblade matches Laravel 13's HTML byte for byte on all 977 paired conformance cases in CI. The
expected output comes from Laravel 13.39.0 itself. Separate suites check 181 pagination fixtures,
six Markdown emails in HTML and text, and 4,523 translation records. See the
[parity matrix](design/SPEC.md#blade-parity) for documented differences. Templates use Rust-style
expressions such as `user.name`, `items.len()` and `|c| c.score >= 80`.

## Quick start

```toml
[dependencies]
oxblade = "0.2"
serde_json = "1"
```

```rust
use oxblade::{engine::Environment, loader::MemoryLoader};
use serde_json::json;

fn main() -> Result<(), oxblade::error::Error> {
    let views = MemoryLoader::new()
        .view(
            "layouts.app",
            "<title>@yield('title')</title>\n<main>@yield('content')</main>\n",
        )
        .view(
            "components.badge",
            "@props(tone: String = 'info')\n<span class=\"badge badge-{{ tone }}\">{{ slot }}</span>",
        )
        .view(
            "books",
            "@extends('layouts.app')\n\
             @section('title', 'Books')\n\
             @section('content')\n\
             @foreach (book in books)\n\
             <p>{{ book.title }}@if (book.year < 1900) <x-badge tone=\"old\">classic</x-badge>@endif</p>\n\
             @endforeach\n\
             @endsection\n",
        );

    let env = Environment::builder(views).build();
    let html = env.render_json(
        "books",
        &json!({
            "books": [
                { "title": "Middlemarch", "year": 1871 },
                { "title": "Tom & Jerry's <Guide>", "year": 2026 },
            ]
        }),
    )?;
    print!("{html}");
    Ok(())
}
```

It prints:

```html
<title>Books</title>
<main><p>Middlemarch <span class="badge badge-old">classic</span></p>
<p>Tom &amp; Jerry&#039;s &lt;Guide&gt;</p>
</main>
```

The same program is [`crates/oxblade/examples/quickstart.rs`](crates/oxblade/examples/quickstart.rs); CI
builds and runs it. The [Laravel for Rust example app](examples/laravel-app/README.md) shows how to
register the engine, render typed views and run `blade:check`. See the [guide](docs/index.md) for
installation and configuration.

## Blade, with Rust expressions

Templates use Blade markup and directives with Rust-style expressions.

| PHP Blade | oxblade |
| --- | --- |
| `{{ $user->name }}` | `{{ user.name }}` |
| `@foreach ($posts as $post)` | `@foreach (post in posts)` |
| `@if ($posts->isEmpty())` | `@if (posts.is_empty())` |
| `{{ $items->count() }}` | `{{ items.len() }}` |
| `<x-alert :type="$level" />` | `<x-alert :type="level" />` |
| `@php … @endphp` | `@code … @endcode`, with Rust statements |
| `{{ number_format($price, 2) }}` | `{{ number_format(price, 2) }}` |

Conditions must be `bool`, nothing converts implicitly, and integer division is Rust's. Where a template
needs PHP's exact behaviour, the `php::` functions from
[laravel-rust-format](https://github.com/bowerbird-si/laravel-rust-format) provide it. Laravel's
collection, string, number and date helpers are available under their Laravel names.

## What it covers

- Laravel 13's Blade: its directives, template inheritance, components (anonymous, class and inline),
  slots, `@aware`, stacks, `@once`, `@verbatim`, `@json`, `@js`, custom directives and conditions, view
  composers, pagination views and the mail Markdown components. `@fonts` waits on the framework. The
  [parity matrix](design/SPEC.md#blade-parity) lists every feature and how
  oxblade handles it.
- **Translations:** `__()`, `trans()`, `trans_choice()`, `@lang` and `@choice`, with Laravel's replacements
  and plural rules for 280 locales. The adapter loads the app's `lang/` directory and uses the request's
  locale.
- **Laravel for Rust integration** in `oxblade-laravel`: a view engine and service provider, `route()`,
  `url()`, `asset()`, `@auth`/`@can`, CSRF and method fields, and `blade:check`.
- **Type checking:** `check` validates templates against the Rust view models that render them, in CI.
- **Migration from PHP Blade:** the `oxblade` command (`oxblade-cli`) converts `.blade.php` views,
  marks what needs a person with `TODO` comments, replays later PHP changes as diffs, and converts PHP
  language files with `oxblade lang`.
- **Limits:** output size, loop iterations, collection expansion and nesting depth are bounded
  per core render. The core expression language provides no direct file or environment access.
  The Laravel adapter's `config(key)` allows `app.name`, `app.env`, `app.url`, `app.debug` and keys
  the app explicitly exposes.

## How output is checked

Each case in [`conformance/cases`](conformance/cases) pairs a PHP Blade template with an oxblade
template and shared input data. CI reruns the PHP oracle to check the stored output, then compares
oxblade's render with that output. Case notes explain any deliberate adjustments to the pair.

<!-- kit:counts -->
375 tests · 6 fuzz targets (counted by `kit readme`)
<!-- /kit:counts -->

## Installation and configuration

See the [guide](docs/index.md).

## Compatibility

<!-- kit:compatibility -->
| Crate | Framework | MSRV |
| --- | --- | --- |
| `oxblade` | none | 1.99 |
| `oxblade-macros` | none | 1.99 |
| `oxblade-laravel` | `laravel-rust` 0.2 | 1.99 |
| `oxblade-cli` | none | 1.99 |
| `oxblade-mail` | none | 1.99 |
<!-- /kit:compatibility -->

The adapter requires `laravel-rust` 0.2.0 or later within the 0.2 series. The lockfile and CI tests
use 0.2.0.

## Contributing

Issues and pull requests are welcome, of any size: bug reports, failing test cases, docs fixes, new
features. A template that renders differently from Laravel is the most useful bug report: send the
`.blade.php` file, its data and both outputs. Contributions written with AI coding agents are welcome too;
please say what you checked. Run `scripts/kit ci` before opening a pull request, and see
[CONTRIBUTING.md](CONTRIBUTING.md). If you aren't sure, open an issue first.

## Credits

- [Laravel's Blade](https://github.com/illuminate/view) (MIT): the syntax, directives and behaviour, measured
  against Laravel itself. Laravel's pagination views and mail components and themes are adapted as files and
  keep Laravel's licence notice.
- [laravel-rust-format](https://github.com/bowerbird-si/laravel-rust-format): Laravel's string, number and
  date helpers and the `php::` functions.
- [rustblade](https://github.com/Arsalan-Khan17/RustBlade) (MIT OR Apache-2.0): ideas such as trusted HTML only
  in `{!! !!}`, `format` as Rust's `format!`, and migration with `TODO` markers.
- [blade-syntax](https://github.com/roderio/blade-rs) (MIT OR Apache-2.0): lexing rules for Blade's edge
  cases.
- [MiniJinja](https://github.com/mitsuhiko/minijinja): the speed baseline.

## Status and licence

Version 0.2.0 is the current alpha release. Maintenance is active. See the [MIT licence](LICENSE) and
[upstream credits](CREDITS.md).

Community package, not affiliated with Laravel.