Skip to content

Instantly share code, notes, and snippets.

@duairc
Created June 14, 2010 01:49
Show Gist options
  • Save duairc/437187 to your computer and use it in GitHub Desktop.
Save duairc/437187 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Splices where
import Data.ByteString.Char8(ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Snap.Types
import Text.Templating.Heist
import Text.XML.Expat.Tree hiding (Node)
splices :: [(ByteString, Splice Snap)]
splices = [ ("menu", menuSplice)
, ("item", itemSplice) ]
menuSplice :: Splice Snap
menuSplice = do
input <- getParamNode
return [mkElement "ul" [] $ getChildren input]
itemSplice :: Splice Snap
itemSplice = do
input <- getParamNode
let href = fromJust $ getAttribute "href" input
text = fromJust $ getAttribute "text" input
a = mkElement "a" [ ("href", href)
, ("title", text) ] [mkText $ text]
return [mkElement "li" [] $ a:getChildren input]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment