--------------------------------------------------------------------
-- |
-- Module    : Text.RSS.Export
-- Copyright : (c) Galois, Inc. 2008,
--             (c) Sigbjorn Finne 2009-
-- License   : BSD3
--
-- Maintainer: Sigbjorn Finne <sof@forkIO.com>
-- Stability : provisional
-- Description: Convert from RSS to XML
--
--------------------------------------------------------------------
module Text.RSS.Export
  ( qualNode
  , qualName
  , xmlRSS
  , textRSS
  , xmlChannel
  , xmlItem
  , xmlSource
  , xmlEnclosure
  , xmlCategory
  , xmlGuid
  , xmlImage
  , xmlCloud
  , xmlTextInput
  , xmlSkipHours
  , xmlSkipDays
  , xmlAttr
  , xmlLeaf
  , mb
  ) where

import Prelude.Compat

import qualified Data.Text.Util as U
import Data.XML.Compat
import Data.XML.Types as XML
import Text.RSS.Syntax

import Data.Text (Text, pack)
import qualified Data.Text.Lazy as TL

qualName :: Text -> XML.Name
qualName :: Text -> Name
qualName Text
n = Text -> Maybe Text -> Maybe Text -> Name
Name Text
n Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing

qualNode :: Text -> [XML.Node] -> XML.Element
qualNode :: Text -> [Node] -> Element
qualNode Text
n = Name -> [(Name, [Content])] -> [Node] -> Element
Element (Text -> Maybe Text -> Maybe Text -> Name
Name Text
n Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing) []

