Updated to hamlet 0.2

This commit is contained in:
Michael Snoyman 2010-05-08 22:09:43 +03:00
parent 5df1351a74
commit 7a4f1ad6de
6 changed files with 47 additions and 51 deletions

View File

@ -52,22 +52,22 @@ xmlns _ = cs "http://www.w3.org/2005/Atom"
template :: AtomFeed url -> Hamlet url IO ()
template = [$hamlet|
%feed!xmlns=$xmlns$
%title $atomTitle.cs$
%link!rel=self!href=@atomLinkSelf@
%link!href=@atomLinkHome@
%updated $atomUpdated.formatW3.cs$
%id @atomLinkHome@
$forall atomEntries entry
%feed!xmlns=$.xmlns$
%title $.atomTitle.cs$
%link!rel=self!href=@.atomLinkSelf@
%link!href=@.atomLinkHome@
%updated $.atomUpdated.formatW3.cs$
%id @.atomLinkHome@
$forall .atomEntries entry
^entry.entryTemplate^
|]
entryTemplate :: AtomFeedEntry url -> Hamlet url IO ()
entryTemplate = [$hamlet|
%entry
%id @atomEntryLink@
%link!href=@atomEntryLink@
%updated $atomEntryUpdated.formatW3.cs$
%title $atomEntryTitle.cs$
%content!type=html $atomEntryContent.cdata$
%id @.atomEntryLink@
%link!href=@.atomEntryLink@
%updated $.atomEntryUpdated.formatW3.cs$
%title $.atomEntryTitle.cs$
%content!type=html $.atomEntryContent.cdata$
|]

View File

@ -43,6 +43,7 @@ import Data.Convertible.Text
import Control.Monad.Attempt
import Data.Maybe
import Control.Applicative
import Data.Typeable (Typeable)
import Control.Exception (Exception)
@ -90,21 +91,16 @@ getOpenIdR = do
[] -> return ()
(x:_) -> addCookie destCookieTimeout destCookieName x
rtom <- getRouteToMaster
let html = template (getParams rr "message", rtom)
applyLayout "Log in via OpenID" html
where
urlForward (_, wrapper) = wrapper OpenIdForward
hasMessage = not . null . fst
message ([], _) = cs ""
message (m:_, _) = cs m
template = [$hamlet|
$if hasMessage
%p.message $message$
let message = cs <$> (listToMaybe $ getParams rr "message")
let urlForward = rtom OpenIdForward
applyLayout "Log in via OpenID" $ [$hamlet|
$maybe message msg
%p.message $msg$
%form!method=get!action=@urlForward@
%label!for=openid OpenID:
%input#openid!type=text!name=openid
%input!type=submit!value=Login
|]
|] ()
getOpenIdForward :: GHandler Auth master ()
getOpenIdForward = do
@ -183,9 +179,9 @@ getCheck = do
%h1 Authentication Status
%dl
%dt identifier
%dd $fst$
%dd $.fst$
%dt displayName
%dd $snd$
%dd $.snd$
|]
json (ident, dn) =
jsonMap [ ("ident", jsonScalar ident)

View File

@ -71,11 +71,11 @@ getRegisterR = do
toMaster <- getRouteToMaster
applyLayout "Register a new account" $ [$hamlet|
%p Enter your e-mail address below, and a confirmation e-mail will be sent to you.
%form!method=post!action=@id@
%form!method=post!action=@RegisterR.toMaster@
%label!for=email E-mail
%input#email!type=email!name=email!width=150
%input!type=submit!value=Register
|] $ toMaster RegisterR
|] ()
postRegisterR :: YesodEmailAuth master => GHandler EmailAuth master RepHtml
postRegisterR = do
@ -93,8 +93,8 @@ postRegisterR = do
let verUrl = render $ VerifyR lid verKey
liftIO $ sendVerifyEmail y email verKey verUrl
applyLayout "Confirmation e-mail sent" $ [$hamlet|
%p A confirmation e-mail has been sent to $id$.
|] $ cs email
%p A confirmation e-mail has been sent to $email.cs$.
|] ()
checkEmail :: Form ParamValue -> Form ParamValue
checkEmail = notEmpty -- FIXME
@ -132,12 +132,12 @@ getLoginR = do
toMaster <- getRouteToMaster
msg <- getMessage
applyLayout "Login" $ [$hamlet|
$maybe snd msg
%p.message $msg$
$maybe msg ms
%p.message $ms$
%p Please log in to your account.
%p
%a!href=@fst.fst@ I don't have an account
%form!method=post!action=@fst.snd@
%a!href=@RegisterR.toMaster@ I don't have an account
%form!method=post!action=@LoginR.toMaster@
%table
%tr
%th E-mail
@ -150,7 +150,7 @@ $maybe snd msg
%tr
%td!colspan=2
%input!type=submit!value=Login
|] ((toMaster RegisterR, toMaster LoginR), msg)
|] ()
postLoginR :: YesodEmailAuth master => GHandler EmailAuth master ()
postLoginR = do
@ -182,10 +182,10 @@ getPasswordR = do
redirect RedirectTemporary $ toMaster LoginR
msg <- getMessage
applyLayout "Set password" $ [$hamlet|
$maybe fst msg
%p.message $msg$
$maybe msg ms
%p.message $ms$
%h3 Set a new password
%form!method=post!action=@snd@
%form!method=post!action=@PasswordR.toMaster@
%table
%tr
%th New password
@ -198,7 +198,7 @@ $maybe fst msg
%tr
%td!colspan=2
%input!type=submit!value=Submit
|] (msg, toMaster PasswordR)
|] ()
postPasswordR :: YesodEmailAuth master => GHandler EmailAuth master ()
postPasswordR = do

