{-# LANGUAGE OverloadedStrings #-}
-- | Streaming renderers for the RSS 2.0 standard.
module Text.RSS.Conduit.Render
  ( -- * Top-level
    renderRssDocument
    -- * Elements
  , renderRssItem
  , renderRssSource
  , renderRssEnclosure
  , renderRssGuid
  , renderRssCloud
  , renderRssCategory
  , renderRssImage
  , renderRssTextInput
  , renderRssSkipDays
  , renderRssSkipHours
  ) where

-- {{{ Imports
import           Text.RSS.Extensions
import           Text.RSS.Lens
import           Text.RSS.Types

import           Control.Monad
import           Data.Conduit
import           Data.Monoid
import           Data.Set               (Set)
import qualified Data.Set               as Set
import           Data.Text              as Text hiding (map)
import           Data.Text.Encoding
import           Data.Time.Clock
import           Data.Time.LocalTime
import           Data.Time.RFC822
import           Data.Version
import           Data.XML.Types
import           Lens.Micro
import           Lens.Micro.Extras
import           Safe
import           Text.XML.Stream.Render
import           URI.ByteString
-- }}}

-- | Render the top-level @\<rss\>@ element.
renderRssDocument :: Monad m => RenderRssExtension e => RssDocument e -> ConduitT () Event m ()
renderRssDocument :: RssDocument e -> ConduitT () Event m ()
renderRssDocument RssDocument e
d = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"rss" (Name -> Text -> Attributes
attr Name
"version" (Text -> Attributes) -> (Version -> Text) -> Version -> Attributes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
pack (String -> Text) -> (Version -> String) -> Version -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Version -> String
showVersion (Version -> Attributes) -> Version -> Attributes
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Version (RssDocument e) Version -> Version
forall s a. s -> Getting a s a -> a
^.Getting Version (RssDocument e) Version
forall extensions. Lens' (RssDocument extensions) Version
documentVersionL) (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$
  Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"channel" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ do
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"title" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelTitleL
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"link" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssURI -> Text
renderRssURI (RssURI -> Text) -> RssURI -> Text
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting RssURI (RssDocument e) RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI (RssDocument e) RssURI
forall extensions. Lens' (RssDocument extensions) RssURI
channelLinkL
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"description" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelDescriptionL
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"copyright" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelCopyrightL
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"language" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelLanguageL
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"managingEditor" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelManagingEditorL
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"webMaster" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelWebmasterL
    Maybe UTCTime
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting (Maybe UTCTime) (RssDocument e) (Maybe UTCTime)
-> Maybe UTCTime
forall s a. s -> Getting a s a -> a
^.Getting (Maybe UTCTime) (RssDocument e) (Maybe UTCTime)
forall extensions. Lens' (RssDocument extensions) (Maybe UTCTime)
channelPubDateL) ((UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> UTCTime -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> UTCTime -> ConduitT () Event m ()
dateTag Name
"pubDate"
    Maybe UTCTime
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting (Maybe UTCTime) (RssDocument e) (Maybe UTCTime)
-> Maybe UTCTime
forall s a. s -> Getting a s a -> a
^.Getting (Maybe UTCTime) (RssDocument e) (Maybe UTCTime)
forall extensions. Lens' (RssDocument extensions) (Maybe UTCTime)
channelLastBuildDateL) ((UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> UTCTime -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> UTCTime -> ConduitT () Event m ()
dateTag Name
"lastBuildDate"
    [RssCategory]
-> (RssCategory -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting [RssCategory] (RssDocument e) [RssCategory]
-> [RssCategory]
forall s a. s -> Getting a s a -> a
^.Getting [RssCategory] (RssDocument e) [RssCategory]
forall extensions. Lens' (RssDocument extensions) [RssCategory]
channelCategoriesL) RssCategory -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
RssCategory -> ConduitT () Event m ()
renderRssCategory
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"generator" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelGeneratorL
    Maybe RssURI
-> (RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting (Maybe RssURI) (RssDocument e) (Maybe RssURI)
-> Maybe RssURI
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssURI) (RssDocument e) (Maybe RssURI)
forall extensions. Lens' (RssDocument extensions) (Maybe RssURI)
channelDocsL) ((RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"docs" (Text -> ConduitT () Event m ())
-> (RssURI -> Text) -> RssURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RssURI -> Text
renderRssURI
    Maybe RssCloud
-> (RssCloud -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting (Maybe RssCloud) (RssDocument e) (Maybe RssCloud)
-> Maybe RssCloud
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssCloud) (RssDocument e) (Maybe RssCloud)
forall extensions. Lens' (RssDocument extensions) (Maybe RssCloud)
channelCloudL) RssCloud -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => RssCloud -> ConduitT () Event m ()
renderRssCloud
    Maybe Int
-> (Int -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting (Maybe Int) (RssDocument e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) (RssDocument e) (Maybe Int)
forall extensions. Lens' (RssDocument extensions) (Maybe Int)
channelTtlL) ((Int -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (Int -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"ttl" (Text -> ConduitT () Event m ())
-> (Int -> Text) -> Int -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
forall a. Show a => a -> Text
tshow
    Maybe RssImage
-> (RssImage -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting (Maybe RssImage) (RssDocument e) (Maybe RssImage)
-> Maybe RssImage
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssImage) (RssDocument e) (Maybe RssImage)
forall extensions. Lens' (RssDocument extensions) (Maybe RssImage)
channelImageL) RssImage -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => RssImage -> ConduitT () Event m ()
renderRssImage
    Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"rating" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e -> Getting Text (RssDocument e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssDocument e) Text
forall extensions. Lens' (RssDocument extensions) Text
channelRatingL
    Maybe RssTextInput
-> (RssTextInput -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting
     (Maybe RssTextInput) (RssDocument e) (Maybe RssTextInput)
-> Maybe RssTextInput
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssTextInput) (RssDocument e) (Maybe RssTextInput)
forall extensions.
Lens' (RssDocument extensions) (Maybe RssTextInput)
channelTextInputL) RssTextInput -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
RssTextInput -> ConduitT () Event m ()
renderRssTextInput
    Set Hour -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => Set Hour -> ConduitT () Event m ()
renderRssSkipHours (Set Hour -> ConduitT () Event m ())
-> Set Hour -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e
-> Getting (Set Hour) (RssDocument e) (Set Hour) -> Set Hour
forall s a. s -> Getting a s a -> a
^.Getting (Set Hour) (RssDocument e) (Set Hour)
forall extensions. Lens' (RssDocument extensions) (Set Hour)
channelSkipHoursL
    Set Day -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => Set Day -> ConduitT () Event m ()
renderRssSkipDays (Set Day -> ConduitT () Event m ())
-> Set Day -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e
-> Getting (Set Day) (RssDocument e) (Set Day) -> Set Day
forall s a. s -> Getting a s a -> a
^.Getting (Set Day) (RssDocument e) (Set Day)
forall extensions. Lens' (RssDocument extensions) (Set Day)
channelSkipDaysL
    [RssItem e]
-> (RssItem e -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssDocument e
dRssDocument e
-> Getting [RssItem e] (RssDocument e) [RssItem e] -> [RssItem e]
forall s a. s -> Getting a s a -> a
^.Getting [RssItem e] (RssDocument e) [RssItem e]
forall extensions.
Lens' (RssDocument extensions) [RssItem extensions]
channelItemsL) RssItem e -> ConduitT () Event m ()
forall (m :: * -> *) e.
(Monad m, RenderRssExtension e) =>
RssItem e -> ConduitT () Event m ()
renderRssItem
    RssChannelExtension e -> ConduitT () Event m ()
forall e (m :: * -> *).
(RenderRssExtension e, Monad m) =>
RssChannelExtension e -> ConduitT () Event m ()
renderRssChannelExtension (RssChannelExtension e -> ConduitT () Event m ())
-> RssChannelExtension e -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssDocument e
dRssDocument e
-> Getting
     (RssChannelExtension e) (RssDocument e) (RssChannelExtension e)
-> RssChannelExtension e
forall s a. s -> Getting a s a -> a
^.Getting
  (RssChannelExtension e) (RssDocument e) (RssChannelExtension e)
forall extensions.
Lens' (RssDocument extensions) (RssChannelExtension extensions)
channelExtensionsL

-- | Render an @\<item\>@ element.
renderRssItem :: Monad m => RenderRssExtension e => RssItem e -> ConduitT () Event m ()
renderRssItem :: RssItem e -> ConduitT () Event m ()
renderRssItem RssItem e
i = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"item" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ do
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"title" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssItem e
iRssItem e -> Getting Text (RssItem e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssItem e) Text
forall extensions. Lens' (RssItem extensions) Text
itemTitleL
  Maybe RssURI
-> (RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssItem e
iRssItem e
-> Getting (Maybe RssURI) (RssItem e) (Maybe RssURI)
-> Maybe RssURI
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssURI) (RssItem e) (Maybe RssURI)
forall extensions. Lens' (RssItem extensions) (Maybe RssURI)
itemLinkL) ((RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"link" (Text -> ConduitT () Event m ())
-> (RssURI -> Text) -> RssURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RssURI -> Text
renderRssURI
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"description" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssItem e
iRssItem e -> Getting Text (RssItem e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssItem e) Text
forall extensions. Lens' (RssItem extensions) Text
itemDescriptionL
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"author" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssItem e
iRssItem e -> Getting Text (RssItem e) Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text (RssItem e) Text
forall extensions. Lens' (RssItem extensions) Text
itemAuthorL
  [RssCategory]
-> (RssCategory -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssItem e
iRssItem e
-> Getting [RssCategory] (RssItem e) [RssCategory] -> [RssCategory]
forall s a. s -> Getting a s a -> a
^.Getting [RssCategory] (RssItem e) [RssCategory]
forall extensions. Lens' (RssItem extensions) [RssCategory]
itemCategoriesL) RssCategory -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
RssCategory -> ConduitT () Event m ()
renderRssCategory
  Maybe RssURI
-> (RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssItem e
iRssItem e
-> Getting (Maybe RssURI) (RssItem e) (Maybe RssURI)
-> Maybe RssURI
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssURI) (RssItem e) (Maybe RssURI)
forall extensions. Lens' (RssItem extensions) (Maybe RssURI)
itemCommentsL) ((RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (RssURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"comments" (Text -> ConduitT () Event m ())
-> (RssURI -> Text) -> RssURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RssURI -> Text
renderRssURI
  [RssEnclosure]
-> (RssEnclosure -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssItem e
iRssItem e
-> Getting [RssEnclosure] (RssItem e) [RssEnclosure]
-> [RssEnclosure]
forall s a. s -> Getting a s a -> a
^.Getting [RssEnclosure] (RssItem e) [RssEnclosure]
forall extensions. Lens' (RssItem extensions) [RssEnclosure]
itemEnclosureL) RssEnclosure -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
RssEnclosure -> ConduitT () Event m ()
renderRssEnclosure
  Maybe RssGuid
-> (RssGuid -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssItem e
iRssItem e
-> Getting (Maybe RssGuid) (RssItem e) (Maybe RssGuid)
-> Maybe RssGuid
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssGuid) (RssItem e) (Maybe RssGuid)
forall extensions. Lens' (RssItem extensions) (Maybe RssGuid)
itemGuidL) RssGuid -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => RssGuid -> ConduitT () Event m ()
renderRssGuid
  Maybe UTCTime
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssItem e
iRssItem e
-> Getting (Maybe UTCTime) (RssItem e) (Maybe UTCTime)
-> Maybe UTCTime
forall s a. s -> Getting a s a -> a
^.Getting (Maybe UTCTime) (RssItem e) (Maybe UTCTime)
forall extensions. Lens' (RssItem extensions) (Maybe UTCTime)
itemPubDateL) ((UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> UTCTime -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> UTCTime -> ConduitT () Event m ()
dateTag Name
"pubDate"
  Maybe RssSource
-> (RssSource -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssItem e
iRssItem e
-> Getting (Maybe RssSource) (RssItem e) (Maybe RssSource)
-> Maybe RssSource
forall s a. s -> Getting a s a -> a
^.Getting (Maybe RssSource) (RssItem e) (Maybe RssSource)
forall extensions. Lens' (RssItem extensions) (Maybe RssSource)
itemSourceL) RssSource -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
RssSource -> ConduitT () Event m ()
renderRssSource
  RssItemExtension e -> ConduitT () Event m ()
forall e (m :: * -> *).
(RenderRssExtension e, Monad m) =>
RssItemExtension e -> ConduitT () Event m ()
renderRssItemExtension (RssItemExtension e -> ConduitT () Event m ())
-> RssItemExtension e -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssItem e
iRssItem e
-> Getting (RssItemExtension e) (RssItem e) (RssItemExtension e)
-> RssItemExtension e
forall s a. s -> Getting a s a -> a
^.Getting (RssItemExtension e) (RssItem e) (RssItemExtension e)
forall extensions extensions2.
Lens
  (RssItem extensions)
  (RssItem extensions2)
  (RssItemExtension extensions)
  (RssItemExtension extensions2)
itemExtensionsL

-- | Render a @\<source\>@ element.
renderRssSource :: (Monad m) => RssSource -> ConduitT () Event m ()
renderRssSource :: RssSource -> ConduitT () Event m ()
renderRssSource RssSource
s = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"source" (Name -> Text -> Attributes
attr Name
"url" (Text -> Attributes) -> Text -> Attributes
forall a b. (a -> b) -> a -> b
$ RssURI -> Text
renderRssURI (RssURI -> Text) -> RssURI -> Text
forall a b. (a -> b) -> a -> b
$ RssSource
sRssSource -> Getting RssURI RssSource RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssSource RssURI
Lens' RssSource RssURI
sourceUrlL) (ConduitT () Event m () -> ConduitT () Event m ())
-> (Text -> ConduitT () Event m ())
-> Text
-> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ConduitT () Event m ()
forall (m :: * -> *) i. Monad m => Text -> ConduitT i Event m ()
content (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssSource
sRssSource -> Getting Text RssSource Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssSource Text
Lens' RssSource Text
sourceNameL

-- | Render an @\<enclosure\>@ element.
renderRssEnclosure :: (Monad m) => RssEnclosure -> ConduitT () Event m ()
renderRssEnclosure :: RssEnclosure -> ConduitT () Event m ()
renderRssEnclosure RssEnclosure
e = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"enclosure" Attributes
attributes ConduitT () Event m ()
forall a. Monoid a => a
mempty where
  attributes :: Attributes
attributes = Name -> Text -> Attributes
attr Name
"url" (RssURI -> Text
renderRssURI (RssURI -> Text) -> RssURI -> Text
forall a b. (a -> b) -> a -> b
$ RssEnclosure
eRssEnclosure -> Getting RssURI RssEnclosure RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssEnclosure RssURI
Lens' RssEnclosure RssURI
enclosureUrlL)
    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
attr Name
"length" (Int -> Text
forall a. Show a => a -> Text
tshow (Int -> Text) -> Int -> Text
forall a b. (a -> b) -> a -> b
$ RssEnclosure
eRssEnclosure -> Getting Int RssEnclosure Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int RssEnclosure Int
Lens' RssEnclosure Int
enclosureLengthL)
    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
attr Name
"type" (RssEnclosure
eRssEnclosure -> Getting Text RssEnclosure Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssEnclosure Text
Lens' RssEnclosure Text
enclosureTypeL)

-- | Render a @\<guid\>@ element.
renderRssGuid :: (Monad m) => RssGuid -> ConduitT () Event m ()
renderRssGuid :: RssGuid -> ConduitT () Event m ()
renderRssGuid (GuidUri RssURI
u) = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"guid" (Name -> Text -> Attributes
attr Name
"isPermaLink" Text
"true") (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> ConduitT () Event m ()
forall (m :: * -> *) i. Monad m => Text -> ConduitT i Event m ()
content (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssURI -> Text
renderRssURI RssURI
u
renderRssGuid (GuidText Text
t) = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"guid" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> ConduitT () Event m ()
forall (m :: * -> *) i. Monad m => Text -> ConduitT i Event m ()
content Text
t


-- | Render a @\<cloud\>@ element.
renderRssCloud :: Monad m => RssCloud -> ConduitT () Event m ()
renderRssCloud :: RssCloud -> ConduitT () Event m ()
renderRssCloud RssCloud
c = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"cloud" Attributes
attributes (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ () -> ConduitT () Event m ()
forall (m :: * -> *) a. Monad m => a -> m a
return () where
  attributes :: Attributes
attributes = Name -> Text -> Attributes
attr Name
"domain" Text
domain
    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Maybe Text -> Attributes
optionalAttr Name
"port" Maybe Text
port
    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
attr Name
"path" (Text
path Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
query Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
fragment)
    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
attr Name
"registerProcedure" (RssCloud
cRssCloud -> Getting Text RssCloud Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssCloud Text
Lens' RssCloud Text
cloudRegisterProcedureL)
    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
attr Name
"protocol" (CloudProtocol -> Text
forall p. IsString p => CloudProtocol -> p
describe (CloudProtocol -> Text) -> CloudProtocol -> Text
forall a b. (a -> b) -> a -> b
$ RssCloud
cRssCloud
-> Getting CloudProtocol RssCloud CloudProtocol -> CloudProtocol
forall s a. s -> Getting a s a -> a
^.Getting CloudProtocol RssCloud CloudProtocol
Lens' RssCloud CloudProtocol
cloudProtocolL)

  renderUserInfo :: Maybe UserInfo -> Text
renderUserInfo (Just (UserInfo ByteString
a ByteString
b)) = ByteString -> Text
decodeUtf8 ByteString
a Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
decodeUtf8 ByteString
b Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"@"
  renderUserInfo Maybe UserInfo
_ = Text
""
  renderHost :: Host -> Text
renderHost (Host ByteString
h) = ByteString -> Text
decodeUtf8 ByteString
h
  renderQuery :: Query -> Text
renderQuery (Query [(ByteString, ByteString)]
query) = case Text -> [Text] -> Text
intercalate Text
"&" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ ((ByteString, ByteString) -> Text)
-> [(ByteString, ByteString)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (\(ByteString
a,ByteString
b) -> ByteString -> Text
decodeUtf8 ByteString
a Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
decodeUtf8 ByteString
b) [(ByteString, ByteString)]
query of
    Text
"" -> Text
""
    Text
x  -> Text
"?" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x

  domain :: Text
domain = Text -> (Authority -> Text) -> Maybe Authority -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (\Authority
a -> Maybe UserInfo -> Text
renderUserInfo (Authority -> Maybe UserInfo
authorityUserInfo Authority
a) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Host -> Text
renderHost (Authority -> Host
authorityHost Authority
a)) (Maybe Authority -> Text) -> Maybe Authority -> Text
forall a b. (a -> b) -> a -> b
$ (forall a. URIRef a -> Maybe Authority)
-> RssURI -> Maybe Authority
forall b. (forall a. URIRef a -> b) -> RssURI -> b
withRssURI (Getting (Maybe Authority) (URIRef a) (Maybe Authority)
-> URIRef a -> Maybe Authority
forall a s. Getting a s a -> s -> a
view Getting (Maybe Authority) (URIRef a) (Maybe Authority)
forall a. Lens' (URIRef a) (Maybe Authority)
authorityL) (RssURI -> Maybe Authority) -> RssURI -> Maybe Authority
forall a b. (a -> b) -> a -> b
$ RssCloud
cRssCloud -> Getting RssURI RssCloud RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssCloud RssURI
Lens' RssCloud RssURI
cloudUriL
  port :: Maybe Text
port = (Port -> Text) -> Maybe Port -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (String -> Text
pack (String -> Text) -> (Port -> String) -> Port -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> String) -> (Port -> Int) -> Port -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Port -> Int
portNumber) (Maybe Port -> Maybe Text) -> Maybe Port -> Maybe Text
forall a b. (a -> b) -> a -> b
$ Authority -> Maybe Port
authorityPort (Authority -> Maybe Port) -> Maybe Authority -> Maybe Port
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall a. URIRef a -> Maybe Authority)
-> RssURI -> Maybe Authority
forall b. (forall a. URIRef a -> b) -> RssURI -> b
withRssURI (Getting (Maybe Authority) (URIRef a) (Maybe Authority)
-> URIRef a -> Maybe Authority
forall a s. Getting a s a -> s -> a
view Getting (Maybe Authority) (URIRef a) (Maybe Authority)
forall a. Lens' (URIRef a) (Maybe Authority)
authorityL) (RssCloud
cRssCloud -> Getting RssURI RssCloud RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssCloud RssURI
Lens' RssCloud RssURI
cloudUriL)
  path :: Text
path = ByteString -> Text
decodeUtf8 (ByteString -> Text) -> ByteString -> Text
forall a b. (a -> b) -> a -> b
$ (forall a. URIRef a -> ByteString) -> RssURI -> ByteString
forall b. (forall a. URIRef a -> b) -> RssURI -> b
withRssURI (Getting ByteString (URIRef a) ByteString -> URIRef a -> ByteString
forall a s. Getting a s a -> s -> a
view Getting ByteString (URIRef a) ByteString
forall a. Lens' (URIRef a) ByteString
pathL) (RssURI -> ByteString) -> RssURI -> ByteString
forall a b. (a -> b) -> a -> b
$ RssCloud
cRssCloud -> Getting RssURI RssCloud RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssCloud RssURI
Lens' RssCloud RssURI
cloudUriL
  query :: Text
query = Query -> Text
renderQuery (Query -> Text) -> Query -> Text
forall a b. (a -> b) -> a -> b
$ (forall a. URIRef a -> Query) -> RssURI -> Query
forall b. (forall a. URIRef a -> b) -> RssURI -> b
withRssURI (Getting Query (URIRef a) Query -> URIRef a -> Query
forall a s. Getting a s a -> s -> a
view Getting Query (URIRef a) Query
forall a. Lens' (URIRef a) Query
queryL) (RssURI -> Query) -> RssURI -> Query
forall a b. (a -> b) -> a -> b
$ RssCloud
cRssCloud -> Getting RssURI RssCloud RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssCloud RssURI
Lens' RssCloud RssURI
cloudUriL
  fragment :: Text
fragment = Text -> (ByteString -> Text) -> Maybe ByteString -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" ByteString -> Text
decodeUtf8 (Maybe ByteString -> Text) -> Maybe ByteString -> Text
forall a b. (a -> b) -> a -> b
$ (forall a. URIRef a -> Maybe ByteString)
-> RssURI -> Maybe ByteString
forall b. (forall a. URIRef a -> b) -> RssURI -> b
withRssURI (Getting (Maybe ByteString) (URIRef a) (Maybe ByteString)
-> URIRef a -> Maybe ByteString
forall a s. Getting a s a -> s -> a
view Getting (Maybe ByteString) (URIRef a) (Maybe ByteString)
forall a. Lens' (URIRef a) (Maybe ByteString)
fragmentL) (RssURI -> Maybe ByteString) -> RssURI -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ RssCloud
cRssCloud -> Getting RssURI RssCloud RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssCloud RssURI
Lens' RssCloud RssURI
cloudUriL

  describe :: CloudProtocol -> p
describe CloudProtocol
ProtocolXmlRpc   = p
"xml-rpc"
  describe CloudProtocol
ProtocolSoap     = p
"soap"
  describe CloudProtocol
ProtocolHttpPost = p
"http-post"

-- | Render a @\<category\>@ element.
renderRssCategory :: (Monad m) => RssCategory -> ConduitT () Event m ()
renderRssCategory :: RssCategory -> ConduitT () Event m ()
renderRssCategory RssCategory
c = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"category" (Name -> Text -> Attributes
attr Name
"domain" (Text -> Attributes) -> Text -> Attributes
forall a b. (a -> b) -> a -> b
$ RssCategory
cRssCategory -> Getting Text RssCategory Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssCategory Text
Lens' RssCategory Text
categoryDomainL) (ConduitT () Event m () -> ConduitT () Event m ())
-> (Text -> ConduitT () Event m ())
-> Text
-> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ConduitT () Event m ()
forall (m :: * -> *) i. Monad m => Text -> ConduitT i Event m ()
content (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssCategory
cRssCategory -> Getting Text RssCategory Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssCategory Text
Lens' RssCategory Text
categoryNameL

-- | Render an @\<image\>@ element.
renderRssImage :: (Monad m) => RssImage -> ConduitT () Event m ()
renderRssImage :: RssImage -> ConduitT () Event m ()
renderRssImage RssImage
i = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"image" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ do
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"url" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssURI -> Text
renderRssURI (RssURI -> Text) -> RssURI -> Text
forall a b. (a -> b) -> a -> b
$ RssImage
iRssImage -> Getting RssURI RssImage RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssImage RssURI
Lens' RssImage RssURI
imageUriL
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"title" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssImage
iRssImage -> Getting Text RssImage Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssImage Text
Lens' RssImage Text
imageTitleL
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"link" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssURI -> Text
renderRssURI (RssURI -> Text) -> RssURI -> Text
forall a b. (a -> b) -> a -> b
$ RssImage
iRssImage -> Getting RssURI RssImage RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssImage RssURI
Lens' RssImage RssURI
imageLinkL
  Maybe Int
-> (Int -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssImage
iRssImage -> Getting (Maybe Int) RssImage (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) RssImage (Maybe Int)
Lens' RssImage (Maybe Int)
imageHeightL) ((Int -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (Int -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"height" (Text -> ConduitT () Event m ())
-> (Int -> Text) -> Int -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
forall a. Show a => a -> Text
tshow
  Maybe Int
-> (Int -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (RssImage
iRssImage -> Getting (Maybe Int) RssImage (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) RssImage (Maybe Int)
Lens' RssImage (Maybe Int)
imageWidthL) ((Int -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (Int -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"width" (Text -> ConduitT () Event m ())
-> (Int -> Text) -> Int -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
forall a. Show a => a -> Text
tshow
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
"description" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssImage
iRssImage -> Getting Text RssImage Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssImage Text
Lens' RssImage Text
imageDescriptionL

-- | Render a @\<textInput\>@ element.
renderRssTextInput :: (Monad m) => RssTextInput -> ConduitT () Event m ()
renderRssTextInput :: RssTextInput -> ConduitT () Event m ()
renderRssTextInput RssTextInput
t = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"textInput" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ do
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"title" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssTextInput
tRssTextInput -> Getting Text RssTextInput Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssTextInput Text
Lens' RssTextInput Text
textInputTitleL
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"description" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssTextInput
tRssTextInput -> Getting Text RssTextInput Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssTextInput Text
Lens' RssTextInput Text
textInputDescriptionL
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"name" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssTextInput
tRssTextInput -> Getting Text RssTextInput Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text RssTextInput Text
Lens' RssTextInput Text
textInputNameL
  Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"link" (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ RssURI -> Text
renderRssURI (RssURI -> Text) -> RssURI -> Text
forall a b. (a -> b) -> a -> b
$ RssTextInput
tRssTextInput -> Getting RssURI RssTextInput RssURI -> RssURI
forall s a. s -> Getting a s a -> a
^.Getting RssURI RssTextInput RssURI
Lens' RssTextInput RssURI
textInputLinkL

-- | Render a @\<skipDays\>@ element.
renderRssSkipDays :: (Monad m) => Set Day -> ConduitT () Event m ()
renderRssSkipDays :: Set Day -> ConduitT () Event m ()
renderRssSkipDays Set Day
s = Bool -> ConduitT () Event m () -> ConduitT () Event m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Day -> Bool
forall a. Set a -> Bool
Set.null Set Day
s) (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"skipDays" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Set Day
-> (Day -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Set Day
s ((Day -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (Day -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"day" (Text -> ConduitT () Event m ())
-> (Day -> Text) -> Day -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Day -> Text
forall a. Show a => a -> Text
tshow

-- | Render a @\<skipHours\>@ element.
renderRssSkipHours :: (Monad m) => Set Hour -> ConduitT () Event m ()
renderRssSkipHours :: Set Hour -> ConduitT () Event m ()
renderRssSkipHours Set Hour
s = Bool -> ConduitT () Event m () -> ConduitT () Event m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Hour -> Bool
forall a. Set a -> Bool
Set.null Set Hour
s) (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
"skipHour" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Set Hour
-> (Hour -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Set Hour
s ((Hour -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (Hour -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
"hour" (Text -> ConduitT () Event m ())
-> (Hour -> Text) -> Hour -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hour -> Text
forall a. Show a => a -> Text
tshow


-- {{{ Utils
tshow :: Show a => a -> Text
tshow :: a -> Text
tshow = String -> Text
pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show

textTag :: (Monad m) => Name -> Text -> ConduitT () Event m ()
textTag :: Name -> Text -> ConduitT () Event m ()
textTag Name
name = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
name Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (Text -> ConduitT () Event m ())
-> Text
-> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ConduitT () Event m ()
forall (m :: * -> *) i. Monad m => Text -> ConduitT i Event m ()
content

optionalTextTag :: Monad m => Name -> Text -> ConduitT () Event m ()
optionalTextTag :: Name -> Text -> ConduitT () Event m ()
optionalTextTag Name
name Text
value = Bool -> ConduitT () Event m () -> ConduitT () Event m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
Text.null Text
value) (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Name -> Text -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Name -> Text -> ConduitT () Event m ()
textTag Name
name Text
value

dateTag :: (Monad m) => Name -> UTCTime -> ConduitT () Event m ()
dateTag :: Name -> UTCTime -> ConduitT () Event m ()
dateTag Name
name = Name
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *) i.
Monad m =>
Name
-> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
tag Name
name Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (UTCTime -> ConduitT () Event m ())
-> UTCTime
-> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ConduitT () Event m ()
forall (m :: * -> *) i. Monad m => Text -> ConduitT i Event m ()
content (Text -> ConduitT () Event m ())
-> (UTCTime -> Text) -> UTCTime -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> Text
forall t. TextualMonoid t => ZonedTime -> t
formatTimeRFC822 (ZonedTime -> Text) -> (UTCTime -> ZonedTime) -> UTCTime -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc

renderRssURI :: RssURI -> Text
renderRssURI :: RssURI -> Text
renderRssURI = ByteString -> Text
decodeUtf8 (ByteString -> Text) -> (RssURI -> ByteString) -> RssURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> RssURI -> ByteString
forall b. (forall a. URIRef a -> b) -> RssURI -> b
withRssURI forall a. URIRef a -> ByteString
serializeURIRef'
-- }}}