{-|
Module      : Slick.Mustache
Description : Slick utilities for working with mustache
Copyright   : (c) Chris Penner, 2019
License     : BSD3
-}
module Slick.Mustache
  ( compileTemplate'
  )
where

import           Development.Shake
import           Text.Mustache
import           Text.Mustache.Compile

-- | Like 'compileTemplate' from <http://hackage.haskell.org/package/mustache mustache> but tracks changes to template files and partials within Shake for cache-busting.
compileTemplate' :: FilePath -> Action Template
compileTemplate' :: FilePath -> Action Template
compileTemplate' FilePath
fp = do
  Partial => [FilePath] -> Action ()
need [FilePath
fp]
  Either ParseError Template
result <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO (Either ParseError Template)
localAutomaticCompile FilePath
fp
  case Either ParseError Template
result of
    Right Template
templ -> do
      Partial => [FilePath] -> Action ()
need (STree -> [FilePath]
getPartials forall b c a. (b -> c) -> (a -> b) -> a -> c
. Template -> STree
ast forall a b. (a -> b) -> a -> b
$ Template
templ)
      forall (m :: * -> *) a. Monad m => a -> m a
return Template
templ
    Left ParseError
err -> forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> FilePath
show ParseError
err