{- | Module : Shakebook.Mustahce Copyright : Copyright (C) 2020 Daniel Firth Maintainer : Daniel Firth )) import GHC.TypeLits (KnownSymbol) import RIO import qualified RIO.Text as T import qualified Slick.Mustache import Text.Mustache -- | Lifted version of `Slick.Mustache.compileTemplate'` with well-typed `Path`. compileTemplate' :: MonadAction m => Path b File -> m Template compileTemplate' = liftAction . Slick.Mustache.compileTemplate' . toFilePath -- | Build a single page straight from a template. buildPageAction :: MonadAction m => Path b File -- ^ The HTML templatate. -> Value -- ^ A JSON value. -> Path b' File -- ^ The out filepath. -> m () buildPageAction template value out = do pageT <- compileTemplate' template writeFile' out $ substitute pageT value buildPageAction' :: (MonadAction m, MonadThrow m, KnownSymbol s) => Path Rel Dir -> (s :-> xs) -> JsonFormat e xs -> Path b File -> m () buildPageAction' d xs f o = do let (t, v) = valWithName xs t' <- parseRelFile $ T.unpack t buildPageAction (d t') (toJsonWithFormat f v) o