View File

@ -47,13 +47,13 @@ data SitemapUrl url = SitemapUrl
, priority :: Double
}
sitemapNS :: [SitemapUrl url] -> HtmlContent
sitemapNS _ = cs "http://www.sitemaps.org/schemas/sitemap/0.9"
sitemapNS :: HtmlContent
sitemapNS = cs "http://www.sitemaps.org/schemas/sitemap/0.9"
template :: [SitemapUrl url] -> Hamlet url IO ()
template = [$hamlet|
%urlset!xmlns=$sitemapNS$
$forall id url
$forall .id url
%url
%loc @url.sitemapLoc@
%lastmod $url.sitemapLastMod.formatW3.cs$

View File

@ -67,11 +67,11 @@ class YesodSite a => Yesod a where
!!!
%html
%head
%title $pageTitle$
^pageHead^
%title $p.pageTitle$
^p.pageHead^
%body
^pageBody^
|] p
^p.pageBody^
|] ()
-- | Gets called at the beginning of each request. Useful for logging.
onRequest :: a -> Request -> IO ()
@ -126,7 +126,7 @@ defaultErrorHandler NotFound = do
r <- waiRequest
applyLayout' "Not Found" $ [$hamlet|
%h1 Not Found
%p $helper$
%p $.helper$
|] r
where
helper = Unencoded . cs . W.pathInfo
@ -146,10 +146,10 @@ defaultErrorHandler (InvalidArgs ia) =
defaultErrorHandler (InternalError e) =
applyLayout' "Internal Server Error" $ [$hamlet|
%h1 Internal Server Error
%p $cs$
|] e
%p $e.cs$
|] ()
defaultErrorHandler (BadMethod m) =
applyLayout' "Bad Method" $ [$hamlet|
%h1 Method Not Supported
%p Method "$cs$" not supported
|] m
%p Method "$m.cs$" not supported
|] ()

View File

@ -30,7 +30,7 @@ library
template-haskell >= 2.4 && < 2.5,
web-routes >= 0.22 && < 0.23,
web-routes-quasi >= 0.1 && < 0.2,
hamlet >= 0.0.1 && < 0.1,
hamlet >= 0.2.0 && < 0.3,
transformers >= 0.1 && < 0.3,
clientsession >= 0.2 && < 0.3,
MonadCatchIO-transformers >= 0.2.2 && < 0.3,