NAME
BarefootJS::Backend::Xslate - Text::Xslate (Kolon) rendering backend for BarefootJS
SYNOPSIS
use BarefootJS;
use BarefootJS::Backend::Xslate;
my $backend = BarefootJS::Backend::Xslate->new(path => ['templates']);
my $bf = BarefootJS->new(undef, { backend => $backend });
# Renders templates/counter.tx, binding the runtime as the `bf` object.
my $html = $backend->render_named('counter', $bf, { count => 0 });
DESCRIPTION
A rendering backend that lets the engine-agnostic BarefootJS runtime render its marked templates with Text::Xslate (Kolon syntax). Because it has no dependency on a web framework, a plain Text::Xslate instance renders templates from a path, so it runs under any PSGI / Plack application (or none at all).
Pair it with the @barefootjs/xslate compile-time adapter, which emits Kolon .tx templates that call the runtime as a bf object — <: $bf.scope_attr() :>, <: $bf.json($x) :>, <: $bf.spread_attrs($h) :>. Kolon auto-escapes <: ... :> interpolations (the backend builds Text::Xslate with type => 'html'); helpers that emit markup return mark_raw values, mirroring Mojo EP's <%== versus <%=.
METHODS
new(%args)
Constructs a backend. Accepts a pre-built xslate instance, or a path (arrayref of template directories) plus optional xslate_options to build a Kolon, html-escaping Text::Xslate. json_encoder overrides the default canonical JSON::PP encoder.
No custom Kolon function map is needed: the @barefootjs/xslate adapter calls every runtime helper as a $bf method ($bf.filter($arr, -> $x { ... }), $bf.lc($s), …) or a Kolon builtin ($arr.join(", "), $arr.size()), so a plain instance renders the emitted templates.
encode_json($data) / mark_raw($str) / materialize($value) / render_named($name, $bf, \%vars)
The four engine-specific operations the runtime delegates to. mark_raw uses Text::Xslate::mark_raw; render_named renders <name>.tx with $bf bound as the bf variable plus \%vars.
SEE ALSO
BarefootJS, Text::Xslate, Plack, https://github.com/piconic-ai/barefootjs
AUTHOR
kobaken <kentafly88@gmail.com>
LICENSE
Copyright (c) 2025-present BarefootJS Contributors.
This library is free software; you can redistribute it and/or modify it under the MIT License. See the LICENSE file in the distribution for the full text.