Added Html' and get404
This commit is contained in:
parent
d8ece1db78
commit
db7dfcbefd
@ -20,6 +20,7 @@ module Yesod.Form
|
|||||||
-- * Newtype wrappers
|
-- * Newtype wrappers
|
||||||
, JqueryDay (..)
|
, JqueryDay (..)
|
||||||
, NicHtml (..)
|
, NicHtml (..)
|
||||||
|
, Html'
|
||||||
-- * Unwrapping functions
|
-- * Unwrapping functions
|
||||||
, runFormGet
|
, runFormGet
|
||||||
, runFormPost
|
, runFormPost
|
||||||
@ -551,6 +552,8 @@ instance ToFormField (Maybe (Html ())) where
|
|||||||
newtype NicHtml = NicHtml { unNicHtml :: Html () }
|
newtype NicHtml = NicHtml { unNicHtml :: Html () }
|
||||||
deriving PersistField
|
deriving PersistField
|
||||||
|
|
||||||
|
type Html' = Html ()
|
||||||
|
|
||||||
nicHtmlField :: Html () -> Html () -> FormletField sub y (Html ())
|
nicHtmlField :: Html () -> Html () -> FormletField sub y (Html ())
|
||||||
nicHtmlField label tooltip = requiredFieldHelper nicHtmlFieldProfile
|
nicHtmlField label tooltip = requiredFieldHelper nicHtmlFieldProfile
|
||||||
{ fpLabel = label
|
{ fpLabel = label
|
||||||
|
|||||||
@ -12,6 +12,7 @@ module Yesod.Yesod
|
|||||||
-- ** Persistence
|
-- ** Persistence
|
||||||
, YesodPersist (..)
|
, YesodPersist (..)
|
||||||
, module Database.Persist
|
, module Database.Persist
|
||||||
|
, get404
|
||||||
-- ** Breadcrumbs
|
-- ** Breadcrumbs
|
||||||
, YesodBreadcrumbs (..)
|
, YesodBreadcrumbs (..)
|
||||||
, breadcrumbs
|
, breadcrumbs
|
||||||
@ -38,6 +39,8 @@ import Data.Monoid (mempty)
|
|||||||
import Data.ByteString.UTF8 (toString)
|
import Data.ByteString.UTF8 (toString)
|
||||||
import Database.Persist
|
import Database.Persist
|
||||||
import Web.Routes.Site (Site)
|
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
|
-- | This class is automatically instantiated when you use the template haskell
|
||||||
-- mkYesod function. You should never need to deal with it directly.
|
-- mkYesod function. You should never need to deal with it directly.
|
||||||
@ -218,6 +221,17 @@ class YesodPersist y where
|
|||||||
type YesodDB y :: (* -> *) -> * -> *
|
type YesodDB y :: (* -> *) -> * -> *
|
||||||
runDB :: YesodDB y (GHandler sub y) a -> GHandler sub y a
|
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.
|
-- | 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
|
-- Built on top of 'isAuthorized'. This is useful for building page that only
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user