-- |This module provides, @instance 'XMLGenerator' ('ServerPartT' m)@
{-# LANGUAGE CPP, MultiParamTypeClasses, TypeSynonymInstances, FlexibleContexts, FlexibleInstances, TypeFamilies, OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module HSP.ServerPartT () where

import Control.Monad              (liftM)
import Data.Monoid                ((<>))
import qualified Data.Text        as T
import qualified Data.Text.Lazy   as TL
import HSP.XML
import HSP.XMLGenerator
import Happstack.Server (ServerPartT)

instance (Monad m) => XMLGen (ServerPartT m) where
    type XMLType (ServerPartT m) = XML
    type StringType (ServerPartT m) = TL.Text
    newtype ChildType (ServerPartT m) = SChild { ChildType (ServerPartT m) -> XML
unSChild :: XML }
    newtype AttributeType (ServerPartT m) = SAttr { AttributeType (ServerPartT m) -> Attribute
unSAttr :: Attribute }
    genElement :: Name (StringType (ServerPartT m))
-> [XMLGenT (ServerPartT m) [AttributeType (ServerPartT m)]]
-> [XMLGenT (ServerPartT m) [ChildType (ServerPartT m)]]
-> XMLGenT (ServerPartT m) (XMLType (ServerPartT m))
genElement Name (StringType (ServerPartT m))
n [XMLGenT (ServerPartT m) [AttributeType (ServerPartT m)]]
attrs [XMLGenT (ServerPartT m) [ChildType (ServerPartT m)]]
children =
        do [Attribute]
attribs <- (AttributeType (ServerPartT m) -> Attribute)
-> [AttributeType (ServerPartT m)] -> [Attribute]
forall a b. (a -> b) -> [a] -> [b]
map AttributeType (ServerPartT m) -> Attribute
forall (m :: * -> *). AttributeType (ServerPartT m) -> Attribute
unSAttr ([AttributeType (ServerPartT m)] -> [Attribute])
-> XMLGenT (ServerPartT m) [AttributeType (ServerPartT m)]
-> XMLGenT (ServerPartT m) [Attribute]
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` [XMLGenT (ServerPartT m) [AttributeType (ServerPartT m)]]
-> XMLGenT (ServerPartT m) [AttributeType (ServerPartT m)]
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr [XMLGenT (ServerPartT m) [AttributeType (ServerPartT m)]]
attrs
           [XML]
childer <- ([XML] -> [XML]
flattenCDATA ([XML] -> [XML])
-> ([ChildType (ServerPartT m)] -> [XML])
-> [ChildType (ServerPartT m)]
-> [XML]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChildType (ServerPartT m) -> XML)
-> [ChildType (ServerPartT m)] -> [XML]
forall a b. (a -> b) -> [a] -> [b]
map ChildType (ServerPartT m) -> XML
forall (m :: * -> *). ChildType (ServerPartT m) -> XML
unSChild) ([ChildType (ServerPartT m)] -> [XML])
-> XMLGenT (ServerPartT m) [ChildType (ServerPartT m)]
-> XMLGenT (ServerPartT m) [XML]
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM`[XMLGenT (ServerPartT m) [ChildType (ServerPartT m)]]
-> XMLGenT (ServerPartT m) [ChildType (ServerPartT m)]
forall (m :: * -> *) c. EmbedAsChild m c => c -> GenChildList m
asChild [XMLGenT (ServerPartT m) [ChildType (ServerPartT m)]]
children
           XML -> XMLGenT (ServerPartT m) XML
forall (m :: * -> *) a. Monad m => a -> m a
return (NSName -> [Attribute] -> [XML] -> XML
Element
                              (NSName -> NSName
forall n s. IsName n s => n -> Name s
toName NSName
Name (StringType (ServerPartT m))
n)
                              [Attribute]
attribs
                              [XML]
childer
                             )
    xmlToChild :: XMLType (ServerPartT m) -> ChildType (ServerPartT m)
xmlToChild = XMLType (ServerPartT m) -> ChildType (ServerPartT m)
forall (m :: * -> *). XML -> ChildType (ServerPartT m)
SChild
    pcdataToChild :: StringType (ServerPartT m) -> ChildType (ServerPartT m)
pcdataToChild = XML -> ChildType (ServerPartT m)
forall (m :: * -> *). XMLGen m => XMLType m -> ChildType m
xmlToChild (XML -> ChildType (ServerPartT m))
-> (Text -> XML) -> Text -> ChildType (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> XML
pcdata

flattenCDATA :: [XML] -> [XML]
flattenCDATA :: [XML] -> [XML]
flattenCDATA [XML]
cxml =
                case [XML] -> [XML] -> [XML]
flP [XML]
cxml [] of
                 [] -> []
                 [CDATA Bool
_ Text
""] -> []
                 [XML]
xs -> [XML]
xs
    where
        flP :: [XML] -> [XML] -> [XML]
        flP :: [XML] -> [XML] -> [XML]
flP [] [XML]
bs = [XML] -> [XML]
forall a. [a] -> [a]
reverse [XML]
bs
        flP [XML
x] [XML]
bs = [XML] -> [XML]
forall a. [a] -> [a]
reverse (XML
xXML -> [XML] -> [XML]
forall a. a -> [a] -> [a]
:[XML]
bs)
        flP (XML
x:XML
y:[XML]
xs) [XML]
bs = case (XML
x,XML
y) of
                           (CDATA Bool
e1 Text
s1, CDATA Bool
e2 Text
s2) | Bool
e1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
e2 -> [XML] -> [XML] -> [XML]
flP (Bool -> Text -> XML
CDATA Bool
e1 (Text
s1Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>Text
s2) XML -> [XML] -> [XML]
forall a. a -> [a] -> [a]
: [XML]
xs) [XML]
bs
                           (XML, XML)
_ -> [XML] -> [XML] -> [XML]
flP (XML
yXML -> [XML] -> [XML]
forall a. a -> [a] -> [a]
:[XML]
xs) (XML
xXML -> [XML] -> [XML]
forall a. a -> [a] -> [a]
:[XML]
bs)

{-
instance (Monad m) => IsAttrValue (ServerPartT m) T.Text where
    toAttrValue = toAttrValue . T.unpack

instance (Monad m) => IsAttrValue (ServerPartT m) TL.Text where
    toAttrValue = toAttrValue . TL.unpack
-}
instance (Functor m, Monad m) => EmbedAsAttr (ServerPartT m) Attribute where
    asAttr :: Attribute -> GenAttributeList (ServerPartT m)
asAttr = [AttributeType (ServerPartT m)] -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. Monad m => a -> m a
return ([AttributeType (ServerPartT m)]
 -> GenAttributeList (ServerPartT m))
-> (Attribute -> [AttributeType (ServerPartT m)])
-> Attribute
-> GenAttributeList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AttributeType (ServerPartT m)
-> [AttributeType (ServerPartT m)]
-> [AttributeType (ServerPartT m)]
forall a. a -> [a] -> [a]
:[]) (AttributeType (ServerPartT m) -> [AttributeType (ServerPartT m)])
-> (Attribute -> AttributeType (ServerPartT m))
-> Attribute
-> [AttributeType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Attribute -> AttributeType (ServerPartT m)
forall (m :: * -> *). Attribute -> AttributeType (ServerPartT m)
SAttr

instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n Char) where
    asAttr :: Attr n Char -> GenAttributeList (ServerPartT m)
asAttr (n
n := Char
c)  = Attr n [Char] -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr (n
n n -> [Char] -> Attr n [Char]
forall n a. n -> a -> Attr n a
:= [Char
c])

instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n String) where
    asAttr :: Attr n [Char] -> GenAttributeList (ServerPartT m)
