The stache package

[Tags:benchmark, bsd3, library, test]

Mustache templates for Haskell.


[Skip to Readme]

Properties

Versions 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.2.0, 0.2.1, 0.2.2
Change log CHANGELOG.md
Dependencies aeson (>=0.11 && <1.3), base (>=4.7 && <5.0), bytestring (==0.10.*), containers (==0.5.*), deepseq (==1.4.*), directory (>=1.2 && <1.4), exceptions (==0.8.*), filepath (>=1.2 && <1.5), megaparsec (>=5.0 && <6.0), mtl (>=2.1 && <3.0), semigroups (==0.18.*), template-haskell (>=2.10 && <2.12), text (==1.2.*), unordered-containers (>=0.2.5 && <0.3), vector (>=0.11 && <0.13) [details]
License BSD3
Author Mark Karpov <markkarpov@openmailbox.org>
Maintainer Mark Karpov <markkarpov@openmailbox.org>
Category Text
Home page https://github.com/stackbuilders/stache
Bug tracker https://github.com/stackbuilders/stache/issues
Source repository head: git clone https://github.com/stackbuilders/stache.git
Uploaded Sat Mar 18 19:27:04 UTC 2017 by mrkkrp
Updated Fri May 26 15:32:09 UTC 2017 by mrkkrp to revision 2
Distributions LTSHaskell:0.2.2, NixOS:0.2.2, Stackage:0.2.2, Tumbleweed:0.2.2
Downloads 549 total (42 in the last 30 days)
Votes
1 []
Status Docs available [build log]
Last success reported on 2017-03-18 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
devTurn on development settings.DisabledManual

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for stache

Readme for stache-0.2.2

Stache

License BSD3 Hackage Stackage Nightly Stackage LTS Build Status Coverage Status

This is a Haskell implementation of Mustache templates. The implementation conforms to the version 1.1.3 of official [Mustache specification] (https://github.com/mustache/spec). It is extremely simple and straightforward to use with 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 superior quality of error messages.

For rendering you only need to create Aeson's Value where you put the data to interpolate. Since the library re-uses Aeson's instances and most data types in Haskell ecosystem are instances of classes like Data.Aeson.ToJSON, the whole process is very simple for end user.

Template Haskell helpers for compilation of templates at compile time are available in the Text.Mustache.Compile.TH module. The helpers are currently available only for GHC 8 users though.

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.

Quick start

Here is an example of basic usage:

{-# 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 TIO

main :: IO ()
main = do
  let res = compileMustacheText "foo"
        "Hi, {{name}}! You have:\n{{#things}}\n  * {{.}}\n{{/things}}\n"
  case res of
    Left err -> putStrLn (parseErrorPretty err)
    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:

License

Copyright © 2016–2017 Stack Builders

Distributed under BSD 3 clause license.