Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mustache templates for Haskell

License

NotificationsYou must be signed in to change notification settings

stackbuilders/stache

Repository files navigation

HackageStackage NightlyStackage LTSCI

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.

Usage

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  * egg

For more information about Mustache templates the following links may behelpful:

License

MIT, seethe LICENSE file.

Contributing

Do you want to contribute to this project? Please take a look at ourcontributing guideline to know how you can help us build it.


Stack BuildersCheck out our libraries |Join our team

About

Mustache templates for Haskell

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors9


[8]ページ先頭

©2009-2025 Movatter.jp