asAttr (n
n := [Char]
str)  = Attribute -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr (Attribute -> GenAttributeList (ServerPartT m))
-> Attribute -> GenAttributeList (ServerPartT m)
forall a b. (a -> b) -> a -> b
$ (NSName, AttrValue) -> Attribute
MkAttr (n -> NSName
forall n s. IsName n s => n -> Name s
toName n
n, Text -> AttrValue
pAttrVal (Text -> AttrValue) -> Text -> AttrValue
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
TL.pack [Char]
str)

instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n Bool) where
    asAttr :: Attr n Bool -> GenAttributeList (ServerPartT m)
asAttr (n
n := Bool
True)  = Attribute -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr (Attribute -> GenAttributeList (ServerPartT m))
-> Attribute -> GenAttributeList (ServerPartT m)
forall a b. (a -> b) -> a -> b
$ (NSName, AttrValue) -> Attribute
MkAttr (n -> NSName
forall n s. IsName n s => n -> Name s
toName n
n, Text -> AttrValue
pAttrVal Text
"true")
    asAttr (n
n := Bool
False) = Attribute -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr (Attribute -> GenAttributeList (ServerPartT m))
-> Attribute -> GenAttributeList (ServerPartT m)
forall a b. (a -> b) -> a -> b
$ (NSName, AttrValue) -> Attribute
MkAttr (n -> NSName
forall n s. IsName n s => n -> Name s
toName n
n, Text -> AttrValue
pAttrVal Text
"false")

