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 :: forall (n :: * -> *). Monad n => Splice n
bindStrictImpl = do
node <- HeistT n n Node
forall (m :: * -> *) (n :: * -> *). Monad m => HeistT n m Node
getParamNode
cs <- runChildren
let err = String
"must supply \"" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
bindAttr String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"\" attribute in <" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack (Node -> Text
X.elementTag Node
node) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
">"
maybe (return () `orError` err) (add cs)
(X.getAttribute bindAttr node)
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
caller <- HeistT n n Node
forall (m :: * -> *) (n :: * -> *). Monad m => HeistT n m Node
getParamNode
ctx <- getContext
rawApply "bindstrict-content" cs Nothing ctx (X.childNodes caller)