{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Rowdy.Yesod
( module Rowdy.Yesod
, (//)
, (/:)
, Endpoint(..)
, PathPiece(..)
, Type(..)
, Verb(..)
) where
import Data.Foldable (traverse_)
import Data.Typeable (Proxy (..), Typeable)
import Yesod.Routes.TH.Types
import Rowdy
import Rowdy.Yesod.Internal
toYesod :: Dsl () -> [ResourceTree String]
toYesod :: Dsl () -> [ResourceTree String]
toYesod = [RouteTree String PathPiece Endpoint] -> [ResourceTree String]
routeTreeToResourceTree ([RouteTree String PathPiece Endpoint] -> [ResourceTree String])
-> (Dsl () -> [RouteTree String PathPiece Endpoint])
-> Dsl ()
-> [ResourceTree String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dsl () -> [RouteTree String PathPiece Endpoint]
forall n c e a. RouteDsl n c e a -> Forest n c e
runRouteDsl
type Dsl = RouteDsl String PathPiece Endpoint
get, put, post, delete :: String -> Dsl ()
get :: String -> Dsl ()
get = Verb -> String -> Dsl ()
doVerb Verb
Get
put :: String -> Dsl ()
put = Verb -> String -> Dsl ()
doVerb Verb
Put
post :: String -> Dsl ()
post = Verb -> String -> Dsl ()
doVerb Verb
Post
delete :: String -> Dsl ()
delete = Verb -> String -> Dsl ()
doVerb Verb
Delete
doVerb :: Verb -> String -> Dsl ()
doVerb :: Verb -> String -> Dsl ()
doVerb Verb
v String
s = Endpoint -> Dsl ()
forall endpoint nest capture.
endpoint -> RouteDsl nest capture endpoint ()
terminal (Verb -> String -> Endpoint
MkResource Verb
v String
s)
subsite :: String -> String -> String -> Dsl ()
subsite :: String -> String -> String -> Dsl ()
subsite String
name String
thing String
func =
Endpoint -> Dsl ()
forall endpoint nest capture.
endpoint -> RouteDsl nest capture endpoint ()
terminal (String -> String -> String -> Endpoint
MkSubsite String
name String
thing String
func)
capture :: forall typ. Typeable typ => PathPiece
capture :: PathPiece
capture =
Proxy typ -> PathPiece
forall typ. Typeable typ => Proxy typ -> PathPiece
captureP (Proxy typ
forall k (t :: k). Proxy t
Proxy @typ)
captureP :: forall typ. Typeable typ => Proxy typ -> PathPiece
captureP :: Proxy typ -> PathPiece
captureP = Type -> PathPiece
Capture (Type -> PathPiece)
-> (Proxy typ -> Type) -> Proxy typ -> PathPiece
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy typ -> Type
forall t. Typeable t => Proxy t -> Type
Type
resource :: String -> [String -> Dsl ()] -> Dsl ()
resource :: String -> [String -> Dsl ()] -> Dsl ()
resource = ((String -> Dsl ()) -> Dsl ()) -> [String -> Dsl ()] -> Dsl ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (((String -> Dsl ()) -> Dsl ()) -> [String -> Dsl ()] -> Dsl ())
-> (String -> (String -> Dsl ()) -> Dsl ())
-> String
-> [String -> Dsl ()]
-> Dsl ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((String -> Dsl ()) -> String -> Dsl ())
-> String -> (String -> Dsl ()) -> Dsl ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (String -> Dsl ()) -> String -> Dsl ()
forall a. a -> a
id
attr :: String -> Dsl () -> Dsl ()
attr :: String -> Dsl () -> Dsl ()
attr = PathPiece -> Dsl () -> Dsl ()
forall capture nest endpoint.
capture
-> RouteDsl nest capture endpoint ()
-> RouteDsl nest capture endpoint ()
pathComponent (PathPiece -> Dsl () -> Dsl ())
-> (String -> PathPiece) -> String -> Dsl () -> Dsl ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> PathPiece
Attr
(/!) :: String -> Dsl () -> Dsl ()
/! :: String -> Dsl () -> Dsl ()
(/!) = String -> Dsl () -> Dsl ()
attr
infixr 8 /!
(!) :: Dsl () -> String -> Dsl ()
(!) = (String -> Dsl () -> Dsl ()) -> Dsl () -> String -> Dsl ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> Dsl () -> Dsl ()
attr
infixl 8 !