{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Text.Blaze.DTC where import Data.Bool import Data.Eq (Eq) import Data.Function (($), (.)) import Data.Int (Int) import Data.Maybe (Maybe(..)) import Data.Text (Text) import Text.Blaze import Text.Blaze.Internal import Text.Show (Show(..)) import Text.Blaze.Utils import Text.Blaze.DTC.Attributes -- * Type 'DTC' type DTC = Markup xmlModel :: Text -> DTC xmlModel rnc = Leaf "xml-model" "\n" () ! attribute "type" " type=\"" "application/relax-ng-compact-syntax" ! attribute "href" " href=\"" (attrValue rnc) xmlStylesheet :: Text -> DTC xmlStylesheet xsl = Leaf "xml-stylesheet" "\n" () ! attribute "type" " type=\"" "text/xsl" ! attribute "href" " href=\"" (attrValue xsl) html5Stylesheet :: Text -> DTC html5Stylesheet xsl = Leaf "html5-stylesheet" "\n" () ! attribute "type" " type=\"" "text/xsl" ! attribute "href" " href=\"" (attrValue xsl) atomStylesheet :: Text -> DTC atomStylesheet xsl = Leaf "atom-stylesheet" "\n" () ! attribute "type" " type=\"" "text/xsl" ! attribute "href" " href=\"" (attrValue xsl) about :: DTC -> DTC about = Parent "about" "" address :: DTC -> DTC address = Parent "address" "" artwork :: DTC -> DTC artwork = Parent "artwork" "" author :: DTC -> DTC author = Parent "author" "" b :: DTC -> DTC b = Parent "b" "" br :: DTC br = Leaf "br" "" () call :: DTC -> DTC call = Parent "call" "" code :: DTC -> DTC code = Parent "code" "" -- * Type 'Date' data Date = Date { date_year :: Int , date_month :: Maybe Int , date_day :: Maybe Int } deriving (Eq,Show) date :: Date -> DTC date Date{..} = Leaf "date" "" () ! attribute "year" " year=\"" (attrValue date_year) !?? (date_month, attribute "month" " month=\"" . attrValue) !?? (date_day, attribute "day" " day=\"" . attrValue) define :: DTC -> DTC define = Parent "define" "" document :: DTC -> DTC document = Parent "document" "" editor :: DTC -> DTC editor = Parent "editor" "" email :: DTC -> DTC email = Parent "email" "" eref :: DTC -> DTC eref (Empty a) = Leaf "eref" "" a eref x = Parent "eref" "" x figure :: DTC -> DTC figure = Parent "figure" "" i :: DTC -> DTC i = Parent "i" "" include :: Bool -> AttributeValue -> DTC include inc h = Leaf "include" "" () !? (not inc, attribute "include" " include=\"" "no") ! href h keyword :: DTC -> DTC keyword = Parent "keyword" "" li :: DTC -> DTC li = Parent "li" "" link :: DTC -> DTC link = Parent "link" "" macro :: DTC -> DTC macro = Parent "macro" "" name :: DTC -> DTC name = Parent "name" "" note :: DTC -> DTC note = Parent "note" "" ol :: DTC -> DTC ol = Parent "ol" "" organization :: DTC -> DTC organization = Parent "organization" "" para :: DTC -> DTC para = Parent "para" "" q :: DTC -> DTC q = Parent "q" "" quote :: DTC -> DTC quote = Parent "quote" "" ref :: DTC -> DTC ref (Empty a) = Leaf "ref" "" a ref x = Parent "ref" "" x reference :: DTC -> DTC reference = Parent "reference" "" references :: DTC -> DTC references = Parent "references" "" rref :: DTC -> DTC rref (Empty a) = Leaf "rref" "" a rref x = Parent "rref" "" x section :: DTC -> DTC section = Parent "section" "" ul :: DTC -> DTC ul = Parent "ul" "" -- * Type 'Postal' data Postal = Postal { postal_street :: Text , postal_zipcode :: Text , postal_city :: Text , postal_region :: Text , postal_country :: Text } deriving (Eq,Show) postal :: Postal -> DTC postal Postal{..} = Parent "postal" "" $ do Parent "street" "" $ toMarkup postal_street Parent "zipcode" "" $ toMarkup postal_zipcode Parent "city" "" $ toMarkup postal_city Parent "region" "" $ toMarkup postal_region Parent "country" "" $ toMarkup postal_country indentTag :: Text -> IndentTag indentTag t = case t of "about" -> IndentTagChildren "address" -> IndentTagChildren "author" -> IndentTagChildren "document" -> IndentTagChildren "figure" -> IndentTagChildren "ol" -> IndentTagChildren "postal" -> IndentTagChildren "reference" -> IndentTagChildren "references" -> IndentTagChildren "section" -> IndentTagChildren "ul" -> IndentTagChildren "a" -> IndentTagText "b" -> IndentTagText "i" -> IndentTagText "li" -> IndentTagText "para" -> IndentTagText "q" -> IndentTagText "quote" -> IndentTagText "note" -> IndentTagText _ -> IndentTagPreserve