module Heist.Splices.BindStrict where
import Data.Text (Text)
import qualified Data.Text as T
import qualified Text.XmlHtml as X
import Heist.Common
import Heist.Interpreted.Internal
import Heist.Splices.Apply
import Heist.Splices.Bind
import Heist.Internal.Types.HeistState
bindStrictTag :: Text
bindStrictTag :: Text
bindStrictTag = Text
"bindStrict"
bindStrictImpl :: Monad n => Splice n
bindStrictImpl :: Splice n
bindStrictImpl = do
Node
node <- HeistT n n Node
forall (m :: * -> *) (n :: * -> *). Monad m => HeistT n m Node
getParamNode
Template
cs <- Splice n
forall (n :: * -> *). Monad n => Splice n
runChildren
let err :: [Char]
err = [Char]
"must supply \"" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
T.unpack Text
bindAttr [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
"\" attribute in <" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
T.unpack (Node -> Text
X.elementTag Node
node) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
">"
HeistT n n ()
-> (Text -> HeistT n n ()) -> Maybe Text -> HeistT n n ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> HeistT n n ()
forall (m :: * -> *) a. Monad m => a -> m a
return () HeistT n n () -> [Char] -> HeistT n n ()
forall (m :: * -> *) (n :: * -> *) b.
Monad m =>
HeistT n m b -> [Char] -> HeistT n m b
`orError` [Char]
err) (Template -> Text -> HeistT n n ()
forall (m :: * -> *) (n :: * -> *).
(Monad m, Monad n) =>
Template -> Text -> HeistT n m ()
add Template
cs)
(Text -> Node -> Maybe Text
X.getAttribute Text
bindAttr Node
node)
Template -> Splice n
forall (m :: * -> *) a. Monad m => a -> m a
return []
where
add :: Template -> Text -> HeistT n m ()
add Template
cs Text
nm = (HeistState n -> HeistState n) -> HeistT n m ()
forall (m :: * -> *) (n :: * -> *).
Monad m =>
(HeistState n -> HeistState n) -> HeistT n m ()
modifyHS ((HeistState n -> HeistState n) -> HeistT n m ())
-> (HeistState n -> HeistState n) -> HeistT n m ()
forall a b. (a -> b) -> a -> b
$ Text -> Splice n -> HeistState n -> HeistState n
forall (n :: * -> *).
Text -> Splice n -> HeistState n -> HeistState n
bindSplice Text
nm (Splice n -> HeistState n -> HeistState n)
-> Splice n -> HeistState n -> HeistState n
forall a b. (a -> b) -> a -> b
$ do
Node
caller <- HeistT n n Node
forall (m :: * -> *) (n :: * -> *). Monad m => HeistT n m Node
getParamNode
TPath
ctx <- HeistT n n TPath
forall (m :: * -> *) (n :: * -> *). Monad m => HeistT n m TPath
getContext
Text -> Template -> Maybe [Char] -> TPath -> Template -> Splice n
forall (n :: * -> *).
Monad n =>
Text -> Template -> Maybe [Char] -> TPath -> Template -> Splice n
rawApply Text
"bindstrict-content" Template
cs Maybe [Char]
forall a. Maybe a
Nothing TPath
ctx (Node -> Template
X.childNodes Node
caller)