Permalink
Browse files

Couple more convenience functions

  • Loading branch information...
1 parent 52c41d4 commit a15e4e0b243689780314b13a7aea5521a54c1874 @ozataman committed Jul 26, 2012
Showing with 23 additions and 0 deletions.
  1. +23 −0 src/Snap/Restful.hs
View
@@ -20,9 +20,12 @@ module Snap.Restful
, destroyPath
, itemActionPath
+ , templatePath
+
, resourceSplices
, itemSplices
+ , redirToItem
) where
-------------------------------------------------------------------------------
@@ -106,6 +109,20 @@ mkCrudRoute Resource{..} (crud, h) =
, ifTop $ method POST h)
+-- | Return heist template location for given crud action
+templatePath Resource{..} crud =
+ case crud of
+ RIndex -> B.intercalate "/" [r, "index"]
+ RCreate -> error "Create action does not get a template."
+ RShow -> B.intercalate "/" [r, "show"]
+ RNew -> B.intercalate "/" [r, "new"]
+ REdit -> B.intercalate "/" [r, "edit"]
+ RUpdate -> error "Update action does not get a template."
+ RDestroy -> error "Destroy action does not get a template."
+ where
+ r = T.encodeUtf8 rRoot
+
+
-------------------------------------------------------------------------------
crudPath :: Resource b v a -> CRUD -> DBId -> Text
crudPath Resource{..} crud DBId{..} =
@@ -202,6 +219,12 @@ mkItemActionSplice r@Resource{..} dbid t =
-------------------------------------------------------------------------------
+-- | Redirect to given item's default show page
+redirToItem :: MonadSnap m => Resource b v a -> DBId -> m a
+redirToItem r dbid = redirect . T.encodeUtf8 $ showPath r dbid
+
+
+-------------------------------------------------------------------------------
showT :: Show a => a -> Text
showT = T.pack . show

0 comments on commit a15e4e0

Please sign in to comment.