Recent Hamlet changes

This commit is contained in:
Michael Snoyman 2011-01-19 21:53:39 +02:00
parent 085bb88bb1
commit 0874b61763
3 changed files with 51 additions and 47 deletions

View File

@ -116,16 +116,17 @@ class Eq (Route a) => Yesod a where
defaultLayout w = do defaultLayout w = do
p <- widgetToPageContent w p <- widgetToPageContent w
mmsg <- getMessage mmsg <- getMessage
hamletToRepHtml [HAMLET| hamletToRepHtml [HAMLET|\
!!! \<!DOCTYPE html>
%html
%head <html>
%title $pageTitle.p$ <head>
^pageHead.p^ <title>#{pageTitle p}
%body \^{pageHead p}
$maybe mmsg msg <body>
%p.message $msg$ $maybe msg <- mmsg
^pageBody.p^ <p .message>#{msg}
\^{pageBody p}
|] |]
-- | Gets called at the beginning of each request. Useful for logging. -- | Gets called at the beginning of each request. Useful for logging.
@ -306,8 +307,8 @@ defaultErrorHandler NotFound = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%h1 Not Found <h1>Not Found
%p $path'$ <p>#{path'}
|] |]
defaultErrorHandler (PermissionDenied msg) = defaultErrorHandler (PermissionDenied msg) =
applyLayout' "Permission Denied" applyLayout' "Permission Denied"
@ -316,8 +317,8 @@ defaultErrorHandler (PermissionDenied msg) =
#else #else
[$hamlet| [$hamlet|
#endif #endif
%h1 Permission denied <h1>Permission denied
%p $msg$ <p>#{msg}
|] |]
defaultErrorHandler (InvalidArgs ia) = defaultErrorHandler (InvalidArgs ia) =
applyLayout' "Invalid Arguments" applyLayout' "Invalid Arguments"
@ -326,10 +327,10 @@ defaultErrorHandler (InvalidArgs ia) =
#else #else
[$hamlet| [$hamlet|
#endif #endif
%h1 Invalid Arguments <h1>Invalid Arguments
%ul <ul>
$forall ia msg $forall msg <- ia
%li $msg$ <li>#{msg}
|] |]
defaultErrorHandler (InternalError e) = defaultErrorHandler (InternalError e) =
applyLayout' "Internal Server Error" applyLayout' "Internal Server Error"
@ -338,8 +339,8 @@ defaultErrorHandler (InternalError e) =
#else #else
[$hamlet| [$hamlet|
#endif #endif
%h1 Internal Server Error <h1>Internal Server Error
%p $e$ <p>#{e}
|] |]
defaultErrorHandler (BadMethod m) = defaultErrorHandler (BadMethod m) =
applyLayout' "Bad Method" applyLayout' "Bad Method"
@ -348,8 +349,8 @@ defaultErrorHandler (BadMethod m) =
#else #else
[$hamlet| [$hamlet|
#endif #endif
%h1 Method Not Supported <h1>Method Not Supported
%p Method "$m$" not supported <p>Method "#{m}" not supported
|] |]
-- | Return the same URL if the user is authorized to see it. -- | Return the same URL if the user is authorized to see it.
@ -418,21 +419,21 @@ widgetToPageContent (GWidget w) = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
$forall scripts s $forall s <- scripts
%script!src=^s^ <script src="^{s}">
$forall stylesheets s $forall s <- stylesheets
%link!rel=stylesheet!href=^s^ <link rel="stylesheet" href="^{s}">
$maybe style s $maybe s <- style
$maybe cssLoc s $maybe s <- cssLoc
%link!rel=stylesheet!href=$s$ <link rel="stylesheet" href="#{s}">
$nothing $nothing
%style ^celper.s^ <style>^{celper s}
$maybe jscript j $maybe j <- jscript
$maybe jsLoc s $maybe s <- jsLoc
%script!src=$s$ <script src="#{s}">
$nothing $nothing
%script ^jelper.j^ <script>^{jelper j}
^head'^ \^{head'}
|] |]
return $ PageContent title head'' body return $ PageContent title head'' body
@ -500,15 +501,16 @@ redirectToPost dest = hamletToRepHtml
#else #else
[$hamlet| [$hamlet|
#endif #endif
!!! \<!DOCTYPE html>
%html
%head <html>
%title Redirecting... <head>
%body!onload="document.getElementById('form').submit()" <title>Redirecting...
%form#form!method=post!action=@dest@ <body onload="document.getElementById('form').submit()">
%noscript <form id="form" method="post" action="@{dest}">
%p Javascript has been disabled; please click on the button below to be redirected. <noscript>
%input!type=submit!value=Continue <p>Javascript has been disabled; please click on the button below to be redirected.
<input type="submit" value="Continue">
|] >>= sendResponse |] >>= sendResponse
yesodVersion :: String yesodVersion :: String

View File

@ -70,8 +70,10 @@ langKey = "_LANG"
data Location url = Local url | Remote String data Location url = Local url | Remote String
deriving (Show, Eq) deriving (Show, Eq)
locationToHamlet :: Location url -> Hamlet url locationToHamlet :: Location url -> Hamlet url
locationToHamlet (Local url) = [HAMLET|@url@|] locationToHamlet (Local url) = [HAMLET|\@{url}
locationToHamlet (Remote s) = [HAMLET|$s$|] |]
locationToHamlet (Remote s) = [HAMLET|\#{s}
|]
newtype UniqueList x = UniqueList ([x] -> [x]) newtype UniqueList x = UniqueList ([x] -> [x])
instance Monoid (UniqueList x) where instance Monoid (UniqueList x) where

View File

@ -47,7 +47,7 @@ library
, monad-peel >= 0.1 && < 0.2 , monad-peel >= 0.1 && < 0.2
, enumerator >= 0.4 && < 0.5 , enumerator >= 0.4 && < 0.5
, cookie >= 0.0 && < 0.1 , cookie >= 0.0 && < 0.1
, blaze-html >= 0.3.2.1 && < 0.4 , blaze-html >= 0.4 && < 0.5
exposed-modules: Yesod.Content exposed-modules: Yesod.Content
Yesod.Core Yesod.Core
Yesod.Dispatch Yesod.Dispatch