{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeSynonymInstances #-} module Happstack.Server.Dialogues.Scaffold where import Happstack.Server import Happstack.Server.Dialogues import Language.Haskell.TH import qualified Data.ByteString.Lazy.Char8 as B import Data.Char (ord) import Data.Maybe (fromMaybe) import Data.List escapeHtml :: String -> String escapeHtml "" = "" escapeHtml ('\"':cs) = """ ++ escapeHtml cs escapeHtml ('\'':cs) = "'" ++ escapeHtml cs escapeHtml ('&' :cs) = "&" ++ escapeHtml cs escapeHtml ('<' :cs) = "<" ++ escapeHtml cs escapeHtml ('>' :cs) = ">" ++ escapeHtml cs escapeHtml (c :cs) | ord c >= 160 = "" ++ show (ord c) ++ ";" ++ escapeHtml cs | otherwise = c : escapeHtml cs {-| The 'scaffold' function builds a user interaction to display and collect information. In a finished web application, this should generally be replaced with a better mechanism for rendering pages, such as a templating engine, XSLT, or something of the sort. -} scaffold :: (Scaffolded a, Monad m) => String -> a -> Dlg m a scaffold s v = showPage out inp where out uri = return $ setHeader "Content-type" "text/html" $ toResponse $ "
" ++ escapeHtml s ++ "