The StrappedTemplates package

[Tags:bsd3, library, test]

Easy templating in haskell.

  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 $}

Properties

Versions 0.1.0.0, 0.1.1.0, 0.2.0.0, 0.2.0.1, 0.2.0.2
Dependencies base (>=4.7 && <4.9), blaze-builder (>=0.3 && <0.5), bytestring (==0.10.*), containers (==0.5.*), filemanip (==0.3.6.*), filepath (>=1.3 && <1.5), mtl (>=2.2.1 && <2.3), parsec (==3.1.*), text (>=1.0 && <1.3), transformers (==0.4.*) [details]
License BSD3
Author Kyle Hanson
Maintainer me@khanson.io
Category Text
Home page https://github.com/hansonkd/StrappedTemplates
Source repository head: git clone git@github.com:hansonkd/StrappedTemplates.git
Uploaded Sun Jul 12 17:47:32 UTC 2015 by hansonkd
Distributions NixOS:0.2.0.2
Downloads 943 total (10 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2015-07-12 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees