Hastache

December 28, 2016

{-# LANGUAGE DeriveDataTypeable #-}

import Data.Data (Data)
import Data.Generics (Typeable)
import qualified Data.Text.Lazy.IO as TL
import Text.Hastache (hastacheStr, defaultConfig, encodeStr)
import Text.Hastache.Context (mkGenericContext)

data Model = Model { name :: String } deriving (Data, Typeable)

main :: IO ()
main = do
  let model = Model { name = "world" }
  let context = mkGenericContext model
  let template = "Hello, {{name}}!"
  hastacheStr defaultConfig (encodeStr template) context >>= TL.putStrLn

Usage

$ curl -s https://earldouglas.com/notes/haskell-recipes.md |
  codedown sh | sh -s hastache.md hastache
Hello, world!

References