instance (Functor m, Monad m, IsName n TL.Text) => EmbedAsAttr (ServerPartT m) (Attr n Int) where
    asAttr :: Attr n Int -> GenAttributeList (ServerPartT m)
asAttr (n
n := Int
i)  = Attribute -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr (Attribute -> GenAttributeList (ServerPartT m))
-> Attribute -> GenAttributeList (ServerPartT m)
forall a b. (a -> b) -> a -> b
$ (NSName, AttrValue) -> Attribute
MkAttr (n -> NSName
forall n s. IsName n s => n -> Name s
toName n
n, Text -> AttrValue
pAttrVal ([Char] -> Text
TL.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
i))

instance (Functor m, Monad m, IsName n TL.Text) => (EmbedAsAttr (ServerPartT m) (Attr n TL.Text)) where
    asAttr :: Attr n Text -> GenAttributeList (ServerPartT m)
asAttr (n
n := Text
a) = Attribute -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr (Attribute -> GenAttributeList (ServerPartT m))
-> Attribute -> GenAttributeList (ServerPartT m)
forall a b. (a -> b) -> a -> b
$ (NSName, AttrValue) -> Attribute
MkAttr (n -> NSName
forall n s. IsName n s => n -> Name s
toName n
n, Text -> AttrValue
pAttrVal (Text -> AttrValue) -> Text -> AttrValue
forall a b. (a -> b) -> a -> b
$ Text
a)

instance (Functor m, Monad m, IsName n TL.Text) => (EmbedAsAttr (ServerPartT m) (Attr n T.Text)) where
    asAttr :: Attr n Text -> GenAttributeList (ServerPartT m)
asAttr (n
n := Text
a) = Attribute -> GenAttributeList (ServerPartT m)
forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
asAttr (Attribute -> GenAttributeList (ServerPartT m))
-> Attribute -> GenAttributeList (ServerPartT m)
forall a b. (a -> b) -> a -> b
$ (NSName, AttrValue) -> Attribute
MkAttr (n -> NSName
forall n s. IsName n s => n -> Name s
toName n
n, Text -> AttrValue
pAttrVal (Text -> AttrValue) -> Text -> AttrValue
forall a b. (a -> b) -> a -> b
$ Text -> Text
TL.fromStrict Text
a)

instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) Char where
    asChild :: Char -> GenChildList (ServerPartT m)
