Added Html' and get404

This commit is contained in:
Michael Snoyman 2010-07-13 11:17:25 +03:00
parent d8ece1db78
commit db7dfcbefd
2 changed files with 17 additions and 0 deletions

View File

@ -20,6 +20,7 @@ module Yesod.Form
-- * Newtype wrappers
, JqueryDay (..)
, NicHtml (..)
, Html'
-- * Unwrapping functions
, runFormGet
, runFormPost
@ -551,6 +552,8 @@ instance ToFormField (Maybe (Html ())) where
newtype NicHtml = NicHtml { unNicHtml :: Html () }
deriving PersistField
type Html' = Html ()
nicHtmlField :: Html () -> Html () -> FormletField sub y (Html ())
nicHtmlField label tooltip = requiredFieldHelper nicHtmlFieldProfile
{ fpLabel = label

View File

@ -12,6 +12,7 @@ module Yesod.Yesod
-- ** Persistence
, YesodPersist (..)
, module Database.Persist
, get404
-- ** Breadcrumbs
, YesodBreadcrumbs (..)
, breadcrumbs
@ -38,6 +39,8 @@ import Data.Monoid (mempty)
import Data.ByteString.UTF8 (toString)
import Database.Persist
import Web.Routes.Site (Site)
import Control.Monad.Trans.Class (MonadTrans (..))
import Control.Monad.Attempt (Failure)
-- | This class is automatically instantiated when you use the template haskell
-- mkYesod function. You should never need to deal with it directly.
@ -218,6 +221,17 @@ class YesodPersist y where
type YesodDB y :: (* -> *) -> * -> *
runDB :: YesodDB y (GHandler sub y) a -> GHandler sub y a
-- Get the given entity by ID, or return a 404 not found if it doesn't exist.
get404 :: (PersistBackend (t m), PersistEntity val, Monad (t m),
Failure ErrorResponse m, MonadTrans t)
=> Key val -> t m val
get404 key = do
mres <- get key
case mres of
Nothing -> lift notFound
Just res -> return res
-- | Return the same URL if the user is authorized to see it.
--
-- Built on top of 'isAuthorized'. This is useful for building page that only