This is a Nushell plugin that adds integrates Handlebars template engine, powered by the handlebars crate.
- Redner Handlebars templates from Nushell.
- The data for Handlebars is Nu values - no need to serialize them.
- Supports partials.
- Supports helpers.
Install the crate using:
cargo install nu_plugin_handlebarsThen register the plugin using (this must be done inside Nushell):
plugin add ~/.cargo/bin/nu_plugin_handlebarslet hb = handlebars new
$hb | handlebars helper add {|a b| $a + $b}
$hb | handlebars partial addition --text "{{x}} + {{y}}"
let tpl = $hb | handlebars compile --text "{{>addition}} = {{add x y}}"
{x: 1, y: 2} | handlebars render $tpl
# This prints `1 + 2 = 3`handlebars helper and handlebars partial also return the registry, so the entire registry creation and template compilation can be pipelined:
let tpl = handlebars new
| handlebars helper add {|a b| $a + $b}
| handlebars partial addition --text "{{x}} + {{y}}"
| handlebars compile --text "{{>addition}} = {{add x y}}"- Commands that accept a string via a
--textflag can also read from a file using a--filearg. - There is an
handlebars evalcommand that can compile and render a template in a single command.