Dali is a Racket implementation of a language similar to Mustache and Handlebars. It tries to be as faithful as possible to Mustache, providing a simple and high-level idiomatic module for callers. Not all features of Handlebars are implemented, or implemented in the same manner, as they are more JavaScript focused.
dali
- template engine module, providescompile-string
,expand-string
, andexpand-file
functions for template expansion. The expand functions rely on the compile function to read the template and convert it into a Racket function for performance and re-use.
The following example expands a very simple template with a nested list. Note that the context provided to the expansion function is simply comprised of hash?
and list?
structures.
(require dali)
(define template "a list: {{#items}} {{item}}, {{/items}}and that's all")
(define context (hash "items" (list (hash "item" "one")
(hash "item" "two")
(hash "item" "three"))))
(expand-string template context)
The module also provides a cache for loaded and compiled partial to support greater performance.
- To install (from within the package directory):
raco pkg install
- To install (once uploaded to pkgs.racket-lang.org):
raco pkg install dali
- To uninstall:
raco pkg remove dali
- To view documentation:
raco docs dali
-
1.1 - Feature Stable Release
- Completed documentation, using Mustache flow and examples.
- Refactored the compiled code for sections, it's now much faster and cleaner.
- Updated escaping to match the Mustache spec.
- Support more simple value options, numbers, symbols, booleans, and characters.
- Added
error-missing-value-handler
.
-
1.0 - Initial Version