Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Wire in resource endpoints

  • Loading branch information...
commit 1fe3d849ca91d34eb2aeae8f87552e2604684827 1 parent 2b06dd0
@ozataman authored
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/Snap/Restful.hs
View
19 src/Snap/Restful.hs
@@ -249,6 +249,8 @@ templatePath Resource{..} crud =
-- x -> error $ "Unimplemented crudpath " ++ show x
+resourceActionPath Resource{..} t = mkPath [rRoot, t]
+
------------------------------------------------------------------------------
itemActionPath :: Resource -> Text -> DBId -> Text
itemActionPath Resource{..} t DBId{..} =
@@ -308,19 +310,19 @@ getFormAction = do
-------------------------------------------------------------------------------
+-- | Paths at the resource/collection level
resourceSplices :: Monad m => Resource -> [(Text, HeistT n m Template)]
resourceSplices r@Resource{..} =
+ map (mkResourceActionSplice r) rResourceEndpoints ++
[ (T.concat [rName, "NewPath"], I.textSplice $ newPath r)
, (T.concat [rName, "IndexPath"], I.textSplice $ indexPath r)
, (T.concat [rName, "CreatePath"], I.textSplice $ createPath r)
, (T.concat [rName, "Path"], I.textSplice $ rootPath r)
-
- -- This splice is designed to be used in create and update forms to specify
- -- the correct action URL.
- --, ("RESTFormAction", undefined)
]
+
------------------------------------------------------------------------------
+-- | Paths at the resource-item level
itemSplices :: Monad m => Resource -> DBId -> [(Text, I.Splice m)]
itemSplices r@Resource{..} dbid =
map (mkItemActionSplice r dbid) rItemEndpoints ++
@@ -336,7 +338,7 @@ itemSplices r@Resource{..} dbid =
-------------------------------------------------------------------------------
resourceCSplices :: MonadSnap m => Resource -> [(Text, C.Splice m)]
-resourceCSplices r = C.mapSnd (C.runNodeList =<<) (resourceSplices r)
+resourceCSplices r = C.mapSnd (C.runNodeList =<<) $ resourceSplices r
------------------------------------------------------------------------------
@@ -365,6 +367,13 @@ mkItemActionSplice r@Resource{..} dbid t =
-------------------------------------------------------------------------------
+mkResourceActionSplice :: Monad m => Resource -> Text -> (Text, HeistT n m Template)
+mkResourceActionSplice r@Resource{..} t =
+ ( T.concat [rName, cap t, "Path"]
+ , I.textSplice $ resourceActionPath r t)
+
+
+-------------------------------------------------------------------------------
mkItemActionCSplice :: Resource -> Text -> (Text, DBId -> Text)
mkItemActionCSplice r@Resource{..} t =
( T.concat [rName, "Item", cap t, "Path"]
Please sign in to comment.
Something went wrong with that request. Please try again.