asChild = ServerPartT m [ChildType (ServerPartT m)]
-> GenChildList (ServerPartT m)
forall (m :: * -> *) a. m a -> XMLGenT m a
XMLGenT (ServerPartT m [ChildType (ServerPartT m)]
 -> GenChildList (ServerPartT m))
-> (Char -> ServerPartT m [ChildType (ServerPartT m)])
-> Char
-> GenChildList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ChildType (ServerPartT m)]
-> ServerPartT m [ChildType (ServerPartT m)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ChildType (ServerPartT m)]
 -> ServerPartT m [ChildType (ServerPartT m)])
-> (Char -> [ChildType (ServerPartT m)])
-> Char
-> ServerPartT m [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChildType (ServerPartT m)
-> [ChildType (ServerPartT m)] -> [ChildType (ServerPartT m)]
forall a. a -> [a] -> [a]
:[]) (ChildType (ServerPartT m) -> [ChildType (ServerPartT m)])
-> (Char -> ChildType (ServerPartT m))
-> Char
-> [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XML -> ChildType (ServerPartT m)
forall (m :: * -> *). XML -> ChildType (ServerPartT m)
SChild (XML -> ChildType (ServerPartT m))
-> (Char -> XML) -> Char -> ChildType (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> XML
pcdata (Text -> XML) -> (Char -> Text) -> Char -> XML
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
TL.singleton

instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) String where
    asChild :: [Char] -> GenChildList (ServerPartT m)
asChild = ServerPartT m [ChildType (ServerPartT m)]
-> GenChildList (ServerPartT m)
forall (m :: * -> *) a. m a -> XMLGenT m a
XMLGenT (ServerPartT m [ChildType (ServerPartT m)]
 -> GenChildList (ServerPartT m))
-> ([Char] -> ServerPartT m [ChildType (ServerPartT m)])
-> [Char]
-> GenChildList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ChildType (ServerPartT m)]
-> ServerPartT m [ChildType (ServerPartT m)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ChildType (ServerPartT m)]
 -> ServerPartT m [ChildType (ServerPartT m)])
-> ([Char] -> [ChildType (ServerPartT m)])
-> [Char]
-> ServerPartT m [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChildType (ServerPartT m)
-> [ChildType (ServerPartT m)] -> [ChildType (ServerPartT m)]
forall a. a -> [a] -> [a]
:[]) (ChildType (ServerPartT m) -> [ChildType (ServerPartT m)])
-> ([Char] -> ChildType (ServerPartT m))
-> [Char]
-> [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XML -> ChildType (ServerPartT m)
forall (m :: * -> *). XML -> ChildType (ServerPartT m)
SChild (XML -> ChildType (ServerPartT m))
-> ([Char] -> XML) -> [Char] -> ChildType (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> XML
pcdata (Text -> XML) -> ([Char] -> Text) -> [Char] -> XML
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
TL.pack

instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) Int where
    asChild :: Int -> GenChildList (ServerPartT m)
asChild = ServerPartT m [ChildType (ServerPartT m)]
-> GenChildList (ServerPartT m)
forall (m :: * -> *) a. m a -> XMLGenT m a
XMLGenT (ServerPartT m [ChildType (ServerPartT m)]
 -> GenChildList (ServerPartT m))
-> (Int -> ServerPartT m [ChildType (ServerPartT m)])
-> Int
-> GenChildList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ChildType (ServerPartT m)]
-> ServerPartT m [ChildType (ServerPartT m)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ChildType (ServerPartT m)]
 -> ServerPartT m [ChildType (ServerPartT m)])