---
xmlRSS :: RSS -> XML.Element
xmlRSS :: RSS -> Element
xmlRSS RSS
r =
  (Text -> [Node] -> Element
qualNode Text
"rss" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$ (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement (RSSChannel -> Element
xmlChannel (RSS -> RSSChannel
rssChannel RSS
r) Element -> [Element] -> [Element]
forall a. a -> [a] -> [a]
: RSS -> [Element]
rssOther RSS
r))
    {elementAttributes :: [(Name, [Content])]
elementAttributes = Text -> Text -> (Name, [Content])
mkAttr Text
"version" (RSS -> Text
rssVersion RSS
r) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> [a] -> [a]
: RSS -> [(Name, [Content])]
rssAttrs RSS
r}

textRSS :: RSS -> Maybe TL.Text
textRSS :: RSS -> Maybe Text
textRSS = (RSS -> Element) -> RSS -> Maybe Text
forall a. (a -> Element) -> a -> Maybe Text
U.renderFeed RSS -> Element
xmlRSS

xmlChannel :: RSSChannel -> XML.Element
xmlChannel :: RSSChannel -> Element
xmlChannel RSSChannel
ch =
  Text -> [Node] -> Element
qualNode Text
"channel" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$
  (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map
    Element -> Node
NodeElement
    ([ Text -> Text -> Element
xmlLeaf Text
"title" (RSSChannel -> Text
rssTitle RSSChannel
ch)
     , Text -> Text -> Element
xmlLeaf Text
"link" (RSSChannel -> Text
rssLink RSSChannel
ch)
     , Text -> Text -> Element
xmlLeaf Text
"description" (RSSChannel -> Text
rssDescription RSSChannel
ch)
     ] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (RSSItem -> Element) -> [RSSItem] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map RSSItem -> Element
xmlItem (RSSChannel -> [RSSItem]
rssItems RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"language") (RSSChannel -> Maybe Text
rssLanguage RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"copyright") (RSSChannel -> Maybe Text
rssCopyright RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"managingEditor") (RSSChannel -> Maybe Text
rssEditor RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"webMaster") (RSSChannel -> Maybe Text
rssWebMaster RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"pubDate") (RSSChannel -> Maybe Text
rssPubDate RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"lastBuildDate") (RSSChannel -> Maybe Text
rssLastUpdate RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (RSSCategory -> Element) -> [RSSCategory] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map RSSCategory -> Element
xmlCategory (RSSChannel -> [RSSCategory]
rssCategories RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"generator") (RSSChannel -> Maybe Text
rssGenerator RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"docs") (RSSChannel -> Maybe Text
rssDocs RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (RSSCloud -> Element) -> Maybe RSSCloud -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb RSSCloud -> Element
xmlCloud (RSSChannel -> Maybe RSSCloud
rssCloud RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Integer -> Element) -> Maybe Integer -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"ttl" (Text -> Element) -> (Integer -> Text) -> Integer -> Element
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack (String -> Text) -> (Integer -> String) -> Integer -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show) (RSSChannel -> Maybe Integer
rssTTL RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (RSSImage -> Element) -> Maybe RSSImage -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb RSSImage -> Element
xmlImage (RSSChannel -> Maybe RSSImage
rssImage RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"rating") (RSSChannel -> Maybe Text
rssRating RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (RSSTextInput -> Element) -> Maybe RSSTextInput -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb RSSTextInput -> Element
xmlTextInput (RSSChannel -> Maybe RSSTextInput
rssTextInput RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     ([Integer] -> Element) -> Maybe [Integer] -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb [Integer] -> Element
xmlSkipHours (RSSChannel -> Maybe [Integer]
rssSkipHours RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ ([Text] -> Element) -> Maybe [Text] -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb [Text] -> Element
xmlSkipDays (RSSChannel -> Maybe [Text]
rssSkipDays RSSChannel
ch) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ RSSChannel -> [Element]
rssChannelOther RSSChannel
ch)

xmlItem :: RSSItem -> XML.Element
xmlItem :: RSSItem -> Element
xmlItem RSSItem
it =
  (Text -> [Node] -> Element
qualNode Text
"item" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$
   (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map
     Element -> Node
NodeElement
     ((Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"title") (RSSItem -> Maybe Text
rssItemTitle RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"link") (RSSItem -> Maybe Text
rssItemLink RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"description") (RSSItem -> Maybe Text
rssItemDescription RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"author") (RSSItem -> Maybe Text
rssItemAuthor RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (RSSCategory -> Element) -> [RSSCategory] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map RSSCategory -> Element
xmlCategory (RSSItem -> [RSSCategory]
rssItemCategories RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"comments") (RSSItem -> Maybe Text
rssItemComments RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (RSSEnclosure -> Element) -> Maybe RSSEnclosure -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb RSSEnclosure -> Element
xmlEnclosure (RSSItem -> Maybe RSSEnclosure
rssItemEnclosure RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (RSSGuid -> Element) -> Maybe RSSGuid -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb RSSGuid -> Element
xmlGuid (RSSItem -> Maybe RSSGuid
rssItemGuid RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"pubDate") (RSSItem -> Maybe Text
rssItemPubDate RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      (RSSSource -> Element) -> Maybe RSSSource -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb RSSSource -> Element
xmlSource (RSSItem -> Maybe RSSSource
rssItemSource RSSItem
it) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ RSSItem -> [Element]
rssItemOther RSSItem
it))
    {elementAttributes :: [(Name, [Content])]
elementAttributes = RSSItem -> [(Name, [Content])]
rssItemAttrs RSSItem
it}

xmlSource :: RSSSource -> XML.Element
xmlSource :: RSSSource -> Element
xmlSource RSSSource
s =
  (Text -> Text -> Element
xmlLeaf Text
"source" (RSSSource -> Text
rssSourceTitle RSSSource
s))
    {elementAttributes :: [(Name, [Content])]
elementAttributes = Text -> Text -> (Name, [Content])
mkAttr Text
"url" (RSSSource -> Text
rssSourceURL RSSSource
s) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> [a] -> [a]
: RSSSource -> [(Name, [Content])]
rssSourceAttrs RSSSource
s}

xmlEnclosure :: RSSEnclosure -> XML.Element
xmlEnclosure :: RSSEnclosure -> Element
xmlEnclosure RSSEnclosure
e =
  (Text -> Text -> Element
xmlLeaf Text
"enclosure" Text
"")
    { elementAttributes :: [(Name, [Content])]
elementAttributes =
        Text -> Text -> (Name, [Content])
mkAttr Text
"url" (RSSEnclosure -> Text
rssEnclosureURL RSSEnclosure
e) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> [a] -> [a]
:
        Text -> Text -> (Name, [Content])
mkAttr Text
"type" (RSSEnclosure -> Text
rssEnclosureType RSSEnclosure
e) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> [a] -> [a]
:
        (Integer -> (Name, [Content]))
-> Maybe Integer -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
mkAttr Text
"length" (Text -> (Name, [Content]))
-> (Integer -> Text) -> Integer -> (Name, [Content])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack (String -> Text) -> (Integer -> String) -> Integer -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show) (RSSEnclosure -> Maybe Integer
rssEnclosureLength RSSEnclosure
e) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++ RSSEnclosure -> [(Name, [Content])]
rssEnclosureAttrs RSSEnclosure
e
    }

xmlCategory :: RSSCategory -> XML.Element
xmlCategory :: RSSCategory -> Element
xmlCategory RSSCategory
c =
  (Text -> Text -> Element
xmlLeaf Text
"category" (RSSCategory -> Text
rssCategoryValue RSSCategory
c))
    { elementAttributes :: [(Name, [Content])]
elementAttributes =
        ([(Name, [Content])] -> [(Name, [Content])])
-> (Text -> [(Name, [Content])] -> [(Name, [Content])])
-> Maybe Text
-> [(Name, [Content])]
-> [(Name, [Content])]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> a
id (\Text
n -> (Text -> Text -> (Name, [Content])
mkAttr Text
"domain" Text
n (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> [a] -> [a]
:)) (RSSCategory -> Maybe Text
rssCategoryDomain RSSCategory
c) (RSSCategory -> [(Name, [Content])]
rssCategoryAttrs RSSCategory
c)
    }

xmlGuid :: RSSGuid -> XML.Element
xmlGuid :: RSSGuid -> Element
xmlGuid RSSGuid
g =
  (Text -> Text -> Element
xmlLeaf Text
"guid" (RSSGuid -> Text
rssGuidValue RSSGuid
g))
    { elementAttributes :: [(Name, [Content])]
elementAttributes =
        ([(Name, [Content])] -> [(Name, [Content])])
-> (Bool -> [(Name, [Content])] -> [(Name, [Content])])
-> Maybe Bool
-> [(Name, [Content])]
-> [(Name, [Content])]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
          [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> a
id
          (\Bool
n -> (Text -> Text -> (Name, [Content])
mkAttr Text
"isPermaLink" (Bool -> Text
forall p. IsString p => Bool -> p
toBool Bool
n) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> [a] -> [a]
:))
          (RSSGuid -> Maybe Bool
rssGuidPermanentURL RSSGuid
g)
          (RSSGuid -> [(Name, [Content])]
rssGuidAttrs RSSGuid
g)
    }
  where
    toBool :: Bool -> p
toBool Bool
False = p
"false"
    toBool Bool
_ = p
"true"

xmlImage :: RSSImage -> XML.Element
xmlImage :: RSSImage -> Element
xmlImage RSSImage
im =
  Text -> [Node] -> Element
qualNode Text
"image" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$
  (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map
    Element -> Node
NodeElement
    ([ Text -> Text -> Element
xmlLeaf Text
"url" (RSSImage -> Text
rssImageURL RSSImage
im)
     , Text -> Text -> Element
xmlLeaf Text
"title" (RSSImage -> Text
rssImageTitle RSSImage
im)
     , Text -> Text -> Element
xmlLeaf Text
"link" (RSSImage -> Text
rssImageLink RSSImage
im)
     ] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Integer -> Element) -> Maybe Integer -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"width" (Text -> Element) -> (Integer -> Text) -> Integer -> Element
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack (String -> Text) -> (Integer -> String) -> Integer -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show) (RSSImage -> Maybe Integer
rssImageWidth RSSImage
im) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Integer -> Element) -> Maybe Integer -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"height" (Text -> Element) -> (Integer -> Text) -> Integer -> Element
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack (String -> Text) -> (Integer -> String) -> Integer -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show) (RSSImage -> Maybe Integer
rssImageHeight RSSImage
im) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
     (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
xmlLeaf Text
"description") (RSSImage -> Maybe Text
rssImageDesc RSSImage
im) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ RSSImage -> [Element]
rssImageOther RSSImage
im)

xmlCloud :: RSSCloud -> XML.Element
xmlCloud :: RSSCloud -> Element
xmlCloud RSSCloud
cl =
  (Text -> Text -> Element
xmlLeaf Text
"cloud" Text
"")
    { elementAttributes :: [(Name, [Content])]
elementAttributes =
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
mkAttr Text
"domain") (RSSCloud -> Maybe Text
rssCloudDomain RSSCloud
cl) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
mkAttr Text
"port") (RSSCloud -> Maybe Text
rssCloudPort RSSCloud
cl) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
mkAttr Text
"path") (RSSCloud -> Maybe Text
rssCloudPath RSSCloud
cl) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
mkAttr Text
"registerProcedure") (RSSCloud -> Maybe Text
rssCloudRegisterProcedure RSSCloud
cl) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
mkAttr Text
"protocol") (RSSCloud -> Maybe Text
rssCloudProtocol RSSCloud
cl) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++ RSSCloud -> [(Name, [Content])]
rssCloudAttrs RSSCloud
cl
    }

xmlTextInput :: RSSTextInput -> XML.Element
xmlTextInput :: RSSTextInput -> Element
xmlTextInput RSSTextInput
ti =
  (Text -> [Node] -> Element
qualNode Text
"textInput" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$
   (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map
     Element -> Node
NodeElement
     ([ Text -> Text -> Element
xmlLeaf Text
"title" (RSSTextInput -> Text
rssTextInputTitle RSSTextInput
ti)
      , Text -> Text -> Element
xmlLeaf Text
"description" (RSSTextInput -> Text
rssTextInputDesc RSSTextInput
ti)
      , Text -> Text -> Element
xmlLeaf Text
"name" (RSSTextInput -> Text
rssTextInputName RSSTextInput
ti)
      , Text -> Text -> Element
xmlLeaf Text
"link" (RSSTextInput -> Text
rssTextInputLink RSSTextInput
ti)
      ] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
      RSSTextInput -> [Element]
rssTextInputOther RSSTextInput
ti))
    {elementAttributes :: [(Name, [Content])]
elementAttributes = RSSTextInput -> [(Name, [Content])]
rssTextInputAttrs RSSTextInput
ti}

xmlSkipHours :: [Integer] -> XML.Element
xmlSkipHours :: [Integer] -> Element
xmlSkipHours [Integer]
hs =
  Text -> [Node] -> Element
qualNode Text
"skipHours" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$ (Integer -> Node) -> [Integer] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map (Element -> Node
NodeElement (Element -> Node) -> (Integer -> Element) -> Integer -> Node
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Integer
n -> Text -> Text -> Element
xmlLeaf Text
"hour" (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Integer -> String
forall a. Show a => a -> String
show Integer
n))) [Integer]
hs

xmlSkipDays :: [Text] -> XML.Element
xmlSkipDays :: [Text] -> Element
xmlSkipDays [Text]
hs = Text -> [Node] -> Element
qualNode Text
"skipDays" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$ (Text -> Node) -> [Text] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map (Element -> Node
NodeElement (Element -> Node) -> (Text -> Element) -> Text -> Node
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Element
xmlLeaf Text
"day") [Text]
hs

xmlAttr :: Text -> Text -> Attr
xmlAttr :: Text -> Text -> (Name, [Content])
xmlAttr Text
k = Name -> Text -> (Name, [Content])
mkNAttr (Text -> Name
qualName Text
k)

xmlLeaf :: Text -> Text -> XML.Element
xmlLeaf :: Text -> Text -> Element
xmlLeaf Text
tg Text
txt =
  Element :: Name -> [(Name, [Content])] -> [Node] -> Element
Element
    { elementAttributes :: [(Name, [Content])]
elementAttributes = []
    , elementName :: Name
elementName = Text -> Maybe Text -> Maybe Text -> Name
Name Text
tg Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing
    , elementNodes :: [Node]
elementNodes = [Content -> Node
NodeContent (Text -> Content
ContentText Text
txt)]
    }

---
mb :: (a -> b) -> Maybe a -> [b]
mb :: (a -> b) -> Maybe a -> [b]
mb a -> b
_ Maybe a
Nothing = []
mb a -> b
f (Just a
x) = [a -> b
f a
x]