Specify label and tooltip in field attributes
This commit is contained in:
parent
c71821a5c9
commit
6d05c9ec30
@ -64,6 +64,7 @@ import Data.Char (toUpper, isUpper)
|
|||||||
import Data.Int (Int64)
|
import Data.Int (Int64)
|
||||||
import qualified Data.ByteString.Lazy.UTF8 as U
|
import qualified Data.ByteString.Lazy.UTF8 as U
|
||||||
import Yesod.Widget
|
import Yesod.Widget
|
||||||
|
import Control.Arrow ((&&&))
|
||||||
|
|
||||||
data FormResult a = FormMissing
|
data FormResult a = FormMissing
|
||||||
| FormFailure [String]
|
| FormFailure [String]
|
||||||
@ -513,10 +514,18 @@ share2 f g a = do
|
|||||||
mkIsForm :: [EntityDef] -> Q [Dec]
|
mkIsForm :: [EntityDef] -> Q [Dec]
|
||||||
mkIsForm = mapM derive
|
mkIsForm = mapM derive
|
||||||
where
|
where
|
||||||
|
getLabel (x, _, z) = fromMaybe (toLabel x) $ getLabel' z
|
||||||
|
getLabel' [] = Nothing
|
||||||
|
getLabel' (('l':'a':'b':'e':'l':'=':x):_) = Just x
|
||||||
|
getLabel' (_:x) = getLabel' x
|
||||||
|
getTooltip (_, _, z) = fromMaybe "" $ getTooltip' z
|
||||||
|
getTooltip' (('t':'o':'o':'l':'t':'i':'p':'=':x):_) = Just x
|
||||||
|
getTooltip' (_:x) = getTooltip' x
|
||||||
|
getTooltip' [] = Nothing
|
||||||
derive :: EntityDef -> Q Dec
|
derive :: EntityDef -> Q Dec
|
||||||
derive t = do
|
derive t = do
|
||||||
let fst3 (x, _, _) = x
|
let fst3 (x, _, _) = x
|
||||||
let cols = map (toLabel . fst3) $ entityColumns t
|
let cols = map (getLabel &&& getTooltip) $ entityColumns t
|
||||||
ap <- [|(<*>)|]
|
ap <- [|(<*>)|]
|
||||||
just <- [|pure|]
|
just <- [|pure|]
|
||||||
nothing <- [|Nothing|]
|
nothing <- [|Nothing|]
|
||||||
@ -542,10 +551,11 @@ mkIsForm = mapM derive
|
|||||||
go ap just' string' mem mfx ftt a =
|
go ap just' string' mem mfx ftt a =
|
||||||
let x = foldl (ap' ap) just' $ map (go' string' mem) a
|
let x = foldl (ap' ap) just' $ map (go' string' mem) a
|
||||||
in mfx `AppE` ftt `AppE` x
|
in mfx `AppE` ftt `AppE` x
|
||||||
go' string' mempty' (label, ex) =
|
go' string' mempty' ((label, tooltip), ex) =
|
||||||
let label' = string' `AppE` LitE (StringL label)
|
let label' = string' `AppE` LitE (StringL label)
|
||||||
|
tooltip' = string' `AppE` LitE (StringL tooltip)
|
||||||
in VarE (mkName "toFormField") `AppE` label'
|
in VarE (mkName "toFormField") `AppE` label'
|
||||||
`AppE` mempty' `AppE` ex
|
`AppE` tooltip' `AppE` ex
|
||||||
ap' ap x y = InfixE (Just x) ap (Just y)
|
ap' ap x y = InfixE (Just x) ap (Just y)
|
||||||
|
|
||||||
toLabel :: String -> String
|
toLabel :: String -> String
|
||||||
|
|||||||
@ -335,7 +335,7 @@ getEmailVerifyR lid key = do
|
|||||||
redirect RedirectTemporary $ toMaster EmailPasswordR
|
redirect RedirectTemporary $ toMaster EmailPasswordR
|
||||||
_ -> applyLayout "Invalid verification key" mempty [$hamlet|
|
_ -> applyLayout "Invalid verification key" mempty [$hamlet|
|
||||||
%p I'm sorry, but that was an invalid verification key.
|
%p I'm sorry, but that was an invalid verification key.
|
||||||
|]
|
|]
|
||||||
|
|
||||||
getEmailLoginR :: Yesod master => GHandler Auth master RepHtml
|
getEmailLoginR :: Yesod master => GHandler Auth master RepHtml
|
||||||
getEmailLoginR = do
|
getEmailLoginR = do
|
||||||
|
|||||||
17
blog.hs
17
blog.hs
@ -8,7 +8,7 @@ import Data.Time (Day)
|
|||||||
type Html' = Html ()
|
type Html' = Html ()
|
||||||
share2 mkPersist mkIsForm [$persist|
|
share2 mkPersist mkIsForm [$persist|
|
||||||
Entry
|
Entry
|
||||||
title String
|
title String "label=Entry title" "tooltip=Make it something cool"
|
||||||
posted Day Desc
|
posted Day Desc
|
||||||
content Html'
|
content Html'
|
||||||
deriving
|
deriving
|
||||||
@ -44,8 +44,9 @@ instance Yesod Blog where
|
|||||||
!!!
|
!!!
|
||||||
%html
|
%html
|
||||||
%head
|
%head
|
||||||
%title $pageTitle.p$
|
%title $<pageTitle.p>$
|
||||||
^pageHead.p^
|
^pageHead.p^
|
||||||
|
%style textarea.html{width:500px;height:200px}div.tooltip{font-size:80%;font-style:italic;color:#666}
|
||||||
%body
|
%body
|
||||||
%p
|
%p
|
||||||
%a!href=@RootR@ Homepage
|
%a!href=@RootR@ Homepage
|
||||||
@ -56,9 +57,9 @@ instance Yesod Blog where
|
|||||||
$maybe mcreds c
|
$maybe mcreds c
|
||||||
Welcome $
|
Welcome $
|
||||||
$maybe credsDisplayName.c dn
|
$maybe credsDisplayName.c dn
|
||||||
$string.dn$
|
$dn$
|
||||||
$nothing
|
$nothing
|
||||||
$string.credsIdent.c$
|
$credsIdent.c$
|
||||||
\ $
|
\ $
|
||||||
%a!href=@AuthR.Logout@ Logout
|
%a!href=@AuthR.Logout@ Logout
|
||||||
$nothing
|
$nothing
|
||||||
@ -90,7 +91,7 @@ getRootR = do
|
|||||||
%ul
|
%ul
|
||||||
$forall entries entry
|
$forall entries entry
|
||||||
%li
|
%li
|
||||||
%a!href=@EntryR.fst.entry@ $string.entryTitle.snd.entry$
|
%a!href=@EntryR.fst.entry@ $entryTitle.snd.entry$
|
||||||
|]
|
|]
|
||||||
|
|
||||||
getEntryR :: EntryId -> Handler Blog RepHtml
|
getEntryR :: EntryId -> Handler Blog RepHtml
|
||||||
@ -99,9 +100,9 @@ getEntryR eid = do
|
|||||||
applyLayoutW $ do
|
applyLayoutW $ do
|
||||||
setTitle $ string $ entryTitle entry
|
setTitle $ string $ entryTitle entry
|
||||||
addBody [$hamlet|
|
addBody [$hamlet|
|
||||||
%h1 $string.entryTitle.entry$
|
%h1 $entryTitle.entry$
|
||||||
%h2 $string.show.entryPosted.entry$
|
%h2 $show.entryPosted.entry$
|
||||||
#content $entryContent.entry$
|
#content $<entryContent.entry>$
|
||||||
|]
|
|]
|
||||||
main = withSqlite "blog.db3" $ \conn -> do
|
main = withSqlite "blog.db3" $ \conn -> do
|
||||||
flip runSqlite conn $ initialize (undefined :: Entry)
|
flip runSqlite conn $ initialize (undefined :: Entry)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user