Skip to content

idanarye/nu_plugin_handlebars

Repository files navigation

Build Status Latest Version

nu_plugin_handlebars

This is a Nushell plugin that adds integrates Handlebars template engine, powered by the handlebars crate.

Features

  • Redner Handlebars templates from Nushell.
  • The data for Handlebars is Nu values - no need to serialize them.
  • Supports partials.
  • Supports helpers.

Planned features

Installing

Install the crate using:

cargo install nu_plugin_handlebars

Then register the plugin using (this must be done inside Nushell):

plugin add ~/.cargo/bin/nu_plugin_handlebars

Usage

let 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 --text flag can also read from a file using a --file arg.
  • There is an handlebars eval command that can compile and render a template in a single command.

About

An `handlebars` command for Nushell for rendering Nu values using Handlebars templates

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors