Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make Route a data family, so the typechecker can infer Site types fro…

…m Route types
  • Loading branch information...
commit f3afdfeea2b2cac40051ce1ad795e798faf96be6 1 parent 125090a
@softmechanics authored
View
7 Yesod/Dispatch.hs
@@ -138,8 +138,9 @@ mkYesodGeneral name args clazzes isSub res = do
th <- mapM (thResourceFromResource arg) res -- FIXME now we cannot have multi-nested subsites
w' <- createRoutes th
let routesName = mkName $ name ++ "Route"
- let w = DataD [] routesName [] w' [''Show, ''Read, ''Eq]
- let x = TySynInstD ''Route [arg] $ ConT routesName
+ let route = ConT ''Route `AppT` arg
+ let w = DataInstD [] ''Route [arg] w' [''Show, ''Read, ''Eq]
+ let x = TySynD routesName (map PlainTV args') route
parse' <- createParse th
parse'' <- newName "parse"
@@ -164,7 +165,7 @@ mkYesodGeneral name args clazzes isSub res = do
let y = InstanceD ctx ytyp
[ FunD (mkName yfunc) [Clause [] (NormalB site') []]
]
- return ([w, x], [y])
+ return ([w,x], [y])
isStatic :: Piece -> Bool
isStatic StaticPiece{} = True
View
2  Yesod/Handler.hs
@@ -120,7 +120,7 @@ import Yesod.Content
#endif
-- | The type-safe URLs associated with a site argument.
-type family Route a
+data family Route a
data HandlerData sub master = HandlerData
{ handlerRequest :: Request
View
3  Yesod/Helpers/Crud.hs
@@ -7,7 +7,8 @@
module Yesod.Helpers.Crud
( Item (..)
, Crud (..)
- , CrudRoute (..)
+ , CrudRoute
+ , Route (..)
, defaultCrud
) where
View
9 Yesod/Helpers/Static.hs
@@ -27,7 +27,8 @@
module Yesod.Helpers.Static
( -- * Subsite
Static (..)
- , StaticRoute (..)
+ , StaticRoute
+ , Route (..)
-- * Lookup files in filesystem
, fileLookupDir
, staticFiles
@@ -74,10 +75,10 @@ data Static = Static
-- would generate a url such as 'http://site.com/static/thumb001.jpg?foo=5&bar=choc'
-- The StaticRoute constructor can be used when url's cannot be statically generated at compile-time.
-- E.g. When generating image galleries.
-data StaticRoute = StaticRoute [String] [(String, String)]
- deriving (Eq, Show, Read)
-type instance Route Static = StaticRoute
+data instance Route Static = StaticRoute [String] [(String, String)]
+ deriving (Eq, Show, Read)
+type StaticRoute = Route Static
instance YesodSubSite Static master where
getSubSite = Site
View
4 Yesod/Yesod.hs
@@ -11,6 +11,7 @@ module Yesod.Yesod
Yesod (..)
, YesodSite (..)
, YesodSubSite (..)
+ , YesodSubRoute (..)
-- ** Persistence
, YesodPersist (..)
, module Database.Persist
@@ -82,6 +83,9 @@ type Method = String
class Eq (Route s) => YesodSubSite s y where
getSubSite :: Site (Route s) (Method -> Maybe (GHandler s y ChooseRep))
+class YesodSubRoute s y where
+ subRoute :: Route s -> Route y
+
-- | Define settings for a Yesod applications. The only required setting is
-- 'approot'; other than that, there are intelligent defaults.
class Eq (Route a) => Yesod a where
Please sign in to comment.
Something went wrong with that request. Please try again.