This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.
import Control.Monad.IO.Class
import qualified Blaze.ByteString.Builder as B
import qualified Data.Text as T
import Data.Time
import Text.Strapped
makeBucket :: Integer -> InputBucket IO
makeBucket i = bucketFromList
[ ("is", lit $ map (LitInteger) [1..i])
, ("is_truthy", lit i)
, ("ioTime", Func (\_ -> (liftIO $ getCurrentTime) >>= (\c -> return $ LitText $ T.pack $ show c)))
]
main :: IO ()
main = do
tmpls <- templateStoreFromDirectory defaultConfig "examples/templates" ".strp"
case tmpls of
Left err -> print err
Right store -> do
rendered <- render (putStore store defaultConfig) (makeBucket 2) "base_simple.strp"
either (print) (print . B.toByteString) rendered
{$ inherits base.strp $}
{$ isblock body $}
An IO function to find the current time: ${ ioTime }
{$ if is_truthy $}
{$ inherits base.strp $}
{$ isblock body $}
Any block level can inherit from another template and override blocks.
{$ endisblock $}
{$ else $}
Don't show me.
{$ endif $}
Taken from an includes:
{$ include includes/includes.strp $}
Lets count...
{$ for i in is $}
${ i }
{$ endfor $}
{$ endisblock $}