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])
|
||||
, ("item", [''Item])
|
||||
, ("Key item", [''SinglePiece])
|
||||
, ("Routes master", [''Eq])
|
||||
] [$parseRoutes|
|
||||
/ CrudListR GET
|
||||
/add CrudAddR GET POST
|
||||
@ -58,24 +57,21 @@ getCrudListR = do
|
||||
%a!href=@toMaster.CrudAddR@ Add new item
|
||||
|]
|
||||
|
||||
getCrudAddR :: (Yesod master, Item item, SinglePiece (Key item),
|
||||
Eq (Routes master))
|
||||
getCrudAddR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||
=> GHandler (Crud master item) master RepHtml
|
||||
getCrudAddR = crudHelper
|
||||
"Add new"
|
||||
(Nothing :: Maybe (Key item, item))
|
||||
False
|
||||
|
||||
postCrudAddR :: (Yesod master, Item item, SinglePiece (Key item),
|
||||
Eq (Routes master))
|
||||
postCrudAddR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||
=> GHandler (Crud master item) master RepHtml
|
||||
postCrudAddR = crudHelper
|
||||
"Add new"
|
||||
(Nothing :: Maybe (Key item, item))
|
||||
True
|
||||
|
||||
getCrudEditR :: (Yesod master, Item item, SinglePiece (Key item),
|
||||
Eq (Routes master))
|
||||
getCrudEditR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||
=> String -> GHandler (Crud master item) master RepHtml
|
||||
getCrudEditR s = do
|
||||
itemId <- maybe notFound return $ itemReadId s
|
||||
@ -86,8 +82,7 @@ getCrudEditR s = do
|
||||
(Just (itemId, item))
|
||||
False
|
||||
|
||||
postCrudEditR :: (Yesod master, Item item, SinglePiece (Key item),
|
||||
Eq (Routes master))
|
||||
postCrudEditR :: (Yesod master, Item item, SinglePiece (Key item))
|
||||
=> String -> GHandler (Crud master item) master RepHtml
|
||||
postCrudEditR s = do
|
||||
itemId <- maybe notFound return $ itemReadId s
|
||||
@ -128,7 +123,7 @@ itemReadId :: SinglePiece x => String -> Maybe x
|
||||
itemReadId = either (const Nothing) Just . fromSinglePiece
|
||||
|
||||
crudHelper
|
||||
:: (Item a, Yesod master, SinglePiece (Key a), Eq (Routes master))
|
||||
:: (Item a, Yesod master, SinglePiece (Key a))
|
||||
=> String -> Maybe (Key a, a) -> Bool
|
||||
-> GHandler (Crud master a) master RepHtml
|
||||
crudHelper title me isPost = do
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
{-# LANGUAGE RankNTypes #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
-- | The basic typeclass for a Yesod application.
|
||||
module Yesod.Yesod
|
||||
@ -39,18 +40,18 @@ import Data.Maybe (isNothing)
|
||||
|
||||
-- | This class is automatically instantiated when you use the template haskell
|
||||
-- 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))
|
||||
type Method = String
|
||||
|
||||
-- | Same as 'YesodSite', but for subsites. Once again, users should not need
|
||||
-- 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))
|
||||
|
||||
-- | Define settings for a Yesod applications. The only required setting is
|
||||
-- '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
|
||||
-- trailing slash.
|
||||
--
|
||||
|
||||
Loading…
Reference in New Issue
Block a user