yesod-core-1.7.0.0: test/YesodCoreTest/SplitSubsite/NestedR.hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-orphans #-}
-- | The split-out dispatch module for the subsite's nested 'NestedR'
-- fragment. The handlers for the nested routes live here, alongside the
-- 'YesodSubDispatchNested' instance generated by 'mkNestedSubDispatchInstance'.
--
-- Crucially, this module is compiled /separately/ from the module that
-- defines the subsite's top-level 'YesodSubDispatch' instance. That instance's
-- 'mkYesodSubDispatch' splice sees this 'YesodSubDispatchNested' instance via
-- 'isInstance' and delegates to it — exactly the cross-module splitting that
-- "YesodCoreTest.NestedDispatch.Runtime" demonstrates for top-level sites.
module YesodCoreTest.SplitSubsite.NestedR (NestedR(..)) where
import Yesod.Core
import Yesod.Core.Dispatch
(mkNestedSubDispatchInstance, defaultOpts, TyArgs(..))
import Data.Text (Text, pack)
import YesodCoreTest.SplitSubsite.Data
getNestedHomeR :: SubHandlerFor SplitSub master Text
getNestedHomeR = pure "nestedHome"
getNestedDetailR :: Int -> SubHandlerFor SplitSub master Text
getNestedDetailR n = pure ("nestedDetail:" <> tshow n)
where
tshow = pack . show
$(mkNestedSubDispatchInstance
defaultOpts
"NestedR"
[] -- no instance context
NoTyArgs -- no type arguments (non-parameterized subsite)
return -- handler unwrapper
resourcesSplitSub)