happstack-hsp 6.0.0 → 6.0.1
raw patch · 3 files changed
+37/−15 lines, 3 files
Files
- happstack-hsp.cabal +2/−2
- src/HSP/ServerPartT.hs +6/−0
- src/Happstack/Server/HSP/HTML.hs +29/−13
happstack-hsp.cabal view
@@ -1,5 +1,5 @@ Name: happstack-hsp-Version: 6.0.0+Version: 6.0.1 Synopsis: Support for using HSP templates in Happstack Description: Happstack is a web application framework. HSP is an XML templating solution. This package makes it easy to use HSP templates with Happstack. Homepage: http://www.happstack.com/@@ -7,7 +7,7 @@ License-file: LICENSE Author: Jeremy Shaw Maintainer: Happstack team <happs@googlegroups.com>--- Copyright: +Copyright: 2011 Jeremy Shaw Category: Web Build-type: Simple Cabal-version: >=1.6
src/HSP/ServerPartT.hs view
@@ -73,6 +73,12 @@ instance (Monad m) => EmbedAsChild (ServerPartT m) String where asChild = XMLGenT . return . (:[]) . SChild . pcdata +instance (Monad m) => EmbedAsChild (ServerPartT m) Int where+ asChild = XMLGenT . return . (:[]) . SChild . pcdata . show++instance (Monad m) => EmbedAsChild (ServerPartT m) Integer where+ asChild = XMLGenT . return . (:[]) . SChild . pcdata . show+ instance (Monad m) => EmbedAsChild (ServerPartT m) XML where asChild = XMLGenT . return . (:[]) . SChild
src/Happstack/Server/HSP/HTML.hs view
@@ -1,8 +1,11 @@+-- | support for using HSP+Happstack for rendering HTML {-# LANGUAGE FlexibleInstances, FlexibleContexts #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-orphans -F -pgmFtrhsx #-} module Happstack.Server.HSP.HTML- ( webHSP+ ( defaultTemplate+ , webHSP , webHSP'+ , module HSP ) where import Control.Monad.Trans (MonadIO(), liftIO)@@ -11,16 +14,11 @@ import Control.Monad (liftM) import Happstack.Server ( ToMessage(toMessage, toContentType, toResponse)- , Response()+ , Response ) import HSP- ( HSP()- , XML()- , XMLMetaData(XMLMetaData, contentType)- , evalHSP- , html4Strict- , renderAsHTML- )+import HSP.ServerPartT ()+import qualified HSX.XMLGenerator as HSX instance ToMessage XML where toContentType _ = P.pack "text/html;charset=utf-8"@@ -34,13 +32,31 @@ toMessage (Nothing, xml) = L.fromString (renderAsHTML xml) --- | Converts a @HSP XML@ to a Happstack Response.+-- | A generic webpage template+defaultTemplate :: (XMLGenerator m, EmbedAsChild m headers, EmbedAsChild m body) => + String -- ^ text to use in \<title\> tag+ -> headers -- ^ extra headers to insert in \<head\> tag. Use @()@ if none.+ -> body -- ^ content to put between the \<body\> tags.+ -> m (HSX.XML m)+defaultTemplate title headers body =+ unXMLGenT $+ <html>+ <head>+ <title><% title %> </title>+ <% headers %>+ </head>+ <body>+ <% body %>+ </body>+ </html>++-- | Converts a @HSP XML@ to a Happstack 'Response'. -- Since @HSP XML@ is the type returned by using literal HTML syntax--- with HSP, you can wrap up your HTML as webHSP $ <html>...</html>+-- with HSP, you can wrap up your HTML as webHSP $ \<html\>...\</html\> -- to use it with Happstack. webHSP :: (MonadIO m) => HSP XML -> m Response webHSP = webHSP' Nothing --- | webHSP with XMLMetaData+-- | webHSP with 'XMLMetaData' webHSP' :: (MonadIO m) => Maybe XMLMetaData -> HSP XML -> m Response webHSP' metadata hsp = toResponse `liftM` liftIO (evalHSP metadata hsp)