Finished deprecating old Widget functions
This commit is contained in:
parent
4cc468ca3b
commit
e62e4b8721
@ -31,8 +31,7 @@ import qualified Data.Text.Encoding as DTE
|
|||||||
import Yesod.Form
|
import Yesod.Form
|
||||||
import Yesod.Handler
|
import Yesod.Handler
|
||||||
import Yesod.Content
|
import Yesod.Content
|
||||||
import Yesod.Widget
|
import Yesod.Core (PathPiece, fromPathPiece, whamlet, defaultLayout, setTitleI, toPathPiece)
|
||||||
import Yesod.Core
|
|
||||||
import Control.Monad.IO.Class (liftIO)
|
import Control.Monad.IO.Class (liftIO)
|
||||||
import qualified Yesod.Auth.Message as Msg
|
import qualified Yesod.Auth.Message as Msg
|
||||||
|
|
||||||
@ -113,8 +112,7 @@ getRegisterR = do
|
|||||||
toMaster <- getRouteToMaster
|
toMaster <- getRouteToMaster
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitleI Msg.RegisterLong
|
setTitleI Msg.RegisterLong
|
||||||
addWidget
|
[whamlet|
|
||||||
[whamlet|
|
|
||||||
<p>_{Msg.EnterEmail}
|
<p>_{Msg.EnterEmail}
|
||||||
<form method="post" action="@{toMaster registerR}">
|
<form method="post" action="@{toMaster registerR}">
|
||||||
<label for="email">_{Msg.Email}
|
<label for="email">_{Msg.Email}
|
||||||
@ -144,8 +142,7 @@ postRegisterR = do
|
|||||||
sendVerifyEmail email verKey verUrl
|
sendVerifyEmail email verKey verUrl
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitleI Msg.ConfirmationEmailSentTitle
|
setTitleI Msg.ConfirmationEmailSentTitle
|
||||||
addWidget
|
[whamlet| <p>_{Msg.ConfirmationEmailSent email} |]
|
||||||
[whamlet| <p>_{Msg.ConfirmationEmailSent email} |]
|
|
||||||
|
|
||||||
getVerifyR :: YesodAuthEmail m
|
getVerifyR :: YesodAuthEmail m
|
||||||
=> AuthEmailId m -> Text -> GHandler Auth m RepHtml
|
=> AuthEmailId m -> Text -> GHandler Auth m RepHtml
|
||||||
@ -165,8 +162,7 @@ getVerifyR lid key = do
|
|||||||
_ -> return ()
|
_ -> return ()
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitleI Msg.InvalidKey
|
setTitleI Msg.InvalidKey
|
||||||
addWidget
|
[whamlet| <p>_{Msg.InvalidKey} |]
|
||||||
[whamlet| <p>_{Msg.InvalidKey} |]
|
|
||||||
|
|
||||||
postLoginR :: YesodAuthEmail master => GHandler Auth master ()
|
postLoginR :: YesodAuthEmail master => GHandler Auth master ()
|
||||||
postLoginR = do
|
postLoginR = do
|
||||||
@ -204,8 +200,7 @@ getPasswordR = do
|
|||||||
redirect $ toMaster LoginR
|
redirect $ toMaster LoginR
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitleI Msg.SetPassTitle
|
setTitleI Msg.SetPassTitle
|
||||||
addWidget
|
[whamlet|
|
||||||
[whamlet|
|
|
||||||
<h3>_{Msg.SetPass}
|
<h3>_{Msg.SetPass}
|
||||||
<form method="post" action="@{toMaster setpassR}">
|
<form method="post" action="@{toMaster setpassR}">
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import Yesod.Auth
|
|||||||
import qualified Web.Authenticate.OpenId as OpenId
|
import qualified Web.Authenticate.OpenId as OpenId
|
||||||
|
|
||||||
import Yesod.Handler
|
import Yesod.Handler
|
||||||
import Yesod.Widget
|
import Yesod.Widget (whamlet)
|
||||||
import Yesod.Request
|
import Yesod.Request
|
||||||
import Text.Blaze (toHtml)
|
import Text.Blaze (toHtml)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
|||||||
@ -76,7 +76,7 @@ import Yesod.Persist
|
|||||||
import Yesod.Handler
|
import Yesod.Handler
|
||||||
import Yesod.Form
|
import Yesod.Form
|
||||||
import Yesod.Auth
|
import Yesod.Auth
|
||||||
import Yesod.Widget (addHamlet)
|
import Yesod.Widget (toWidget)
|
||||||
import Text.Hamlet (hamlet, shamlet)
|
import Text.Hamlet (hamlet, shamlet)
|
||||||
|
|
||||||
import Control.Applicative ((<$>), (<*>))
|
import Control.Applicative ((<$>), (<*>))
|
||||||
@ -221,8 +221,7 @@ authHashDB :: ( YesodAuth m, YesodPersist m
|
|||||||
, PersistStore b (GHandler Auth m)
|
, PersistStore b (GHandler Auth m)
|
||||||
, PersistUnique b (GHandler Auth m))
|
, PersistUnique b (GHandler Auth m))
|
||||||
=> (Text -> Maybe (Unique user b)) -> AuthPlugin m
|
=> (Text -> Maybe (Unique user b)) -> AuthPlugin m
|
||||||
authHashDB uniq = AuthPlugin "hashdb" dispatch $ \tm -> addHamlet
|
authHashDB uniq = AuthPlugin "hashdb" dispatch $ \tm -> toWidget [hamlet|
|
||||||
[hamlet|
|
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<h1>Login
|
<h1>Login
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import qualified Web.Authenticate.OpenId as OpenId
|
|||||||
|
|
||||||
import Yesod.Form
|
import Yesod.Form
|
||||||
import Yesod.Handler
|
import Yesod.Handler
|
||||||
import Yesod.Widget
|
import Yesod.Widget (toWidget, whamlet)
|
||||||
import Yesod.Request
|
import Yesod.Request
|
||||||
import Text.Cassius (cassius)
|
import Text.Cassius (cassius)
|
||||||
import Text.Blaze (toHtml)
|
import Text.Blaze (toHtml)
|
||||||
@ -34,8 +34,7 @@ authOpenIdExtended extensionFields =
|
|||||||
name = "openid_identifier"
|
name = "openid_identifier"
|
||||||
login tm = do
|
login tm = do
|
||||||
ident <- lift newIdent
|
ident <- lift newIdent
|
||||||
addCassius
|
toWidget [cassius|##{ident}
|
||||||
[cassius|##{ident}
|
|
||||||
background: #fff url(http://www.myopenid.com/static/openid-icon-small.gif) no-repeat scroll 0pt 50%;
|
background: #fff url(http://www.myopenid.com/static/openid-icon-small.gif) no-repeat scroll 0pt 50%;
|
||||||
padding-left: 18px;
|
padding-left: 18px;
|
||||||
|]
|
|]
|
||||||
|
|||||||
@ -25,8 +25,7 @@ authRpxnow app apiKey =
|
|||||||
where
|
where
|
||||||
login tm = do
|
login tm = do
|
||||||
let url = {- FIXME urlEncode $ -} tm $ PluginR "rpxnow" []
|
let url = {- FIXME urlEncode $ -} tm $ PluginR "rpxnow" []
|
||||||
addHamlet
|
toWidget [hamlet|
|
||||||
[hamlet|
|
|
||||||
<iframe src="http://#{app}.rpxnow.com/openid/embed?token_url=@{url}" scrolling="no" frameBorder="no" allowtransparency="true" style="width:400px;height:240px">
|
<iframe src="http://#{app}.rpxnow.com/openid/embed?token_url=@{url}" scrolling="no" frameBorder="no" allowtransparency="true" style="width:400px;height:240px">
|
||||||
|]
|
|]
|
||||||
dispatch _ [] = do
|
dispatch _ [] = do
|
||||||
|
|||||||
@ -485,7 +485,7 @@ applyLayout' :: Yesod master
|
|||||||
-> GHandler sub master ChooseRep
|
-> GHandler sub master ChooseRep
|
||||||
applyLayout' title body = fmap chooseRep $ defaultLayout $ do
|
applyLayout' title body = fmap chooseRep $ defaultLayout $ do
|
||||||
setTitle title
|
setTitle title
|
||||||
addHamlet body
|
toWidget body
|
||||||
|
|
||||||
-- | The default error handler for 'errorHandler'.
|
-- | The default error handler for 'errorHandler'.
|
||||||
defaultErrorHandler :: Yesod y => ErrorResponse -> GHandler sub y ChooseRep
|
defaultErrorHandler :: Yesod y => ErrorResponse -> GHandler sub y ChooseRep
|
||||||
|
|||||||
@ -114,37 +114,37 @@ class ToWidget sub master a where
|
|||||||
type RY master = Route master -> [(Text, Text)] -> Text
|
type RY master = Route master -> [(Text, Text)] -> Text
|
||||||
|
|
||||||
instance render ~ RY master => ToWidget sub master (render -> Html) where
|
instance render ~ RY master => ToWidget sub master (render -> Html) where
|
||||||
toWidget = addHamlet
|
toWidget x = tell $ GWData (Body x) mempty mempty mempty mempty mempty mempty
|
||||||
instance render ~ RY master => ToWidget sub master (render -> Css) where
|
instance render ~ RY master => ToWidget sub master (render -> Css) where
|
||||||
toWidget = addCassius
|
toWidget x = tell $ GWData mempty mempty mempty mempty (Map.singleton Nothing $ \r -> fromLazyText $ renderCss $ x r) mempty mempty
|
||||||
instance render ~ RY master => ToWidget sub master (render -> Javascript) where
|
instance render ~ RY master => ToWidget sub master (render -> Javascript) where
|
||||||
toWidget = addJulius
|
toWidget x = tell $ GWData mempty mempty mempty mempty mempty (Just x) mempty
|
||||||
instance ToWidget sub master (GWidget sub master ()) where
|
instance ToWidget sub master (GWidget sub master ()) where
|
||||||
toWidget = id
|
toWidget = id
|
||||||
instance ToWidget sub master Html where
|
instance ToWidget sub master Html where
|
||||||
toWidget = addHtml
|
toWidget = toWidget . const
|
||||||
|
|
||||||
class ToWidgetBody sub master a where
|
class ToWidgetBody sub master a where
|
||||||
toWidgetBody :: a -> GWidget sub master ()
|
toWidgetBody :: a -> GWidget sub master ()
|
||||||
|
|
||||||
instance render ~ RY master => ToWidgetBody sub master (render -> Html) where
|
instance render ~ RY master => ToWidgetBody sub master (render -> Html) where
|
||||||
toWidgetBody = addHamlet
|
toWidgetBody = toWidget
|
||||||
instance render ~ RY master => ToWidgetBody sub master (render -> Javascript) where
|
instance render ~ RY master => ToWidgetBody sub master (render -> Javascript) where
|
||||||
toWidgetBody = addJuliusBody
|
toWidgetBody j = toWidget $ \r -> H.script $ preEscapedLazyText $ renderJavascriptUrl r j
|
||||||
instance ToWidgetBody sub master Html where
|
instance ToWidgetBody sub master Html where
|
||||||
toWidgetBody = addHtml
|
toWidgetBody = toWidget
|
||||||
|
|
||||||
class ToWidgetHead sub master a where
|
class ToWidgetHead sub master a where
|
||||||
toWidgetHead :: a -> GWidget sub master ()
|
toWidgetHead :: a -> GWidget sub master ()
|
||||||
|
|
||||||
instance render ~ RY master => ToWidgetHead sub master (render -> Html) where
|
instance render ~ RY master => ToWidgetHead sub master (render -> Html) where
|
||||||
toWidgetHead = addHamletHead
|
toWidgetHead = tell . GWData mempty mempty mempty mempty mempty mempty . Head
|
||||||
instance render ~ RY master => ToWidgetHead sub master (render -> Css) where
|
instance render ~ RY master => ToWidgetHead sub master (render -> Css) where
|
||||||
toWidgetHead = addCassius
|
toWidgetHead = toWidget
|
||||||
instance render ~ RY master => ToWidgetHead sub master (render -> Javascript) where
|
instance render ~ RY master => ToWidgetHead sub master (render -> Javascript) where
|
||||||
toWidgetHead = addJulius
|
toWidgetHead = toWidget
|
||||||
instance ToWidgetHead sub master Html where
|
instance ToWidgetHead sub master Html where
|
||||||
toWidgetHead = addHtmlHead
|
toWidgetHead = toWidgetHead . const
|
||||||
|
|
||||||
-- | Set the page title. Calling 'setTitle' multiple times overrides previously
|
-- | Set the page title. Calling 'setTitle' multiple times overrides previously
|
||||||
-- set values.
|
-- set values.
|
||||||
@ -164,19 +164,19 @@ setTitleI msg = do
|
|||||||
|
|
||||||
-- | Add a 'Hamlet' to the head tag.
|
-- | Add a 'Hamlet' to the head tag.
|
||||||
addHamletHead :: HtmlUrl (Route master) -> GWidget sub master ()
|
addHamletHead :: HtmlUrl (Route master) -> GWidget sub master ()
|
||||||
addHamletHead = tell . GWData mempty mempty mempty mempty mempty mempty . Head
|
addHamletHead = toWidgetHead
|
||||||
|
|
||||||
-- | Add a 'Html' to the head tag.
|
-- | Add a 'Html' to the head tag.
|
||||||
addHtmlHead :: Html -> GWidget sub master ()
|
addHtmlHead :: Html -> GWidget sub master ()
|
||||||
addHtmlHead = addHamletHead . const
|
addHtmlHead = toWidgetHead . const
|
||||||
|
|
||||||
-- | Add a 'Hamlet' to the body tag.
|
-- | Add a 'Hamlet' to the body tag.
|
||||||
addHamlet :: HtmlUrl (Route master) -> GWidget sub master ()
|
addHamlet :: HtmlUrl (Route master) -> GWidget sub master ()
|
||||||
addHamlet x = tell $ GWData (Body x) mempty mempty mempty mempty mempty mempty
|
addHamlet = toWidget
|
||||||
|
|
||||||
-- | Add a 'Html' to the body tag.
|
-- | Add a 'Html' to the body tag.
|
||||||
addHtml :: Html -> GWidget sub master ()
|
addHtml :: Html -> GWidget sub master ()
|
||||||
addHtml = addHamlet . const
|
addHtml = toWidget
|
||||||
|
|
||||||
-- | Add another widget. This is defined as 'id', by can help with types, and
|
-- | Add another widget. This is defined as 'id', by can help with types, and
|
||||||
-- makes widget blocks look more consistent.
|
-- makes widget blocks look more consistent.
|
||||||
@ -185,11 +185,11 @@ addWidget = id
|
|||||||
|
|
||||||
-- | Add some raw CSS to the style tag. Applies to all media types.
|
-- | Add some raw CSS to the style tag. Applies to all media types.
|
||||||
addCassius :: CssUrl (Route master) -> GWidget sub master ()
|
addCassius :: CssUrl (Route master) -> GWidget sub master ()
|
||||||
addCassius x = tell $ GWData mempty mempty mempty mempty (Map.singleton Nothing $ \r -> fromLazyText $ renderCss $ x r) mempty mempty
|
addCassius = toWidget
|
||||||
|
|
||||||
-- | Identical to 'addCassius'.
|
-- | Identical to 'addCassius'.
|
||||||
addLucius :: CssUrl (Route master) -> GWidget sub master ()
|
addLucius :: CssUrl (Route master) -> GWidget sub master ()
|
||||||
addLucius = addCassius
|
addLucius = toWidget
|
||||||
|
|
||||||
-- | Add some raw CSS to the style tag, for a specific media type.
|
-- | Add some raw CSS to the style tag, for a specific media type.
|
||||||
addCassiusMedia :: Text -> CssUrl (Route master) -> GWidget sub master ()
|
addCassiusMedia :: Text -> CssUrl (Route master) -> GWidget sub master ()
|
||||||
@ -239,12 +239,12 @@ addScriptRemoteAttrs x y = tell $ GWData mempty mempty (toUnique $ Script (Remot
|
|||||||
|
|
||||||
-- | Include raw Javascript in the page's script tag.
|
-- | Include raw Javascript in the page's script tag.
|
||||||
addJulius :: JavascriptUrl (Route master) -> GWidget sub master ()
|
addJulius :: JavascriptUrl (Route master) -> GWidget sub master ()
|
||||||
addJulius x = tell $ GWData mempty mempty mempty mempty mempty (Just x) mempty
|
addJulius = toWidget
|
||||||
|
|
||||||
-- | Add a new script tag to the body with the contents of this 'Julius'
|
-- | Add a new script tag to the body with the contents of this 'Julius'
|
||||||
-- template.
|
-- template.
|
||||||
addJuliusBody :: JavascriptUrl (Route master) -> GWidget sub master ()
|
addJuliusBody :: JavascriptUrl (Route master) -> GWidget sub master ()
|
||||||
addJuliusBody j = addHamlet $ \r -> H.script $ preEscapedLazyText $ renderJavascriptUrl r j
|
addJuliusBody = toWidgetBody
|
||||||
|
|
||||||
-- | Content for a web page. By providing this datatype, we can easily create
|
-- | Content for a web page. By providing this datatype, we can easily create
|
||||||
-- generic site templates, which would have the type signature:
|
-- generic site templates, which would have the type signature:
|
||||||
@ -264,7 +264,7 @@ whamletFile = NP.hamletFileWithSettings rules NP.defaultHamletSettings
|
|||||||
|
|
||||||
rules :: Q NP.HamletRules
|
rules :: Q NP.HamletRules
|
||||||
rules = do
|
rules = do
|
||||||
ah <- [|addHtml|]
|
ah <- [|toWidget|]
|
||||||
let helper qg f = do
|
let helper qg f = do
|
||||||
x <- newName "urender"
|
x <- newName "urender"
|
||||||
e <- f $ VarE x
|
e <- f $ VarE x
|
||||||
|
|||||||
@ -63,7 +63,7 @@ widgetFileNoReload x = do
|
|||||||
let c = whenExists x "cassius" cassiusFile
|
let c = whenExists x "cassius" cassiusFile
|
||||||
let j = whenExists x "julius" juliusFile
|
let j = whenExists x "julius" juliusFile
|
||||||
let l = whenExists x "lucius" luciusFile
|
let l = whenExists x "lucius" luciusFile
|
||||||
[|$h >> addCassius $c >> addJulius $j >> addLucius $l|]
|
[|$h >> toWidget $c >> toWidget $j >> toWidget $l|]
|
||||||
|
|
||||||
widgetFileReload :: FilePath -> Q Exp
|
widgetFileReload :: FilePath -> Q Exp
|
||||||
widgetFileReload x = do
|
widgetFileReload x = do
|
||||||
@ -71,7 +71,7 @@ widgetFileReload x = do
|
|||||||
let c = whenExists x "cassius" cassiusFileReload
|
let c = whenExists x "cassius" cassiusFileReload
|
||||||
let j = whenExists x "julius" juliusFileReload
|
let j = whenExists x "julius" juliusFileReload
|
||||||
let l = whenExists x "lucius" luciusFileReload
|
let l = whenExists x "lucius" luciusFileReload
|
||||||
[|$h >> addCassius $c >> addJulius $j >> addLucius $l|]
|
[|$h >> toWidget $c >> toWidget $j >> toWidget $l|]
|
||||||
|
|
||||||
widgetFileJsCss :: (String, FilePath -> Q Exp) -- ^ Css file extenstion and loading function. example: ("cassius", cassiusFileReload)
|
widgetFileJsCss :: (String, FilePath -> Q Exp) -- ^ Css file extenstion and loading function. example: ("cassius", cassiusFileReload)
|
||||||
-> (String, FilePath -> Q Exp) -- ^ Css file extenstion and loading function. example: ("julius", juliusFileReload)
|
-> (String, FilePath -> Q Exp) -- ^ Css file extenstion and loading function. example: ("julius", juliusFileReload)
|
||||||
@ -80,7 +80,7 @@ widgetFileJsCss (jsExt, jsLoad) (csExt, csLoad) x = do
|
|||||||
let h = whenExists x "hamlet" whamletFile
|
let h = whenExists x "hamlet" whamletFile
|
||||||
let c = whenExists x csExt csLoad
|
let c = whenExists x csExt csLoad
|
||||||
let j = whenExists x jsExt jsLoad
|
let j = whenExists x jsExt jsLoad
|
||||||
[|$h >> addCassius $c >> addJulius $j|]
|
[|$h >> toWidget $c >> toWidget $j|]
|
||||||
|
|
||||||
whenExists :: String -> String -> (FilePath -> Q Exp) -> Q Exp
|
whenExists :: String -> String -> (FilePath -> Q Exp) -> Q Exp
|
||||||
whenExists = warnUnlessExists False
|
whenExists = warnUnlessExists False
|
||||||
|
|||||||
@ -66,6 +66,6 @@ entryTemplate arg = [xhamlet|
|
|||||||
atomLink :: Route m
|
atomLink :: Route m
|
||||||
-> Text -- ^ title
|
-> Text -- ^ title
|
||||||
-> GWidget s m ()
|
-> GWidget s m ()
|
||||||
atomLink r title = addHamletHead [hamlet|
|
atomLink r title = toWidgetHead [hamlet|
|
||||||
<link href=@{r} type=#{S8.unpack typeAtom} rel="alternate" title=#{title}
|
<link href=@{r} type=#{S8.unpack typeAtom} rel="alternate" title=#{title}
|
||||||
|]
|
|]
|
||||||
|
|||||||
@ -63,6 +63,6 @@ entryTemplate arg = [xhamlet|
|
|||||||
rssLink :: Route m
|
rssLink :: Route m
|
||||||
-> Text -- ^ title
|
-> Text -- ^ title
|
||||||
-> GWidget s m ()
|
-> GWidget s m ()
|
||||||
rssLink r title = addHamletHead [hamlet|
|
rssLink r title = toWidgetHead [hamlet|
|
||||||
<link href=@{r} type=#{S8.unpack typeRss} rel="alternate" title=#{title}
|
<link href=@{r} type=#{S8.unpack typeRss} rel="alternate" title=#{title}
|
||||||
|]
|
|]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user