-> (Int -> [ChildType (ServerPartT m)])
-> Int
-> ServerPartT m [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChildType (ServerPartT m)
-> [ChildType (ServerPartT m)] -> [ChildType (ServerPartT m)]
forall a. a -> [a] -> [a]
:[]) (ChildType (ServerPartT m) -> [ChildType (ServerPartT m)])
-> (Int -> ChildType (ServerPartT m))
-> Int
-> [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XML -> ChildType (ServerPartT m)
forall (m :: * -> *). XML -> ChildType (ServerPartT m)
SChild (XML -> ChildType (ServerPartT m))
-> (Int -> XML) -> Int -> ChildType (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> XML
pcdata (Text -> XML) -> (Int -> Text) -> Int -> XML
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
TL.pack ([Char] -> Text) -> (Int -> [Char]) -> Int -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char]
forall a. Show a => a -> [Char]
show

instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) Integer where
    asChild :: Integer -> GenChildList (ServerPartT m)
asChild = ServerPartT m [ChildType (ServerPartT m)]
-> GenChildList (ServerPartT m)
forall (m :: * -> *) a. m a -> XMLGenT m a
XMLGenT (ServerPartT m [ChildType (ServerPartT m)]
 -> GenChildList (ServerPartT m))
-> (Integer -> ServerPartT m [ChildType (ServerPartT m)])
-> Integer
-> GenChildList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ChildType (ServerPartT m)]
-> ServerPartT m [ChildType (ServerPartT m)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ChildType (ServerPartT m)]
 -> ServerPartT m [ChildType (ServerPartT m)])
