module Text.Ascetic
where
import Data.String.Utils
type Content = String
type Tag = String
type Attribute = String
type Value = String
data Ascetic =
C Tag Content
| E Tag [Ascetic]
| A Tag [(Attribute, Value)] [Ascetic]
| D Tag [(Attribute, Value)] Ascetic
deriving (Eq)
class ToAscetic a where
ascetic :: a -> Ascetic
instance Show Ascetic where
show x = to "" x where
to ind x = case x of
C t c -> ind ++ "<" ++ t ++ ">" ++ c ++ "</" ++ t ++ ">"
E t [] -> "<" ++ t ++ "/>"
E t xs ->
ind
++ "<" ++ t ++ ">\n"
++ join "\n" [to (ind ++ " ") x | x <- xs]
++ "\n" ++ ind ++ "</" ++ t ++ ">"
A t avs [] ->
ind
++ "<" ++ t ++ " "
++ join " " [a ++ "=\"" ++ v ++ "\"" | (a,v) <- avs]
++ "/>"
A t avs xs ->
ind
++ "<" ++ t ++ " "
++ join " " [a ++ "=\"" ++ v ++ "\"" | (a,v) <- avs]
++ ">\n"
++ join "\n" [to (ind ++ " ") x | x <- xs]
++ "\n" ++ ind ++ "</" ++ t ++ ">"
D t avs x ->
ind
++ "<?" ++ t ++ " "
++ join " " [a ++ "=\"" ++ v ++ "\"" | (a,v) <- avs]
++ "?>\n"
++ (to ind x)
--eof