module Happstack.Server.Plugins.Dynamic
( PluginHandle
, PluginConf(..)
, initPlugins
, initPluginsWithConf
, defaultPluginConf
, withServerPart
, withServerPart_
) where
import Control.Monad.Trans (MonadIO)
import Language.Haskell.TH (ExpQ, Name, appE, varE)
import Language.Haskell.TH.Lift (lift)
import System.Plugins.Auto ( initPlugins,initPluginsWithConf,PluginHandle,withMonadIO_
, PluginConf(..), defaultPluginConf)
import Happstack.Server (ServerMonad, FilterMonad, WebMonad, Response, internalServerError, escape, toResponse)
withServerPart :: Name -> ExpQ
withServerPart name = appE (appE [| withServerPart_ |] (lift name)) (varE name)
withServerPart_ :: (MonadIO m, ServerMonad m, FilterMonad Response m, WebMonad Response m) =>
Name
-> a
-> PluginHandle
-> ([String] -> a -> m b)
-> m b
withServerPart_ name fun ph use = withMonadIO_ name fun ph notLoaded use
where
notLoaded errs = escape $ internalServerError$ toResponse$
case errs of
[] -> "Module not loaded yet."
_ -> unlines errs