yesod 0.6.1.2 → 0.6.2
raw patch · 4 files changed
+47/−3 lines, 4 files
Files
- Yesod/Content.hs +6/−1
- Yesod/Dispatch.hs +1/−1
- Yesod/Form.hs +39/−0
- yesod.cabal +1/−1
Yesod/Content.hs view
@@ -45,6 +45,7 @@ -- * Utilities , formatW3 , formatRFC1123+ , formatCookieExpires #if TEST , testSuite #endif@@ -249,10 +250,14 @@ Just typeHtml @=? lookup (ext "foo.html") typeByExt #endif --- | Format a 'UTCTime' in W3 format; useful for setting cookies.+-- | Format a 'UTCTime' in W3 format. formatW3 :: UTCTime -> String formatW3 = formatTime defaultTimeLocale "%FT%X-00:00" -- | Format as per RFC 1123. formatRFC1123 :: UTCTime -> String formatRFC1123 = formatTime defaultTimeLocale "%a, %d %b %Y %X %Z"++-- | Format a 'UTCTime' for a cookie.+formatCookieExpires :: UTCTime -> String+formatCookieExpires = formatTime defaultTimeLocale "%a, %d-%b-%Y %X GMT"
Yesod/Dispatch.hs view
@@ -385,7 +385,7 @@ let expires = getExpires minutes in ("Set-Cookie", charsToBs $ key ++ "=" ++ value ++"; path=/; expires="- ++ formatW3 expires)+ ++ formatCookieExpires expires) headerToPair _ (DeleteCookie key) = ("Set-Cookie", charsToBs $ key ++ "=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT")
Yesod/Form.hs view
@@ -29,6 +29,9 @@ , runFormMonadPost , runFormGet' , runFormPost'+ -- ** High-level form post unwrappers+ , runFormTable+ , runFormDivs -- * Field/form helpers , fieldsToTable , fieldsToDivs@@ -45,6 +48,7 @@ import Yesod.Form.Fields import Yesod.Form.Class import Yesod.Form.Profiles (Textarea (..))+import Yesod.Widget (GWidget) import Text.Hamlet import Yesod.Request@@ -143,6 +147,41 @@ (pp, files) <- liftIO $ reqRequestBody rr x <- runFormGeneric pp files f helper x++-- | Create a table-styled form.+--+-- This function wraps around 'runFormPost' and 'fieldsToTable', taking care of+-- some of the boiler-plate in creating forms. In particular, is automatically+-- creates the form element, sets the method, action and enctype attributes,+-- adds the CSRF-protection nonce hidden field and inserts a submit button.+runFormTable :: Route m -> String -> FormField s m a+ -> GHandler s m (FormResult a, GWidget s m ())+runFormTable dest inputLabel form = do+ (res, widget, enctype, nonce) <- runFormPost $ fieldsToTable form+ let widget' = [$hamlet|+%form!method=post!action=@dest@!enctype=$enctype$+ %table+ ^widget^+ %tr+ %td!colspan=2+ $nonce$+ %input!type=submit!value=$inputLabel$+|]+ return (res, widget')++-- | Same as 'runFormPostTable', but uses 'fieldsToDivs' for styling.+runFormDivs :: Route m -> String -> FormField s m a+ -> GHandler s m (FormResult a, GWidget s m ())+runFormDivs dest inputLabel form = do+ (res, widget, enctype, nonce) <- runFormPost $ fieldsToDivs form+ let widget' = [$hamlet|+%form!method=post!action=@dest@!enctype=$enctype$+ ^widget^+ %div+ $nonce$+ %input!type=submit!value=$inputLabel$+|]+ return (res, widget') -- | Run a form against GET parameters, disregarding the resulting HTML and -- returning an error response on invalid input.
yesod.cabal view
@@ -1,5 +1,5 @@ name: yesod-version: 0.6.1.2+version: 0.6.2 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>