packages feed

happs-tutorial-0.1: src/View.hs

{-# OPTIONS -fglasgow-exts -fno-monomorphism-restriction #-}
module View where

import Text.StringTemplate
import Misc

getTutTemplates = unsafeVolatileDirectoryGroup "templates" 1 -- 1 second reload time

-- plug a base templatate with a string which is based on a template file
withBaseTemplateW :: [(String,String)] -> String -> IO (StringTemplate String)
withBaseTemplateW attrs contentTmpl = do
  content <- return . toString =<< renderTut attrs contentTmpl
  withBaseContentW content

-- plug a base template with a string
withBaseContentW :: String -> IO (StringTemplate String)
withBaseContentW content = renderTut [("contentarea",content)] "base"
  
renderTut :: [(String,String)] -> String -> IO ( StringTemplate String )
renderTut attrs tmpl = withTutTemplate ( renderDef attrs tmpl )

withTutTemplate :: (STGroup String -> a) -> IO a
withTutTemplate = withTemplateDir "templates"