-> (Integer -> [ChildType (ServerPartT m)])
-> Integer
-> ServerPartT m [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChildType (ServerPartT m)
-> [ChildType (ServerPartT m)] -> [ChildType (ServerPartT m)]
forall a. a -> [a] -> [a]
:[]) (ChildType (ServerPartT m) -> [ChildType (ServerPartT m)])
-> (Integer -> ChildType (ServerPartT m))
-> Integer
-> [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XML -> ChildType (ServerPartT m)
forall (m :: * -> *). XML -> ChildType (ServerPartT m)
SChild (XML -> ChildType (ServerPartT m))
-> (Integer -> XML) -> Integer -> ChildType (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> XML
pcdata (Text -> XML) -> (Integer -> Text) -> Integer -> XML
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
TL.pack ([Char] -> Text) -> (Integer -> [Char]) -> Integer -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> [Char]
forall a. Show a => a -> [Char]
show

instance (Functor m, Monad m) => EmbedAsChild (ServerPartT m) XML where
    asChild :: XML -> GenChildList (ServerPartT m)
asChild = ServerPartT m [ChildType (ServerPartT m)]
-> GenChildList (ServerPartT m)
forall (m :: * -> *) a. m a -> XMLGenT m a
XMLGenT (ServerPartT m [ChildType (ServerPartT m)]
 -> GenChildList (ServerPartT m))
-> (XML -> ServerPartT m [ChildType (ServerPartT m)])
-> XML
-> GenChildList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ChildType (ServerPartT m)]
-> ServerPartT m [ChildType (ServerPartT m)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([ChildType (ServerPartT m)]
 -> ServerPartT m [ChildType (ServerPartT m)])
-> (XML -> [ChildType (ServerPartT m)])
-> XML
-> ServerPartT m [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChildType (ServerPartT m)
-> [ChildType (ServerPartT m)] -> [ChildType (ServerPartT m)]
forall a. a -> [a] -> [a]
:[]) (ChildType (ServerPartT m) -> [ChildType (ServerPartT m)])
-> (XML -> ChildType (ServerPartT m))
-> XML
-> [ChildType (ServerPartT m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XML -> ChildType (ServerPartT m)
forall (m :: * -> *). XML -> ChildType (ServerPartT m)
SChild

instance Monad m => EmbedAsChild (ServerPartT m) () where
  asChild :: () -> GenChildList (ServerPartT m)
asChild () = [ChildType (ServerPartT m)] -> GenChildList (ServerPartT m)
forall (m :: * -> *) a. Monad m => a -> m a
return []

instance (Functor m, Monad m) => (EmbedAsChild (ServerPartT m) TL.Text) where
    asChild :: Text -> GenChildList (ServerPartT m)
asChild = [Char] -> GenChildList (ServerPartT m)
forall (m :: * -> *) c. EmbedAsChild m c => c -> GenChildList m
asChild ([Char] -> GenChildList (ServerPartT m))
-> (Text -> [Char]) -> Text -> GenChildList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
TL.unpack

instance (Functor m, Monad m) => (EmbedAsChild (ServerPartT m) T.Text) where
    asChild :: Text -> GenChildList (ServerPartT m)
asChild = [Char] -> GenChildList (ServerPartT m)
forall (m :: * -> *) c. EmbedAsChild m c => c -> GenChildList m
asChild ([Char] -> GenChildList (ServerPartT m))
-> (Text -> [Char]) -> Text -> GenChildList (ServerPartT m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
T.unpack

instance (Functor m, Monad m) => AppendChild (ServerPartT m) XML where
 appAll :: XML -> GenChildList (ServerPartT m) -> GenXML (ServerPartT m)
appAll XML
xml GenChildList (ServerPartT m)
children = do
        [ChildType (ServerPartT m)]
chs <- GenChildList (ServerPartT m)
children
        case XML
xml of
         CDATA Bool
_ Text
_       -> XML -> XMLGenT (ServerPartT m) XML
forall (m :: * -> *) a. Monad m => a -> m a
return XML
xml
         Element NSName
n [Attribute]
as [XML]
cs -> XML -> XMLGenT (ServerPartT m) XML
forall (m :: * -> *) a. Monad m => a -> m a
return (XML -> XMLGenT (ServerPartT m) XML)
-> XML -> XMLGenT (ServerPartT m) XML
forall a b. (a -> b) -> a -> b
$ NSName -> [Attribute] -> [XML] -> XML
Element NSName
n [Attribute]
as ([XML]
cs [XML] -> [XML] -> [XML]
forall a. [a] -> [a] -> [a]
++ ((ChildType (ServerPartT m) -> XML)
-> [ChildType (ServerPartT m)] -> [XML]
forall a b. (a -> b) -> [a] -> [b]
map ChildType (ServerPartT m) -> XML
forall (m :: * -> *). ChildType (ServerPartT m) -> XML
unSChild [ChildType (ServerPartT m)]
chs))

instance (Functor m, Monad m) => SetAttr (ServerPartT m) XML where
 setAll :: XML -> GenAttributeList (ServerPartT m) -> GenXML (ServerPartT m)
setAll XML
xml GenAttributeList (ServerPartT m)
hats = do
        [AttributeType (ServerPartT m)]
attrs <- GenAttributeList (ServerPartT m)
hats
        case XML
xml of
         CDATA Bool
_ Text
_       -> XML -> XMLGenT (ServerPartT m) XML
forall (m :: * -> *) a. Monad m => a -> m a
return XML
xml
         Element NSName
n [Attribute]
as [XML]
cs -> XML -> XMLGenT (ServerPartT m) XML
forall (m :: * -> *) a. Monad m => a -> m a
return (XML -> XMLGenT (ServerPartT m) XML)
-> XML -> XMLGenT (ServerPartT m) XML
forall a b. (a -> b) -> a -> b
$ NSName -> [Attribute] -> [XML] -> XML
Element NSName
n ((Attribute -> [Attribute] -> [Attribute])
-> [Attribute] -> [Attribute] -> [Attribute]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (:) [Attribute]
as ((AttributeType (ServerPartT m) -> Attribute)
-> [AttributeType (ServerPartT m)] -> [Attribute]
forall a b. (a -> b) -> [a] -> [b]
map AttributeType (ServerPartT m) -> Attribute
forall (m :: * -> *). AttributeType (ServerPartT m) -> Attribute
unSAttr [AttributeType (ServerPartT m)]
attrs)) [XML]
cs

instance (Functor m, Monad m) => XMLGenerator (ServerPartT m)