<commit_before>module Text.Templating.Heist.Splices.Bind where

------------------------------------------------------------------------------
import           Data.Text (Text)
import qualified Text.XmlHtml as X

------------------------------------------------------------------------------
import           Text.Templating.Heist.Internal
import           Text.Templating.Heist.Splices.Apply
import           Text.Templating.Heist.Types

-- | Default name for the bind splice.
bindTag :: Text
bindTag = "bind"


------------------------------------------------------------------------------
-- | Default attribute name for the bind tag.
bindAttr :: Text
bindAttr = "tag"


------------------------------------------------------------------------------
-- | Implementation of the bind splice.
bindImpl :: Monad m => Splice m
bindImpl = generalBind add
  where
    add node nm = do
        modifyTS $ bindSplice nm (return $ X.childNodes node)
        return []


generalBind :: Monad m => (X.Node -> Text -> Splice m) -> Splice m
generalBind k = do
    node <- getParamNode
    maybe (return [])
          (k node)
          (X.getAttribute bindAttr node)


bindImplNew :: Monad m => Splice m
bindImplNew = generalBind action
  where
    action node nm = do --unused nm might be a bug
        caller <- getParamNode
        ctx <- getContext
        rawApply (X.childNodes node) ctx (X.childNodes caller)
<commit_msg>Bind modified to have bound tags accept parameters.<commit_after>module Text.Templating.Heist.Splices.Bind where

------------------------------------------------------------------------------
import           Data.Text (Text)
import qualified Text.XmlHtml as X

------------------------------------------------------------------------------
import           Text.Templating.Heist.Internal
import           Text.Templating.Heist.Splices.Apply
import           Text.Templating.Heist.Types

-- | Default name for the bind splice.
bindTag :: Text
bindTag = "bind"


------------------------------------------------------------------------------
-- | Default attribute name for the bind tag.
bindAttr :: Text
bindAttr = "tag"


------------------------------------------------------------------------------
-- | Implementation of the bind splice.
bindImpl :: Monad m => Splice m
bindImpl = do
    node <- getParamNode
    maybe (return ())
          (add node)
          (X.getAttribute bindAttr node)
    return []

  where
    add node nm = modifyTS $ bindSplice nm $ do
        caller <- getParamNode
        ctx <- getContext
        rawApply (X.childNodes node) ctx (X.childNodes caller)


{'fraction_non_alphanumeric': 0.30609896432681244, 'fraction_numerical': 0.0, 'mean_word_length': 1.1824267782426778, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2481530', 'n_tokens_mistral': 627, 'n_tokens_neox': 595, 'n_words': 198}