{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, OverloadedStrings, RecordWildCards, TemplateHaskell, TypeFamilies, TypeSynonymInstances, OverloadedStrings #-} {-# OPTIONS_GHC -F -pgmFhsx2hs #-} module TinyAuth.Pages where import Data.Text (Text) import qualified Data.Text as Text (null, unpack) import qualified Data.Text.Lazy as Lazy (pack, Text) import Data.Time.Clock (getCurrentTime) import HSP (toName) import HSP.XML as HTML (Attribute(MkAttr), pAttrVal, XML(CDATA)) import Happstack.Auth (AuthProfileURL, getUserId, handleAuthProfile) import Happstack.Foundation ((++>), (<$>), (<++), Applicative((<*), (<*>)), asContentType, Attr(..), EmbedAsAttr(..), EmbedAsChild(..), errorList, fieldset, form, fromStringLit, Functor, Happstack, inputSubmit, inputText, label, li, liftM, mapM, method, Method(GET), Monad(return), MonadIO(liftIO), nestURL, notFound, ok, PathInfo(toPathSegments), query, reform, Response, RouteT, seeOtherURL, select, serveFile, showURL, textarea, ToMessage(toResponse), transformEither, transformEitherM, ul, update, whereami, XML, XMLGen(..), XMLGenerator, XMLGenT(XMLGenT)) import Text.Blaze.Html (Html) import Text.Blaze.Html.Renderer.Text (renderHtml) import TinyAuth.Acid (Acid(..)) import TinyAuth.Events (GetPasteById(GetPasteById), GetRecentPastes(GetRecentPastes), InsertPaste(InsertPaste)) import TinyAuth.Route (CtrlV, CtrlVForm, Route(..)) import TinyAuth.Template (appTemplate, baseAppTemplate) import TinyAuth.Types (Format(..), Paste(..), PasteId(..), PasteMeta(PasteMeta, format, nickname, pasteId, pasted, title)) ------------------------------------------------------------------------------ -- Pages ------------------------------------------------------------------------------ -- | page handler for 'ViewRecent' viewRecentPage :: Acid -> CtrlV Response viewRecentPage acid = do method GET recent <- query (GetRecentPastes 20 0) case recent of [] -> appTemplate acid "Recent Pastes" ()
There are no pastes yet.
_ -> appTemplate acid "Recent Pastes" () $ <%>| id | title | author | date | format |
|---|
Paste <% pid %> could not be found.
(Just (Paste (PasteMeta{..}) paste)) -> do ok () appTemplate acid (Lazy.pack $ "Paste " ++ (show $ unPasteId pid)) () $<% txt %>-- | page handler for 'NewPaste' newPastePage :: Acid -> CtrlV Response newPastePage acid@Acid{..} = do here <- whereami mUserId <- getUserId acidAuth acidProfile case mUserId of Nothing -> appTemplate acid "Add a Paste" () $ <%>