{-# LANGUAGE TemplateHaskell #-}
module Control.Monad.Takahashi.HtmlBuilder.Html
( Html(..)
, showHtml
, showDiv
) where
import Control.Monad.Takahashi.HtmlBuilder.Style
import Data.Monoid
import Data.List (intercalate, lines)
data Html
= H1 String Html
| H2 String Html
| H3 String Html
| Li [String] Html
| P String Html
| TT String Html
| Img String Style Html
| Div
(Maybe String) -- Class
(Maybe String) -- Name
(Maybe Style) -- Style
Html -- Contents
Html
| Emp
deriving (Show, Read, Eq, Ord)
instance Monoid Html where
mempty = Emp
(H1 s h) `mappend` i = H1 s (h `mappend` i)
(H2 s h) `mappend` i = H2 s (h `mappend` i)
(H3 s h) `mappend` i = H3 s (h `mappend` i)
(Li xs h) `mappend` i = Li xs (h `mappend` i)
(P s h) `mappend` i = P s (h `mappend` i)
(TT s h) `mappend` i = TT s (h `mappend` i)
(Img fp s h) `mappend` i = Img fp s (h `mappend` i)
(Div cls name style con h) `mappend` i = Div cls name style con (h `mappend` i)
Emp `mappend` i = i
----
-- show
showHtml :: Html -> String
showHtml = intercalate "
". lines . showHtml'
where
showHtml' :: Html -> String
showHtml' (H1 s h) = concat ["
", s, "
", showHtml h] showHtml' (TT s h) = concat ["", s, "", showHtml h] showHtml' img@(Img _ _ h) = concat ["", showHtml h] showHtml' div@(Div _ _ _ s h) = concat ["