package mustache

  1. Overview
  2. Docs
Mustache logic-less templates in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

mustache-3.2.0.tbz
sha256=080b6852ce81f2604134348e19d7b1c8d2ea311519be854ad4517729508c4d4c
sha512=80bf68ab0547002290254979cb60ad0962ac526551f9a7a0337c4f0426128b2974ca1d9efbac345613d73b340d7027e1331a0baad0d3743256dbd1b2d97f1eb0

Description

Read and write mustache templates, and render them by providing a json object. Contains the mustache command line utility for driving logic-less templates.

Published: 28 Nov 2023

README

ocaml-mustache

mustache.js logic-less templates in OCaml

Example usage

let tmpl =
  try
    Mustache.of_string "Hello {{name}}\n\
                        Mustache is:\n\
                        {{#qualities}}\
                        * {{name}}\n\
                        {{/qualities}}"
  with Mustache.Parse_error err ->
    Format.eprintf "%a@."
      Mustache.pp_template_parse_error err;
    exit 3

let json =
  `O [ "name", `String "OCaml"
     ; "qualities", `A [ `O ["name", `String "awesome"]
                       ; `O ["name", `String "simple"]
                       ; `O ["name", `String "fun"]
                       ]
     ]

let rendered =
  try Mustache.render tmpl json
  with Mustache.Render_error err ->
    Format.eprintf "%a@."
      Mustache.pp_render_error err;
    exit 2

Supported template language

ocaml-mustache accepts the whole Mustache template language, except:

  • it does not support setting delimiter tags to something else than '{{' and '}}'.

  • it does not support lambdas inside the provided data

It is automatically tested against the latest mustache specification testsuite.

ocaml-mustache also supports template inheritance / partials with parameters, tested against the semi-official specification.

Todo/Wish List

  • Support for ropes

http://mustache.github.io/

Dependencies (5)

  1. ocaml >= "4.08"
  2. cmdliner >= "1.0.4" & < "1.1.0"
  3. menhir >= "20180703"
  4. jsonm >= "1.0.1"
  5. dune >= "2.7"

Dev Dependencies (3)

  1. odoc with-doc
  2. ezjsonm with-test
  3. ounit2 with-test

Conflicts

None

OCaml

Innovation. Community. Security.