Yesod routes must fulfill equality constraint
This commit is contained in:
parent
879d5657ba
commit
c7f1669ac0
@ -34,7 +34,6 @@ mkYesodSub "Crud master item"
|
|||||||
[ ("master", [''Yesod])
|
[ ("master", [''Yesod])
|
||||||
, ("item", [''Item])
|
, ("item", [''Item])
|
||||||
, ("Key item", [''SinglePiece])
|
, ("Key item", [''SinglePiece])
|
||||||
, ("Routes master", [''Eq])
|
|
||||||
] [$parseRoutes|
|
] [$parseRoutes|
|
||||||
/ CrudListR GET
|
/ CrudListR GET
|
||||||
/add CrudAddR GET POST
|
/add CrudAddR GET POST
|
||||||
@ -58,24 +57,21 @@ getCrudListR = do
|
|||||||
%a!href=@toMaster.CrudAddR@ Add new item
|
%a!href=@toMaster.CrudAddR@ Add new item
|
||||||
|]
|
|]
|
||||||
|
|
||||||
getCrudAddR :: (Yesod master, Item item, SinglePiece (Key item),
|
getCrudAddR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||||
Eq (Routes master))
|
|
||||||
=> GHandler (Crud master item) master RepHtml
|
=> GHandler (Crud master item) master RepHtml
|
||||||
getCrudAddR = crudHelper
|
getCrudAddR = crudHelper
|
||||||
"Add new"
|
"Add new"
|
||||||
(Nothing :: Maybe (Key item, item))
|
(Nothing :: Maybe (Key item, item))
|
||||||
False
|
False
|
||||||
|
|
||||||
postCrudAddR :: (Yesod master, Item item, SinglePiece (Key item),
|
postCrudAddR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||||
Eq (Routes master))
|
|
||||||
=> GHandler (Crud master item) master RepHtml
|
=> GHandler (Crud master item) master RepHtml
|
||||||
postCrudAddR = crudHelper
|
postCrudAddR = crudHelper
|
||||||
"Add new"
|
"Add new"
|
||||||
(Nothing :: Maybe (Key item, item))
|
(Nothing :: Maybe (Key item, item))
|
||||||
True
|
True
|
||||||
|
|
||||||
getCrudEditR :: (Yesod master, Item item, SinglePiece (Key item),
|
getCrudEditR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||||
Eq (Routes master))
|
|
||||||
=> String -> GHandler (Crud master item) master RepHtml
|
=> String -> GHandler (Crud master item) master RepHtml
|
||||||
getCrudEditR s = do
|
getCrudEditR s = do
|
||||||
itemId <- maybe notFound return $ itemReadId s
|
itemId <- maybe notFound return $ itemReadId s
|
||||||
@ -86,8 +82,7 @@ getCrudEditR s = do
|
|||||||
(Just (itemId, item))
|
(Just (itemId, item))
|
||||||
False
|
False
|
||||||
|
|
||||||
postCrudEditR :: (Yesod master, Item item, SinglePiece (Key item),
|
postCrudEditR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||||
Eq (Routes master))
|
|
||||||
=> String -> GHandler (Crud master item) master RepHtml
|
=> String -> GHandler (Crud master item) master RepHtml
|
||||||
postCrudEditR s = do
|
postCrudEditR s = do
|
||||||
itemId <- maybe notFound return $ itemReadId s
|
itemId <- maybe notFound return $ itemReadId s
|
||||||
@ -128,7 +123,7 @@ itemReadId :: SinglePiece x => String -> Maybe x
|
|||||||
itemReadId = either (const Nothing) Just . fromSinglePiece
|
itemReadId = either (const Nothing) Just . fromSinglePiece
|
||||||
|
|
||||||
crudHelper
|
crudHelper
|
||||||
:: (Item a, Yesod master, SinglePiece (Key a), Eq (Routes master))
|
:: (Item a, Yesod master, SinglePiece (Key a))
|
||||||
=> String -> Maybe (Key a, a) -> Bool
|
=> String -> Maybe (Key a, a) -> Bool
|
||||||
-> GHandler (Crud master a) master RepHtml
|
-> GHandler (Crud master a) master RepHtml
|
||||||
crudHelper title me isPost = do
|
crudHelper title me isPost = do
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
{-# LANGUAGE RankNTypes #-}
|
{-# LANGUAGE RankNTypes #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
-- | The basic typeclass for a Yesod application.
|
-- | The basic typeclass for a Yesod application.
|
||||||
module Yesod.Yesod
|
module Yesod.Yesod
|
||||||
@ -39,18 +40,18 @@ import Data.Maybe (isNothing)
|
|||||||
|
|
||||||
-- | 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.
|
||||||
class YesodSite y where
|
class Eq (Routes y) => YesodSite y where
|
||||||
getSite :: Site (Routes y) (Method -> Maybe (Handler y ChooseRep))
|
getSite :: Site (Routes y) (Method -> Maybe (Handler y ChooseRep))
|
||||||
type Method = String
|
type Method = String
|
||||||
|
|
||||||
-- | Same as 'YesodSite', but for subsites. Once again, users should not need
|
-- | Same as 'YesodSite', but for subsites. Once again, users should not need
|
||||||
-- to deal with it directly, as the mkYesodSub creates instances appropriately.
|
-- to deal with it directly, as the mkYesodSub creates instances appropriately.
|
||||||
class YesodSubSite s y where
|
class Eq (Routes s) => YesodSubSite s y where
|
||||||
getSubSite :: Site (Routes s) (Method -> Maybe (GHandler s y ChooseRep))
|
getSubSite :: Site (Routes s) (Method -> Maybe (GHandler s y ChooseRep))
|
||||||
|
|
||||||
-- | Define settings for a Yesod applications. The only required setting is
|
-- | Define settings for a Yesod applications. The only required setting is
|
||||||
-- 'approot'; other than that, there are intelligent defaults.
|
-- 'approot'; other than that, there are intelligent defaults.
|
||||||
class Yesod a where
|
class Eq (Routes a) => Yesod a where
|
||||||
-- | An absolute URL to the root of the application. Do not include
|
-- | An absolute URL to the root of the application. Do not include
|
||||||
-- trailing slash.
|
-- trailing slash.
|
||||||
--
|
--
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user