Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stackbuilders/stache
Mustache templates for Haskell
https://github.com/stackbuilders/stache
hacktoberfest hacktoberfest2023 haskell mustache-templates
Last synced: 6 days ago
JSON representation
Mustache templates for Haskell
- Host: GitHub
- URL: https://github.com/stackbuilders/stache
- Owner: stackbuilders
- License: mit
- Created: 2016-06-23T16:03:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T04:05:50.000Z (2 months ago)
- Last Synced: 2024-10-30T00:35:08.395Z (2 months ago)
- Topics: hacktoberfest, hacktoberfest2023, haskell, mustache-templates
- Language: Haskell
- Homepage:
- Size: 284 KB
- Stars: 28
- Watchers: 23
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Stache
[![Hackage](https://img.shields.io/hackage/v/stache.svg?style=flat)](https://hackage.haskell.org/package/stache)
[![Stackage Nightly](http://stackage.org/package/stache/badge/nightly)](http://stackage.org/nightly/package/stache)
[![Stackage LTS](http://stackage.org/package/stache/badge/lts)](http://stackage.org/lts/package/stache)
![CI](https://github.com/stackbuilders/stache/workflows/CI/badge.svg?branch=master)This is a Haskell implementation of Mustache templates. The implementation
conforms to the version 1.1.3 of the official [Mustache
specification](https://github.com/mustache/spec). It has a minimal but
complete API—three functions to compile templates (from directory, from
file, and from lazy text) and one to render them.The implementation uses the Megaparsec parsing library to parse the
templates which results in high-quality error messages.For rendering one only needs to create Aeson's `Value` that is used for
interpolation of template variables. Since the library re-uses Aeson's
instances and most data types in the Haskell ecosystem are instances of
classes like `Data.Aeson.ToJSON`, the process is simple for the end user.Template Haskell helpers for compilation of templates at compile time are
available in the `Text.Mustache.Compile.TH` module.One feature that is not currently supported is lambdas. The feature is
marked as optional in the spec and can be emulated via processing of parsed
template representation. The decision to drop lambdas is intentional, for
the sake of simplicity and better integration with Aeson.## Usage
Here is an example of basic usage:
```haskell
{-# LANGUAGE OverloadedStrings #-}module Main (main) where
import Data.Aeson
import Data.Text
import Text.Megaparsec
import Text.Mustache
import qualified Data.Text.Lazy.IO as TIOmain :: IO ()
main = do
let res = compileMustacheText "foo"
"Hi, {{name}}! You have:\n{{#things}}\n * {{.}}\n{{/things}}\n"
case res of
Left 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
* egg
```For more information about Mustache templates the following links may be
helpful:* 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/## License
MIT, see [the LICENSE file](LICENSE).
## Contributing
Do you want to contribute to this project? Please take a look at our [contributing guideline](/docs/CONTRIBUTING.md) to know how you can help us build it.
---
[Check out our libraries](https://github.com/stackbuilders/) | [Join our team](https://www.stackbuilders.com/join-us/)