Skip to content

Commit

Permalink
Wire in resource endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ozataman committed Mar 14, 2013
1 parent 2b06dd0 commit 1fe3d84
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Snap/Restful.hs
Expand Up @@ -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{..} =
Expand Down Expand Up @@ -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 ++
Expand All @@ -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


------------------------------------------------------------------------------
Expand Down Expand Up @@ -364,6 +366,13 @@ mkItemActionSplice r@Resource{..} dbid t =
, I.textSplice $ itemActionPath r t dbid)


-------------------------------------------------------------------------------
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 =
Expand Down

0 comments on commit 1fe3d84

Please sign in to comment.