Hamlet html-angle-brackets change

This commit is contained in:
Michael Snoyman 2010-07-04 01:28:15 +03:00
parent fcfd1559ca
commit 2289400d7a
7 changed files with 41 additions and 47 deletions

View File

@ -132,12 +132,12 @@ fieldsToTable = mapM_ go
wrapWidget (fiInput fi) $ \w -> [$hamlet| wrapWidget (fiInput fi) $ \w -> [$hamlet|
%tr %tr
%td %td
%label!for=$string.fiIdent.fi$ $fiLabel.fi$ %label!for=$fiIdent.fi$ $<fiLabel.fi>$
.tooltip $fiTooltip.fi$ .tooltip $<fiTooltip.fi>$
%td %td
^w^ ^w^
$maybe fiErrors.fi err $maybe fiErrors.fi err
%td.errors $err$ %td.errors $<err>$
|] |]
class IsForm a where class IsForm a where
@ -213,7 +213,7 @@ stringField = FieldProfile
{ fpParse = Right { fpParse = Right
, fpRender = id , fpRender = id
, fpHamlet = \name val isReq -> [$hamlet| , fpHamlet = \name val isReq -> [$hamlet|
%input#$name$!name=$name$!type=text!:isReq:required!value=$val$ %input#$<name>$!name=$<name>$!type=text!:isReq:required!value=$<val>$
|] |]
, fpWidget = \_name -> return () , fpWidget = \_name -> return ()
} }
@ -227,7 +227,7 @@ intField = FieldProfile
{ fpParse = maybe (Left "Invalid integer") Right . readMayI { fpParse = maybe (Left "Invalid integer") Right . readMayI
, fpRender = showI , fpRender = showI
, fpHamlet = \name val isReq -> [$hamlet| , fpHamlet = \name val isReq -> [$hamlet|
%input#$name$!name=$name$!type=number!:isReq:required!value=$val$ %input#$<name>$!name=$<name>$!type=number!:isReq:required!value=$<val>$
|] |]
, fpWidget = \_name -> return () , fpWidget = \_name -> return ()
} }
@ -250,7 +250,7 @@ doubleField = FieldProfile
{ fpParse = maybe (Left "Invalid number") Right . readMay { fpParse = maybe (Left "Invalid number") Right . readMay
, fpRender = show , fpRender = show
, fpHamlet = \name val isReq -> [$hamlet| , fpHamlet = \name val isReq -> [$hamlet|
%input#$name$!name=$name$!type=number!:isReq:required!value=$val$ %input#$<name>$!name=$<name>$!type=number!:isReq:required!value=$<val>$
|] |]
, fpWidget = \_name -> return () , fpWidget = \_name -> return ()
} }
@ -265,13 +265,13 @@ dayField = FieldProfile
. readMay . readMay
, fpRender = show , fpRender = show
, fpHamlet = \name val isReq -> [$hamlet| , fpHamlet = \name val isReq -> [$hamlet|
%input#$name$!name=$name$!type=date!:isReq:required!value=$val$ %input#$<name>$!name=$<name>$!type=date!:isReq:required!value=$<val>$
|] |]
, fpWidget = \name -> do , fpWidget = \name -> do
addScriptRemote "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" addScriptRemote "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
addScriptRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" addScriptRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"
addStylesheetRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/cupertino/jquery-ui.css" addStylesheetRemote "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/cupertino/jquery-ui.css"
addHead [$hamlet|%script $$(function(){$$("#$string.name$").datepicker({dateFormat:'yy-mm-dd'})})|] addHead [$hamlet|%script $$(function(){$$("#$name$").datepicker({dateFormat:'yy-mm-dd'})})|]
} }
instance IsFormField Day where instance IsFormField Day where
toFormField = requiredField dayField toFormField = requiredField dayField
@ -292,7 +292,7 @@ boolField label tooltip orig = GForm $ \env _ -> do
, fiTooltip = tooltip , fiTooltip = tooltip
, fiIdent = name , fiIdent = name
, fiInput = addBody [$hamlet| , fiInput = addBody [$hamlet|
%input#$string.name$!type=checkbox!name=$string.name$!:val:checked %input#$name$!type=checkbox!name=$name$!:val:checked
|] |]
, fiErrors = case res of , fiErrors = case res of
FormFailure [x] -> Just $ string x FormFailure [x] -> Just $ string x
@ -307,11 +307,11 @@ htmlField = FieldProfile
{ fpParse = Right . preEscapedString { fpParse = Right . preEscapedString
, fpRender = U.toString . renderHtml , fpRender = U.toString . renderHtml
, fpHamlet = \name val _isReq -> [$hamlet| , fpHamlet = \name val _isReq -> [$hamlet|
%textarea.html#$name$!name=$name$ $val$ %textarea.html#$<name>$!name=$<name>$ $<val>$
|] |]
, fpWidget = \name -> do , fpWidget = \name -> do
addScriptRemote "http://js.nicedit.com/nicEdit-latest.js" addScriptRemote "http://js.nicedit.com/nicEdit-latest.js"
addHead [$hamlet|%script bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("$string.name$")})|] addHead [$hamlet|%script bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("$name$")})|]
} }
instance IsFormField (Html ()) where instance IsFormField (Html ()) where
toFormField = requiredField htmlField toFormField = requiredField htmlField
@ -344,10 +344,10 @@ selectField pairs label tooltip initial = GForm $ \env _ -> do
FormSuccess y -> x == y FormSuccess y -> x == y
_ -> Just x == initial _ -> Just x == initial
let input = [$hamlet| let input = [$hamlet|
%select#$string.i$!name=$string.i$ %select#$i$!name=$i$
%option!value=none %option!value=none
$forall pairs' pair $forall pairs' pair
%option!value=$string.show.fst.pair$!:isSelected.fst.snd.pair:selected $string.snd.snd.pair$ %option!value=$show.fst.pair$!:isSelected.fst.snd.pair:selected $snd.snd.pair$
|] |]
let fi = FieldInfo let fi = FieldInfo
{ fiLabel = label { fiLabel = label
@ -381,10 +381,10 @@ maybeSelectField pairs label tooltip initial = GForm $ \env _ -> do
FormSuccess y -> Just x == y FormSuccess y -> Just x == y
_ -> Just x == initial _ -> Just x == initial
let input = [$hamlet| let input = [$hamlet|
%select#$string.i$!name=$string.i$ %select#$i$!name=$i$
%option!value=none %option!value=none
$forall pairs' pair $forall pairs' pair
%option!value=$string.show.fst.pair$!:isSelected.fst.snd.pair:selected $string.snd.snd.pair$ %option!value=$show.fst.pair$!:isSelected.fst.snd.pair:selected $snd.snd.pair$
|] |]
let fi = FieldInfo let fi = FieldInfo
{ fiLabel = label { fiLabel = label

View File

@ -47,17 +47,14 @@ data AtomFeedEntry url = AtomFeedEntry
, atomEntryContent :: Html () , atomEntryContent :: Html ()
} }
xmlns :: Html ()
xmlns = preEscapedString "http://www.w3.org/2005/Atom"
template :: AtomFeed url -> Hamlet url template :: AtomFeed url -> Hamlet url
template arg = [$xhamlet| template arg = [$xhamlet|
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
%feed!xmlns=$xmlns$ %feed!xmlns="http://www.w3.org/2005/Atom"
%title $string.atomTitle.arg$ %title $atomTitle.arg$
%link!rel=self!href=@atomLinkSelf.arg@ %link!rel=self!href=@atomLinkSelf.arg@
%link!href=@atomLinkHome.arg@ %link!href=@atomLinkHome.arg@
%updated $string.formatW3.atomUpdated.arg$ %updated $formatW3.atomUpdated.arg$
%id @atomLinkHome.arg@ %id @atomLinkHome.arg@
$forall atomEntries.arg entry $forall atomEntries.arg entry
^entryTemplate.entry^ ^entryTemplate.entry^
@ -68,7 +65,7 @@ entryTemplate arg = [$xhamlet|
%entry %entry
%id @atomEntryLink.arg@ %id @atomEntryLink.arg@
%link!href=@atomEntryLink.arg@ %link!href=@atomEntryLink.arg@
%updated $string.formatW3.atomEntryUpdated.arg$ %updated $formatW3.atomEntryUpdated.arg$
%title $string.atomEntryTitle.arg$ %title $atomEntryTitle.arg$
%content!type=html $cdata.atomEntryContent.arg$ %content!type=html $<cdata.atomEntryContent.arg>$
|] |]

View File

@ -172,7 +172,7 @@ getOpenIdR = do
message <- getMessage message <- getMessage
applyLayout "Log in via OpenID" mempty [$hamlet| applyLayout "Log in via OpenID" mempty [$hamlet|
$maybe message msg $maybe message msg
%p.message $msg$ %p.message $<msg>$
%form!method=get!action=@rtom.OpenIdForward@ %form!method=get!action=@rtom.OpenIdForward@
%label!for=openid OpenID: $ %label!for=openid OpenID: $
%input#openid!type=text!name=openid %input#openid!type=text!name=openid
@ -257,7 +257,7 @@ getCheck = do
$if isNothing.creds $if isNothing.creds
%p Not logged in %p Not logged in
$maybe creds c $maybe creds c
%p Logged in as $string.credsIdent.c$ %p Logged in as $credsIdent.c$
|] |]
json creds = json creds =
jsonMap jsonMap
@ -317,7 +317,7 @@ postEmailRegisterR = do
let verUrl = render $ tm $ EmailVerifyR lid verKey let verUrl = render $ tm $ EmailVerifyR lid verKey
liftIO $ sendVerifyEmail ae email verKey verUrl liftIO $ sendVerifyEmail ae email verKey verUrl
applyLayout "Confirmation e-mail sent" mempty [$hamlet| applyLayout "Confirmation e-mail sent" mempty [$hamlet|
%p A confirmation e-mail has been sent to $string.email$. %p A confirmation e-mail has been sent to $email$.
|] |]
getEmailVerifyR :: YesodAuth master getEmailVerifyR :: YesodAuth master
@ -344,7 +344,7 @@ getEmailLoginR = do
msg <- getMessage msg <- getMessage
applyLayout "Login" mempty [$hamlet| applyLayout "Login" mempty [$hamlet|
$maybe msg ms $maybe msg ms
%p.message $ms$ %p.message $<ms>$
%p Please log in to your account. %p Please log in to your account.
%p %p
%a!href=@toMaster.EmailRegisterR@ I don't have an account %a!href=@toMaster.EmailRegisterR@ I don't have an account
@ -399,7 +399,7 @@ getEmailPasswordR = do
msg <- getMessage msg <- getMessage
applyLayout "Set password" mempty [$hamlet| applyLayout "Set password" mempty [$hamlet|
$maybe msg ms $maybe msg ms
%p.message $ms$ %p.message $<ms>$
%h3 Set a new password %h3 Set a new password
%form!method=post!action=@toMaster.EmailPasswordR@ %form!method=post!action=@toMaster.EmailPasswordR@
%table %table

View File

@ -52,7 +52,7 @@ getCrudListR = do
$forall items item $forall items item
%li %li
%a!href=@toMaster.CrudEditR.toSinglePiece.fst.item@ %a!href=@toMaster.CrudEditR.toSinglePiece.fst.item@
$string.itemTitle.snd.item$ $itemTitle.snd.item$
%p %p
%a!href=@toMaster.CrudAddR@ Add new item %a!href=@toMaster.CrudAddR@ Add new item
|] |]
@ -103,7 +103,7 @@ getCrudDeleteR s = do
applyLayout "Confirm delete" mempty [$hamlet| applyLayout "Confirm delete" mempty [$hamlet|
%form!method=post!action=@toMaster.CrudDeleteR.s@ %form!method=post!action=@toMaster.CrudDeleteR.s@
%h1 Really delete? %h1 Really delete?
%p Do you really want to delete $string.itemTitle.item$? %p Do you really want to delete $itemTitle.item$?
%p %p
%input!type=submit!value=Yes %input!type=submit!value=Yes
\ $ \ $
@ -147,8 +147,8 @@ crudHelper title me isPost = do
wrapForm toMaster enctype form = [$hamlet| wrapForm toMaster enctype form = [$hamlet|
%p %p
%a!href=@toMaster.CrudListR@ Return to list %a!href=@toMaster.CrudListR@ Return to list
%h1 $string.title$ %h1 $title$
%form!method=post!enctype=$string.show.enctype$ %form!method=post!enctype=$show.enctype$
%table %table
^form^ ^form^
%tr %tr

View File

@ -50,18 +50,15 @@ data SitemapUrl url = SitemapUrl
, priority :: Double , priority :: Double
} }
sitemapNS :: Html ()
sitemapNS = string "http://www.sitemaps.org/schemas/sitemap/0.9"
template :: [SitemapUrl url] -> Hamlet url template :: [SitemapUrl url] -> Hamlet url
template urls = [$hamlet| template urls = [$hamlet|
%urlset!xmlns=$sitemapNS$ %urlset!xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
$forall urls url $forall urls url
%url %url
%loc @sitemapLoc.url@ %loc @sitemapLoc.url@
%lastmod $string.formatW3.sitemapLastMod.url$ %lastmod $formatW3.sitemapLastMod.url$
%changefreq $string.showFreq.sitemapChangeFreq.url$ %changefreq $showFreq.sitemapChangeFreq.url$
%priority $string.show.priority.url$ %priority $show.priority.url$
|] |]
sitemap :: [SitemapUrl (Routes master)] -> GHandler sub master RepXml sitemap :: [SitemapUrl (Routes master)] -> GHandler sub master RepXml

View File

@ -42,7 +42,7 @@ 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|$string.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

@ -83,7 +83,7 @@ class Eq (Routes a) => Yesod a where
!!! !!!
%html %html
%head %head
%title $pageTitle.p$ %title $<pageTitle.p>$
^pageHead.p^ ^pageHead.p^
%body %body
^pageBody.p^ ^pageBody.p^
@ -176,31 +176,31 @@ defaultErrorHandler NotFound = do
r <- waiRequest r <- waiRequest
applyLayout' "Not Found" $ [$hamlet| applyLayout' "Not Found" $ [$hamlet|
%h1 Not Found %h1 Not Found
%p $string.toString.pathInfo.r$ %p $toString.pathInfo.r$
|] |]
where where
pathInfo = W.pathInfo pathInfo = W.pathInfo
defaultErrorHandler (PermissionDenied msg) = defaultErrorHandler (PermissionDenied msg) =
applyLayout' "Permission Denied" $ [$hamlet| applyLayout' "Permission Denied" $ [$hamlet|
%h1 Permission denied %h1 Permission denied
%p $string.msg$ %p $msg$
|] |]
defaultErrorHandler (InvalidArgs ia) = defaultErrorHandler (InvalidArgs ia) =
applyLayout' "Invalid Arguments" $ [$hamlet| applyLayout' "Invalid Arguments" $ [$hamlet|
%h1 Invalid Arguments %h1 Invalid Arguments
%ul %ul
$forall ia msg $forall ia msg
%li $string.msg$ %li $msg$
|] |]
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 $string.e$ %p $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 "$string.m$" not supported %p Method "$m$" not supported
|] |]
class YesodPersist y where class YesodPersist y where