Beginning of old widget function deprecation, not complete

This commit is contained in:
Michael Snoyman 2012-03-13 06:36:27 +02:00
parent 0b9ced7f6c
commit 4cc468ca3b
7 changed files with 26 additions and 31 deletions

View File

@ -149,7 +149,7 @@ setCreds doRedirects creds = do
Nothing ->
when doRedirects $ do
case authRoute y of
Nothing -> do rh <- defaultLayout $ addHtml [shamlet| <h1>Invalid login |]
Nothing -> do rh <- defaultLayout $ toWidget [shamlet| <h1>Invalid login |]
sendResponse rh
Just ar -> do setMessageI Msg.InvalidLogin
redirect ar
@ -164,7 +164,7 @@ getCheckR = do
creds <- maybeAuthId
defaultLayoutJson (do
setTitle "Authentication Status"
addHtml $ html' creds) (jsonCreds creds)
toWidget $ html' creds) (jsonCreds creds)
where
html' creds =
[shamlet|

View File

@ -62,7 +62,7 @@ helper maudience = AuthPlugin
_ -> notFound
, apLogin = \toMaster -> do
addScriptRemote browserIdJs
addHamlet [hamlet|
toWidget [hamlet|
<p>
<a href="javascript:navigator.id.getVerifiedEmail(function(a){if(a)document.location='@{toMaster complete}/'+a});">
<img src="https://browserid.org/i/sign_in_green.png">

View File

@ -12,7 +12,7 @@ import Yesod.Auth
import Yesod.Form (runInputPost, textField, ireq)
import Yesod.Handler (notFound)
import Text.Hamlet (hamlet)
import Yesod.Widget (addHamlet)
import Yesod.Widget (toWidget)
authDummy :: YesodAuth m => AuthPlugin m
authDummy =
@ -24,7 +24,7 @@ authDummy =
dispatch _ _ = notFound
url = PluginR "dummy" []
login authToMaster =
addHamlet [hamlet|
toWidget [hamlet|
<form method="post" action="@{authToMaster url}">
Your new identifier is: #
<input type="text" name="ident">

View File

@ -158,6 +158,10 @@ setTitleI msg = do
mr <- lift getMessageRender
setTitle $ toHtml $ mr msg
{-# DEPRECATED addHamletHead, addHtmlHead "Use toWidgetHead instead" #-}
{-# DEPRECATED addHamlet, addHtml, addCassius, addLucius, addJulius "Use toWidget instead" #-}
{-# DEPRECATED addJuliusBody "Use toWidgetBody instead" #-}
-- | Add a 'Hamlet' to the head tag.
addHamletHead :: HtmlUrl (Route master) -> GWidget sub master ()
addHamletHead = tell . GWData mempty mempty mempty mempty mempty mempty . Head

View File

@ -48,7 +48,7 @@ module Yesod.Form.Fields
import Yesod.Form.Types
import Yesod.Form.I18n.English
import Yesod.Handler (getMessageRender)
import Yesod.Widget
import Yesod.Widget (toWidget, whamlet, GWidget)
import Yesod.Message (RenderMessage (renderMessage), SomeMessage (..))
import Text.Hamlet
import Text.Blaze (ToHtml (..), preEscapedText, unsafeByteString)
@ -100,8 +100,7 @@ intField = Field
Right (a, "") -> Right a
_ -> Left $ MsgInvalidInteger s
, fieldView = \theId name theClass val isReq -> addHamlet
[hamlet|
, fieldView = \theId name theClass val isReq -> toWidget [hamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" type="number" :isReq:required="" value="#{showVal val}">
|]
}
@ -116,8 +115,7 @@ doubleField = Field
Right (a, "") -> Right a
_ -> Left $ MsgInvalidNumber s
, fieldView = \theId name theClass val isReq -> addHamlet
[hamlet|
, fieldView = \theId name theClass val isReq -> toWidget [hamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" type="text" :isReq:required="" value="#{showVal val}">
|]
}
@ -126,8 +124,7 @@ doubleField = Field
dayField :: RenderMessage master FormMessage => Field sub master Day
dayField = Field
{ fieldParse = blank $ parseDate . unpack
, fieldView = \theId name theClass val isReq -> addHamlet
[hamlet|
, fieldView = \theId name theClass val isReq -> toWidget [hamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" type="date" :isReq:required="" value="#{showVal val}">
|]
}
@ -136,8 +133,7 @@ dayField = Field
timeField :: RenderMessage master FormMessage => Field sub master TimeOfDay
timeField = Field
{ fieldParse = blank $ parseTime . unpack
, fieldView = \theId name theClass val isReq -> addHamlet
[hamlet|
, fieldView = \theId name theClass val isReq -> toWidget [hamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate "" theClass}" :isReq:required="" value="#{showVal val}">
|]
}
@ -151,9 +147,8 @@ timeField = Field
htmlField :: RenderMessage master FormMessage => Field sub master Html
htmlField = Field
{ fieldParse = blank $ Right . preEscapedText . sanitizeBalance
, fieldView = \theId name theClass val _isReq -> addHamlet
, fieldView = \theId name theClass val _isReq -> toWidget [hamlet|
-- FIXME: There was a class="html" attribute, for what purpose?
[hamlet|\
<textarea id="#{theId}" name="#{name}" :not (null theClass):class=#{T.intercalate " " theClass}>#{showVal val}
|]
}
@ -180,8 +175,7 @@ instance ToHtml Textarea where
textareaField :: RenderMessage master FormMessage => Field sub master Textarea
textareaField = Field
{ fieldParse = blank $ Right . Textarea
, fieldView = \theId name theClass val _isReq -> addHamlet
[hamlet|\
, fieldView = \theId name theClass val _isReq -> toWidget [hamlet|
<textarea id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}">#{either id unTextarea val}
|]
}
@ -189,8 +183,7 @@ textareaField = Field
hiddenField :: RenderMessage master FormMessage => Field sub master Text
hiddenField = Field
{ fieldParse = blank $ Right
, fieldView = \theId name theClass val _isReq -> addHamlet
[hamlet|\
, fieldView = \theId name theClass val _isReq -> toWidget [hamlet|
<input type="hidden" id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" value="#{either id id val}">
|]
}
@ -207,8 +200,7 @@ textField = Field
passwordField :: RenderMessage master FormMessage => Field sub master Text
passwordField = Field
{ fieldParse = blank $ Right
, fieldView = \theId name theClass val isReq -> addHamlet
[hamlet|\
, fieldView = \theId name theClass val isReq -> toWidget [hamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" type="password" :isReq:required="" value="#{either id id val}">
|]
}
@ -257,8 +249,7 @@ emailField = Field
\s -> if Email.isValid (unpack s)
then Right s
else Left $ MsgInvalidEmail s
, fieldView = \theId name theClass val isReq -> addHamlet
[hamlet|\
, fieldView = \theId name theClass val isReq -> toWidget [hamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" type="email" :isReq:required="" value="#{either id id val}">
|]
}
@ -274,7 +265,7 @@ searchField autoFocus = Field
when autoFocus $ do
-- we want this javascript to be placed immediately after the field
[whamlet|<script>if (!('autofocus' in document.createElement('input'))) {document.getElementById('#{theId}').focus();}|]
addCassius [cassius|
toWidget [cassius|
#{theId}
-webkit-appearance: textfield
|]

View File

@ -65,13 +65,13 @@ jqueryDayField jds = Field
. readMay
. unpack
, fieldView = \theId name theClass val isReq -> do
addHtml [shamlet|\
toWidget [shamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" type="date" :isReq:required="" value="#{showVal val}">
|]
addScript' urlJqueryJs
addScript' urlJqueryUiJs
addStylesheet' urlJqueryUiCss
addJulius [julius|
toWidget [julius|
$(function(){
var i = $("##{theId}");
if (i.attr("type") != "date") {
@ -104,13 +104,13 @@ jqueryAutocompleteField :: (RenderMessage master FormMessage, YesodJquery master
jqueryAutocompleteField src = Field
{ fieldParse = blank $ Right
, fieldView = \theId name theClass val isReq -> do
addHtml [shamlet|\
toWidget [shamlet|
<input id="#{theId}" name="#{name}" :not (null theClass):class="#{T.intercalate " " theClass}" type="text" :isReq:required="" value="#{either id id val}" .autocomplete>
|]
addScript' urlJqueryJs
addScript' urlJqueryUiJs
addStylesheet' urlJqueryUiCss
addJulius [julius|
toWidget [julius|
$(function(){$("##{theId}").autocomplete({source:"@{src}",minLength:2})});
|]
}

View File

@ -32,12 +32,12 @@ nicHtmlField :: YesodNic master => Field sub master Html
nicHtmlField = Field
{ fieldParse = return . Right . fmap (preEscapedText . sanitizeBalance) . listToMaybe
, fieldView = \theId name theClass val _isReq -> do
addHtml [shamlet|
toWidget [shamlet|
<textarea id="#{theId}" :not (null theClass):class="#{T.intercalate " " theClass}" name="#{name}" .html>#{showVal val}
|]
addScript' urlNicEdit
master <- lift getYesod
addJulius $
toWidget $
case jsLoader master of
BottomOfHeadBlocking -> [julius|
bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("#{theId}")});