- Notifications
You must be signed in to change notification settings - Fork10
Mustache templates for Haskell
License
stackbuilders/stache
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a Haskell implementation of Mustache templates. The implementationconforms to the version 1.1.3 of the officialMustachespecification. It has a minimal butcomplete API—three functions to compile templates (from directory, fromfile, and from lazy text) and one to render them.
The implementation uses the Megaparsec parsing library to parse thetemplates which results in high-quality error messages.
For rendering one only needs to create Aeson'sValue that is used forinterpolation of template variables. Since the library re-uses Aeson'sinstances and most data types in the Haskell ecosystem are instances ofclasses likeData.Aeson.ToJSON, the process is simple for the end user.
Template Haskell helpers for compilation of templates at compile time areavailable in theText.Mustache.Compile.TH module.
One feature that is not currently supported is lambdas. The feature ismarked as optional in the spec and can be emulated via processing of parsedtemplate representation. The decision to drop lambdas is intentional, forthe sake of simplicity and better integration with Aeson.
Here is an example of basic usage:
{-#LANGUAGE OverloadedStrings #-}moduleMain (main)whereimportData.AesonimportData.TextimportText.MegaparsecimportText.MustacheimportqualifiedData.Text.Lazy.IOasTIOmain::IO()main=dolet res= compileMustacheText"foo""Hi, {{name}}! You have:\n{{#things}}\n * {{.}}\n{{/things}}\n"case resofLeft bundle->putStrLn (errorBundlePretty bundle)Right template->TIO.putStr$ renderMustache template$ object ["name".= ("John"::Text) ,"things".= ["pen"::Text,"candle","egg"] ]If I run the program, it prints the following:
Hi, John! You have: * pen * candle * eggFor more information about Mustache templates the following links may behelpful:
- The official Mustache site:https://mustache.github.io/
- The manual:https://mustache.github.io/mustache.5.html
- The specification:https://github.com/mustache/spec
- Stack Builders Stache tutorial:https://www.stackbuilders.com/tutorials/haskell/mustache-templates/
MIT, seethe LICENSE file.
Do you want to contribute to this project? Please take a look at ourcontributing guideline to know how you can help us build it.
About
Mustache templates for Haskell
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.
