module Control.Monad.Apiary.Filter.Internal.Capture where
import Control.Applicative
import Control.Monad
import qualified Data.Text as T
import Text.Blaze.Html
import Data.Apiary.Param
import Data.Apiary.SList
import Data.Apiary.Document
import Control.Monad.Apiary.Action.Internal
import Control.Monad.Apiary.Internal
path :: Monad n => T.Text -> ApiaryT c n m a -> ApiaryT c n m a
path p = focus (DocPath p) $ \l -> l <$ path'
where
path' = liftM actionPathInfo getState >>= \case
c:_ | c == p -> modifyState (\s -> s {actionPathInfo = tail $ actionPathInfo s})
_ -> mzero
endPath :: Monad n => ApiaryT c n m a -> ApiaryT c n m a
endPath = focus id $ \l -> l <$ end
where
end = liftM actionPathInfo getState >>= \case
[] -> return ()
_ -> mzero
fetch :: (Path a, Monad n) => proxy a -> Maybe Html -> ApiaryT (Snoc as a) n m b -> ApiaryT as n m b
fetch p h = focus (DocFetch (pathRep p) h) $ \l -> liftM actionPathInfo getState >>= \case
[] -> mzero
c:_ -> case readPathAs p c of
Nothing -> mzero
Just r -> sSnoc l r <$
modifyState (\s -> s {actionPathInfo = tail $ actionPathInfo s})