YesodBreadcrumbs
This commit is contained in:
parent
f3bf9ff27d
commit
ed2f89ca59
@ -9,6 +9,9 @@ module Yesod.Yesod
|
|||||||
-- ** Persistence
|
-- ** Persistence
|
||||||
, YesodPersist (..)
|
, YesodPersist (..)
|
||||||
, PersistEntity (..)
|
, PersistEntity (..)
|
||||||
|
-- ** Breadcrumbs
|
||||||
|
, YesodBreadcrumbs (..)
|
||||||
|
, breadcrumbs
|
||||||
-- * Convenience functions
|
-- * Convenience functions
|
||||||
, applyLayout
|
, applyLayout
|
||||||
, applyLayoutJson
|
, applyLayoutJson
|
||||||
@ -97,6 +100,31 @@ class Yesod a where
|
|||||||
isAuthorized :: a -> Routes a -> IO (Maybe String)
|
isAuthorized :: a -> Routes a -> IO (Maybe String)
|
||||||
isAuthorized _ _ = return Nothing
|
isAuthorized _ _ = return Nothing
|
||||||
|
|
||||||
|
-- | A type-safe, concise method of creating breadcrumbs for pages. For each
|
||||||
|
-- resource, you declare the title of the page and the parent resource (if
|
||||||
|
-- present).
|
||||||
|
class YesodBreadcrumbs y where
|
||||||
|
-- | Returns the title and the parent resource, if available. If you return
|
||||||
|
-- a 'Nothing', then this is considered a top-level page.
|
||||||
|
breadcrumb :: Routes y -> Handler y (String, Maybe (Routes y))
|
||||||
|
|
||||||
|
-- | Gets the title of the current page and the hierarchy of parent pages,
|
||||||
|
-- along with their respective titles.
|
||||||
|
breadcrumbs :: YesodBreadcrumbs y => Handler y (String, [(Routes y, String)])
|
||||||
|
breadcrumbs = do
|
||||||
|
x <- getRoute
|
||||||
|
case x of
|
||||||
|
Nothing -> return ("Not found", [])
|
||||||
|
Just y -> do
|
||||||
|
(title, next) <- breadcrumb y
|
||||||
|
z <- go [] next
|
||||||
|
return (title, z)
|
||||||
|
where
|
||||||
|
go back Nothing = return back
|
||||||
|
go back (Just this) = do
|
||||||
|
(title, next) <- breadcrumb this
|
||||||
|
go ((this, title) : back) next
|
||||||
|
|
||||||
-- | Apply the default layout ('defaultLayout') to the given title and body.
|
-- | Apply the default layout ('defaultLayout') to the given title and body.
|
||||||
applyLayout :: Yesod master
|
applyLayout :: Yesod master
|
||||||
=> String -- ^ title
|
=> String -- ^ title
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod
|
name: yesod
|
||||||
version: 0.3.0
|
version: 0.3.1
|
||||||
license: BSD3
|
license: BSD3
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user