handlebarsmischelpers

Crates.io Crates.io

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Build Status Documentation

A collection of helpers for handlebars (rust).

Helpers extend the template to generate or to transform content. Few helpers are included, but if you need more helpers, ask via an issue or a PR.

To use an helper:

handlebars {{ helper_name argument}}

To chain helpers, use parenthesis:

handlebars {{ to_upper_case (to_singular "Hello foo-bars") }} // -> "BAR"

see Handlebars templating language

String transformation

for the same input: "Hello foo-bars"

helper_name | example out -- | -- to_lower_case | "hello foo-bars" to_upper_case | "HELLO FOO-BARS" to_camel_case | "helloFooBars" to_pascal_case | "HelloFooBars" to_snake_case | "hello_foo_bars" to_screaming_snake_case | "HELLO_FOO_BARS" to_kebab_case | "hello-foo-bars" to_train_case | "Hello-Foo-Bars" to_sentence_case | "Hello foo bars" to_title_case | "Hello Foo Bars" to_class_case | "HelloFooBar" to_table_case | "hello_foo_bars" to_plural | "bars" to_singular | "bar"

Http content

Helper able to render body response from an http request.

helper_name | usage -- | -- http_get | http_get "http://hello/..." gitignore_io | gitignore_io "rust"

Path extraction

Helper able to extract (or transform) path (defined as string).

for the same input: "/hello/bar/foo.txt"

helpername | sample output -- | -- filename | "foo.txt" parent | "/hello/bar" extension | "txt"

Environment variable

Helper able to get environment variables.

helpername | usage -- | -- envvar | env_var "HOME"

Specials environment variables are predefined (some of them come from std::env::consts - Rust):

variable possible values
"ARCH"
  • x86
  • x86_64
  • arm
  • aarch64
  • mips
  • mips64
  • powerpc
  • powerpc64
  • s390x
  • sparc64
"DLL_EXTENSION"
  • so
  • dylib
  • dll
"DLL_PREFIX"
  • lib
  • "" (an empty string)
"DLL_SUFFIX"
  • .so
  • .dylib
  • .dll
"EXE_EXTENSION"
  • exe
  • "" (an empty string)
"EXE_SUFFIX"
  • .exe
  • .nexe
  • .pexe
  • "" (an empty string)
"FAMILY"
  • unix
  • windows
"OS"
  • linux
  • macos
  • ios
  • freebsd
  • dragonfly
  • netbsd
  • openbsd
  • solaris
  • android
  • windows
"USERNAME"try to find the current username, in the order:
  1. environment variable "USERNAME"
  2. environment variable "username"
  3. environment variable "USER"
  4. environment variable "user"

JSON

Helper able to extract information from json using JMESPath syntax.

usage| output -- | -- {{ json_query "foo" "{}" }} | null {{ json_query "foo" "{\"foo\":{\"bar\":{\"baz\":true}}}" }} | {"bar":{"baz":true}} {{ json_query "foo.bar.baz" "{\"foo\":{\"bar\":{\"baz\":true}}}" }} | true

Assign

Helper able to assign (to set) a variable to use later in the template.

usage| output -- | -- {{ assign "foo" "{}" }} | ` {{ assign "foo" "{}" }}{{ foo }}|{} {{ assign "foo" "hello world" }}{{ foo }}|hello world {{ assign "foo" {} }}{{ foo }}|[object] {{ assign "foo" {"bar": 33} }}{{ foo }}|[object]`