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 :: AtomFeed url -> Hamlet url IO ()
template = [$hamlet| template = [$hamlet|
%feed!xmlns=$xmlns$ %feed!xmlns=$.xmlns$
%title $atomTitle.cs$ %title $.atomTitle.cs$
%link!rel=self!href=@atomLinkSelf@ %link!rel=self!href=@.atomLinkSelf@
%link!href=@atomLinkHome@ %link!href=@.atomLinkHome@
%updated $atomUpdated.formatW3.cs$ %updated $.atomUpdated.formatW3.cs$
%id @atomLinkHome@ %id @.atomLinkHome@
$forall atomEntries entry $forall .atomEntries entry
^entry.entryTemplate^ ^entry.entryTemplate^
|] |]
entryTemplate :: AtomFeedEntry url -> Hamlet url IO () entryTemplate :: AtomFeedEntry url -> Hamlet url IO ()
entryTemplate = [$hamlet| entryTemplate = [$hamlet|
%entry %entry
%id @atomEntryLink@ %id @.atomEntryLink@
%link!href=@atomEntryLink@ %link!href=@.atomEntryLink@
%updated $atomEntryUpdated.formatW3.cs$ %updated $.atomEntryUpdated.formatW3.cs$
%title $atomEntryTitle.cs$ %title $.atomEntryTitle.cs$
%content!type=html $atomEntryContent.cdata$ %content!type=html $.atomEntryContent.cdata$
|] |]

View File

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

View File

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

View File

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

View File

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

View File

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