| CARVIEW |
Select Language
HTTP/2 200
server: nginx
date: Fri, 16 Jan 2026 21:08:26 GMT
content-type: application/octet-stream
content-length: 6934
last-modified: Mon, 11 Jan 2021 21:17:27 GMT
{-# LANGUAGE FlexibleContexts, FlexibleInstances,
MultiParamTypeClasses, ScopedTypeVariables,
TypeFamilies, TypeSynonymInstances,
QuasiQuotes, OverloadedStrings #-}
module Main where
import Control.Applicative
import Control.Applicative.Indexed
(IndexedFunctor(..), IndexedApplicative(..))
import Control.Monad (msum)
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as Lazy
import qualified Data.Text as Strict
import Happstack.Server
import Happstack.Server.XMLGenT ()
import Happstack.Server.HSP.HTML ()
import HSP
import HSP.Monad (HSPT(..))
import Language.Haskell.HSX.QQ (hsx)
import Text.Reform
( CommonFormError(..), Form, FormError(..), Proof(..), (++>)
, (<++), commonFormErrorStr, decimal, prove
, transformEither, transform )
import Text.Reform.Happstack
import Text.Reform.HSP.Text
type AppT m = XMLGenT (HSPT XML (ServerPartT m))
type AppT' m = HSPT XML (ServerPartT m)
appTemplate :: ( Functor m, Monad m
, EmbedAsChild (AppT' m) headers
, EmbedAsChild (AppT' m) body
) =>
Text -- ^ contents of tag
-> headers -- ^ extra content for tag.
-- use () for nothing
-> body -- ^ contents of tag
-> AppT m Response
appTemplate title headers body =
toResponse <$> [hsx|
<% title %>
<% headers %>
<% body %>
|]
type SimpleForm =
Form (AppT IO) [Input] AppError [AppT IO XML] ()
data AppError
= Required
| NotANatural String
| AppCFE (CommonFormError [Input])
deriving Show
instance (Functor m, Monad m) =>
EmbedAsChild (AppT' m) AppError where
asChild Required =
asChild $ "required"
asChild (NotANatural str) =
asChild $ "Could not decode as a positive integer: " ++ str
asChild (AppCFE cfe) =
asChild $ commonFormErrorStr show cfe
instance (Functor m, Monad m) =>
EmbedAsChild (AppT' m) Strict.Text where
asChild t = asChild (Lazy.fromStrict t)
instance (Functor m, Monad m) =>
EmbedAsAttr (AppT' m) (Attr Text Strict.Text) where
asAttr (n := v) = asAttr (n := Lazy.fromStrict v)
instance FormError AppError where
type ErrorInputType AppError = [Input]
commonFormError = AppCFE
data Message = Message
{ name :: Strict.Text -- ^ the author's name
, title :: Strict.Text -- ^ the message title
, message :: Strict.Text -- ^ contents of the message
} deriving (Eq, Ord, Read, Show)
renderMessage :: ( Functor m
, Monad m
, EmbedAsChild (AppT' m) Strict.Text) =>
Message -> AppT m XML
renderMessage msg =
[hsx|
- name:
- <% name msg %>
- title:
- <% title msg %>
- message:
- <% message msg %>