Web.Routes.Quasi
Contents
- parseRoutes :: QuasiQuoter
- parseRoutesNoCheck :: QuasiQuoter
- createQuasiDispatch :: QuasiSiteSettings -> Q [Clause]
- createRender :: QuasiSiteSettings -> [Resource] -> Q [Clause]
- createParse :: QuasiSiteSettings -> [Resource] -> Q [Clause]
- createQuasiSite :: QuasiSiteSettings -> Q QuasiSiteDecs
- createQuasiSite' :: QuasiSiteSettings -> Q [Dec]
- data QuasiSiteSettings = QuasiSiteSettings {}
- data QuasiSiteDecs = QuasiSiteDecs {
- decRoutes :: Dec
- decRoutesSyn :: Dec
- decSiteType :: Dec
- decSite :: Dec
- type QuasiDispatch app sub master = (Routes master -> String) -> Routes sub -> (Routes sub -> Routes master) -> master -> (master -> sub) -> app -> String -> app
- data QuasiSite app sub master = QuasiSite {
- quasiDispatch :: QuasiDispatch app sub master
- quasiRender :: Routes sub -> [String]
- quasiParse :: [String] -> Either String (Routes sub)
- quasiFromSite :: Site surl app -> QuasiSite app (BlankArgs surl) master
- quasiToSite :: QuasiSite app sub sub -> ((String -> app) -> app) -> app -> sub -> Site (Routes sub) app
- type family Routes a
- data BlankArgs routes = BlankArgs
- data Resource = Resource String [Piece] Handler
- data Handler
- data Piece
- liftResources :: [Resource] -> Q Exp
- class SinglePiece s where
- fromSinglePiece :: String -> Either String s
- toSinglePiece :: s -> String
- class MultiPiece s where
- fromMultiPiece :: [String] -> Either String s
- toMultiPiece :: s -> [String]
- type Strings = [String]
Quasi quoter
parseRoutes :: QuasiQuoterSource
A quasi-quoter to parse a string into a list of Resources. Checks for
overlapping routes, failing if present; use parseRoutesNoCheck to skip the
checking. See documentation site for details on syntax.
parseRoutesNoCheck :: QuasiQuoterSource
Same as parseRoutes, but performs no overlap checking.
Template haskell
Low level
createQuasiDispatch :: QuasiSiteSettings -> Q [Clause]Source
Generate the set of clauses necesary to dispatch the given Resources.
See quasiDispatch.
createRender :: QuasiSiteSettings -> [Resource] -> Q [Clause]Source
Generates the set of clauses necesary to render the given Resources. See
quasiRender.
createParse :: QuasiSiteSettings -> [Resource] -> Q [Clause]Source
Generates the set of clauses necesary to parse the given Resources. See quasiParse.
High level for QuasiSites
createQuasiSite :: QuasiSiteSettings -> Q QuasiSiteDecsSource
Template haskell code to convert a list of Resources into appropriate
declarations for a QuasiSite. See the QuasiSiteSettings and
QuasiSiteDecs data types for an explanation for the input and output,
respectively, of this function.
createQuasiSite' :: QuasiSiteSettings -> Q [Dec]Source
data QuasiSiteSettings Source
The arguments passed to createQuasiSite for generating applications
based on the QuasiSite datatype.
Constructors
| QuasiSiteSettings | |
Fields
| |
data QuasiSiteDecs Source
The template Haskell declarations returned from createQuasiSite.
Constructors
| QuasiSiteDecs | |
Fields
| |
Quasi site
type QuasiDispatch app sub masterSource
Arguments
| = (Routes master -> String) | |
| -> Routes sub | |
| -> (Routes sub -> Routes master) | |
| -> master | |
| -> (master -> sub) | |
| -> app | bad method handler |
| -> String | method |
| -> app |
The type for quasiDispatch; separated out for clarity of Haddock docs.
data QuasiSite app sub master Source
Very similar in principle to Site, but with special support for
arguments and subsites.
Constructors
| QuasiSite | |
Fields
| |
quasiFromSite :: Site surl app -> QuasiSite app (BlankArgs surl) masterSource
Convert a Site to a QuasiSite. quasiRender and quasiParse are
identical to formatPathSegments and parsePathSegments; for the
quasiDispatch function, we just ignore the extra arguments that Site
does not use.
Arguments
| :: QuasiSite app sub sub | |
| -> ((String -> app) -> app) | grab method |
| -> app | bad method |
| -> sub | |
| -> Site (Routes sub) app |
Convert a QuasiSite to a Site. quasiRender and quasiParse are
identical to formatPathSegments and parsePathSegments; for the
handleSite function, we need some extra information passed to this
function. We also restrict the resulting QuasiSite to cases where subsite
and master site are the same.
Used for applications with no arguments. In particular, this facilitates a
translation from a Site to a QuasiSite via quasiFromSite.
Constructors
| BlankArgs |
Underlying data types
A single resource pattern.
First argument is the name of the constructor, second is the URL pattern to match, third is how to dispatch.
Defines how to dispatch a request for a specific resource.
ByMethod allows a different function to be called for each request method. The first value in each pair is the method, the second is the name of the handler.
Single dispatches to a single function for all methods.
SubSite passes dispatch to a different site. The first argument is the name
of the datatype for the routes. The second is a function returning a
QuasiSite for that type of routes. The third is a function converting the
master argument to the subsite argument.
A single piece of a URL, delimited by slashes.
In the case of StaticPiece, the argument is the value of the piece; for the other constructors, it is the name of the parameter represented by this piece. That value is not used here, but may be useful elsewhere.
Constructors
| StaticPiece String | |
| SinglePiece String | |
| MultiPiece String |
liftResources :: [Resource] -> Q ExpSource
FIXME
class SinglePiece s whereSource
class MultiPiece s whereSource
Instances