MyNixOS website logo
Description

Straight implementation of mustache templates.

mustache-haskell

A Haskell implementation of mustache templates. Expects input data to be JSON.

Should be compatible with the the mustache specification. Except lambdas are not supported.

Supported syntax:

  • basic variables
  • sections
  • inverted sections
  • comments (are suppressed)
  • partials
  • set delimiter

This project currently only provides a command line interface. Later versions will provide a library API for templating ToJSON instances.

Install

You need the Haskell platform on your system.

cabal install mustache-haskell

Or alternatively

git clone [email protected]:danchoi/mustache-haskell.git
cd mustache-haskell
cabal sandbox init
cabal install
# Now copy .cabal-sandbox/bin/mus to your PATH

Usage

mus template.mustache < input.json
mus 

Usage: mus [-c] [-d TEMPLATE_DIRECTORY] TEMPLATE_FILE
  A Haskell implementation of Mustache templates. On STDIN provide the JSON to
  insert into the template.

Available options:
  -h,--help                Show this help text
  -c                       Just output parse tree of template file
  -d TEMPLATE_DIRECTORY    Template directory

List separator syntax

mustache-haskell adds one additional feature to the mustache specification. If you are outputing elements of a list, you can designate an optional list separator with the following syntax:

{{#hobbies, }}{{name}}{{/hobbies}}

This designates ", " as the list separator and will output

sewing, brewing, cooking

when the input is

{"hobbies":[{"name":"sewing"},{"name":"brewing"},{"name":"cooking"}]}

Performance

In a few informal tests,

mus template.mustache < input.json

is about 10x faster than the Ruby mustache gem command-line implementation,

mustache - template.mustache < input.json

Related projects

  • whiskers Mustache templates with Template Haskell (reddit)
  • hastache Haskell implementation of Mustache templates
  • mustache2hs takes in Haskell records (single data constructor only) and a list of mustache template and record name pairs, and generates Haskell code for functions that take an escape function and one of the records
  • mustache.go an implementation of the mustache template language in Go.
Metadata

Version

0.1.0.5

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows