{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes        #-}
-- | Streaming renderers for the Atom 1.0 standard.
module Text.Atom.Conduit.Render
  ( -- * Top-level
    renderAtomFeed
    -- * Elements
  , renderAtomEntry
  , renderAtomContent
  , renderAtomSource
  , renderAtomGenerator
  , renderAtomLink
  , renderAtomCategory
    -- * Constructs
  , renderAtomPerson
  , renderAtomText
  ) where

-- {{{ Imports
import           Text.Atom.Lens
import           Text.Atom.Types

import           Conduit
import           Control.Monad
import           Data.Monoid
import           Data.Text              as Text
import           Data.Time.Clock
import           Data.Time.LocalTime
import           Data.Time.RFC3339
import           Data.XML.Types
import           Lens.Micro
import           Refined
import           Text.XML               as XML
import           Text.XML.Stream.Render
import qualified Text.XML.Unresolved    as Unresolved
import           URI.ByteString
-- }}}

-- | Render the top-level @atom:feed@ element.
renderAtomFeed :: (Monad m) => AtomFeed -> ConduitT () Event m ()
renderAtomFeed :: AtomFeed -> ConduitT () Event m ()
renderAtomFeed AtomFeed
f = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"feed" (Name -> Text -> Attributes
attr Name
"xmlns" Text
"http://www.w3.org/2005/Atom") (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ do
  [AtomPerson]
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed
-> Getting [AtomPerson] AtomFeed [AtomPerson] -> [AtomPerson]
forall s a. s -> Getting a s a -> a
^.Getting [AtomPerson] AtomFeed [AtomPerson]
Lens' AtomFeed [AtomPerson]
feedAuthorsL) ((AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomPerson -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson Text
"author"
  [AtomCategory]
-> (AtomCategory -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed
-> Getting [AtomCategory] AtomFeed [AtomCategory] -> [AtomCategory]
forall s a. s -> Getting a s a -> a
^.Getting [AtomCategory] AtomFeed [AtomCategory]
Lens' AtomFeed [AtomCategory]
feedCategoriesL) AtomCategory -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomCategory -> ConduitT () Event m ()
renderAtomCategory
  [AtomPerson]
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed
-> Getting [AtomPerson] AtomFeed [AtomPerson] -> [AtomPerson]
forall s a. s -> Getting a s a -> a
^.Getting [AtomPerson] AtomFeed [AtomPerson]
Lens' AtomFeed [AtomPerson]
feedContributorsL) ((AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomPerson -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson Text
"contributor"
  [AtomEntry]
-> (AtomEntry -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed -> Getting [AtomEntry] AtomFeed [AtomEntry] -> [AtomEntry]
forall s a. s -> Getting a s a -> a
^.Getting [AtomEntry] AtomFeed [AtomEntry]
Lens' AtomFeed [AtomEntry]
feedEntriesL) AtomEntry -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomEntry -> ConduitT () Event m ()
renderAtomEntry
  Maybe AtomGenerator
-> (AtomGenerator -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed
-> Getting (Maybe AtomGenerator) AtomFeed (Maybe AtomGenerator)
-> Maybe AtomGenerator
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomGenerator) AtomFeed (Maybe AtomGenerator)
Lens' AtomFeed (Maybe AtomGenerator)
feedGeneratorL) AtomGenerator -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomGenerator -> ConduitT () Event m ()
renderAtomGenerator
  Maybe AtomURI
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed -> Maybe AtomURI
feedIcon AtomFeed
f) ((AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"icon" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ())
-> AtomURI
-> 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 ())
-> (AtomURI -> Text) -> AtomURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> (AtomURI -> ByteString) -> AtomURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef'
  Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"id" 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 (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomFeed
fAtomFeed -> Getting Text AtomFeed Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomFeed Text
Lens' AtomFeed Text
feedIdL
  [AtomLink]
-> (AtomLink -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed -> Getting [AtomLink] AtomFeed [AtomLink] -> [AtomLink]
forall s a. s -> Getting a s a -> a
^.Getting [AtomLink] AtomFeed [AtomLink]
Lens' AtomFeed [AtomLink]
feedLinksL) AtomLink -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => AtomLink -> ConduitT () Event m ()
renderAtomLink
  Maybe AtomURI
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed -> Maybe AtomURI
feedLogo AtomFeed
f) ((AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"logo" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ())
-> AtomURI
-> 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 ())
-> (AtomURI -> Text) -> AtomURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> (AtomURI -> ByteString) -> AtomURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef'
  Maybe AtomText
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed
-> Getting (Maybe AtomText) AtomFeed (Maybe AtomText)
-> Maybe AtomText
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomText) AtomFeed (Maybe AtomText)
Lens' AtomFeed (Maybe AtomText)
feedRightsL) ((AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"rights"
  Maybe AtomText
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomFeed
fAtomFeed
-> Getting (Maybe AtomText) AtomFeed (Maybe AtomText)
-> Maybe AtomText
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomText) AtomFeed (Maybe AtomText)
Lens' AtomFeed (Maybe AtomText)
feedSubtitleL) ((AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"subtitle"
  Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"title" (AtomText -> ConduitT () Event m ())
-> AtomText -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomFeed
fAtomFeed -> Getting AtomText AtomFeed AtomText -> AtomText
forall s a. s -> Getting a s a -> a
^.Getting AtomText AtomFeed AtomText
Lens' AtomFeed AtomText
feedTitleL
  Text -> UTCTime -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> UTCTime -> ConduitT () Event m ()
dateTag Text
"updated" (UTCTime -> ConduitT () Event m ())
-> UTCTime -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomFeed
fAtomFeed -> Getting UTCTime AtomFeed UTCTime -> UTCTime
forall s a. s -> Getting a s a -> a
^.Getting UTCTime AtomFeed UTCTime
Lens' AtomFeed UTCTime
feedUpdatedL

-- | Render an @atom:entry@ element.
renderAtomEntry :: (Monad m) => AtomEntry -> ConduitT () Event m ()
renderAtomEntry :: AtomEntry -> ConduitT () Event m ()
renderAtomEntry AtomEntry
e = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"entry" 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
  [AtomPerson]
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry
-> Getting [AtomPerson] AtomEntry [AtomPerson] -> [AtomPerson]
forall s a. s -> Getting a s a -> a
^.Getting [AtomPerson] AtomEntry [AtomPerson]
Lens' AtomEntry [AtomPerson]
entryAuthorsL) ((AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomPerson -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson Text
"author"
  [AtomCategory]
-> (AtomCategory -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry
-> Getting [AtomCategory] AtomEntry [AtomCategory]
-> [AtomCategory]
forall s a. s -> Getting a s a -> a
^.Getting [AtomCategory] AtomEntry [AtomCategory]
Lens' AtomEntry [AtomCategory]
entryCategoriesL) AtomCategory -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomCategory -> ConduitT () Event m ()
renderAtomCategory
  Maybe AtomContent
-> (AtomContent -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry
-> Getting (Maybe AtomContent) AtomEntry (Maybe AtomContent)
-> Maybe AtomContent
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomContent) AtomEntry (Maybe AtomContent)
Lens' AtomEntry (Maybe AtomContent)
entryContentL) AtomContent -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomContent -> ConduitT () Event m ()
renderAtomContent
  [AtomPerson]
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry
-> Getting [AtomPerson] AtomEntry [AtomPerson] -> [AtomPerson]
forall s a. s -> Getting a s a -> a
^.Getting [AtomPerson] AtomEntry [AtomPerson]
Lens' AtomEntry [AtomPerson]
entryContributorsL) ((AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomPerson -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson Text
"contributor"
  Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"id" 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 (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomEntry
eAtomEntry -> Getting Text AtomEntry Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomEntry Text
Lens' AtomEntry Text
entryIdL
  [AtomLink]
-> (AtomLink -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry -> Getting [AtomLink] AtomEntry [AtomLink] -> [AtomLink]
forall s a. s -> Getting a s a -> a
^.Getting [AtomLink] AtomEntry [AtomLink]
Lens' AtomEntry [AtomLink]
entryLinksL) AtomLink -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => AtomLink -> ConduitT () Event m ()
renderAtomLink
  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_ (AtomEntry
eAtomEntry
-> Getting (Maybe UTCTime) AtomEntry (Maybe UTCTime)
-> Maybe UTCTime
forall s a. s -> Getting a s a -> a
^.Getting (Maybe UTCTime) AtomEntry (Maybe UTCTime)
Lens' AtomEntry (Maybe UTCTime)
entryPublishedL) ((UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> UTCTime -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> UTCTime -> ConduitT () Event m ()
dateTag Text
"published"
  Maybe AtomText
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry
-> Getting (Maybe AtomText) AtomEntry (Maybe AtomText)
-> Maybe AtomText
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomText) AtomEntry (Maybe AtomText)
Lens' AtomEntry (Maybe AtomText)
entryRightsL) ((AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"rights"
  Maybe AtomSource
-> (AtomSource -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry
-> Getting (Maybe AtomSource) AtomEntry (Maybe AtomSource)
-> Maybe AtomSource
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomSource) AtomEntry (Maybe AtomSource)
Lens' AtomEntry (Maybe AtomSource)
entrySourceL) AtomSource -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomSource -> ConduitT () Event m ()
renderAtomSource
  Maybe AtomText
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomEntry
eAtomEntry
-> Getting (Maybe AtomText) AtomEntry (Maybe AtomText)
-> Maybe AtomText
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomText) AtomEntry (Maybe AtomText)
Lens' AtomEntry (Maybe AtomText)
entrySummaryL) ((AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"summary"
  Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"title" (AtomEntry
eAtomEntry -> Getting AtomText AtomEntry AtomText -> AtomText
forall s a. s -> Getting a s a -> a
^.Getting AtomText AtomEntry AtomText
Lens' AtomEntry AtomText
entryTitleL)
  Text -> UTCTime -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> UTCTime -> ConduitT () Event m ()
dateTag Text
"updated" (AtomEntry
eAtomEntry -> Getting UTCTime AtomEntry UTCTime -> UTCTime
forall s a. s -> Getting a s a -> a
^.Getting UTCTime AtomEntry UTCTime
Lens' AtomEntry UTCTime
entryUpdatedL)

-- | Render an @atom:content@ element.
renderAtomContent :: (Monad m) => AtomContent -> ConduitT () Event m ()
renderAtomContent :: AtomContent -> ConduitT () Event m ()
renderAtomContent (AtomContentInlineXHTML Element
element) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"content" (Name -> Text -> Attributes
attr Name
"type" Text
"xhtml") (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ [Event] -> ConduitT () (Element [Event]) m ()
forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldMany ([Event] -> ConduitT () (Element [Event]) m ())
-> [Event] -> ConduitT () (Element [Event]) m ()
forall a b. (a -> b) -> a -> b
$ Element -> [Event]
Unresolved.elementToEvents Element
element
renderAtomContent (AtomContentOutOfLine Text
ctype AtomURI
uri) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"content" (Name -> Text -> Attributes
nonEmptyAttr Name
"type" Text
ctype Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
attr Name
"src" (ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> ByteString -> Text
forall a b. (a -> b) -> a -> b
$ (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef' AtomURI
uri)) (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 ()
renderAtomContent (AtomContentInlineText TextType
TypeHTML Text
t) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"content" (Name -> Text -> Attributes
attr Name
"type" Text
"html") (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
renderAtomContent (AtomContentInlineText TextType
TypeText Text
t) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"content" 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
renderAtomContent (AtomContentInlineOther Text
ctype Text
t) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"content" (Name -> Text -> Attributes
attr Name
"type" Text
ctype) (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 an @atom:source@ element.
renderAtomSource :: (Monad m) => AtomSource -> ConduitT () Event m ()
renderAtomSource :: AtomSource -> ConduitT () Event m ()
renderAtomSource AtomSource
s = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"source" 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
  [AtomPerson]
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting [AtomPerson] AtomSource [AtomPerson] -> [AtomPerson]
forall s a. s -> Getting a s a -> a
^.Getting [AtomPerson] AtomSource [AtomPerson]
Lens' AtomSource [AtomPerson]
sourceAuthorsL) ((AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomPerson -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson Text
"author"
  [AtomCategory]
-> (AtomCategory -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting [AtomCategory] AtomSource [AtomCategory]
-> [AtomCategory]
forall s a. s -> Getting a s a -> a
^.Getting [AtomCategory] AtomSource [AtomCategory]
Lens' AtomSource [AtomCategory]
sourceCategoriesL) AtomCategory -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomCategory -> ConduitT () Event m ()
renderAtomCategory
  [AtomPerson]
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting [AtomPerson] AtomSource [AtomPerson] -> [AtomPerson]
forall s a. s -> Getting a s a -> a
^.Getting [AtomPerson] AtomSource [AtomPerson]
Lens' AtomSource [AtomPerson]
sourceContributorsL) ((AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomPerson -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomPerson -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson Text
"contributor"
  Maybe AtomGenerator
-> (AtomGenerator -> ConduitT () Event m ())
-> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting (Maybe AtomGenerator) AtomSource (Maybe AtomGenerator)
-> Maybe AtomGenerator
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomGenerator) AtomSource (Maybe AtomGenerator)
Lens' AtomSource (Maybe AtomGenerator)
sourceGeneratorL) AtomGenerator -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
AtomGenerator -> ConduitT () Event m ()
renderAtomGenerator
  Maybe AtomURI
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource -> Maybe AtomURI
sourceIcon AtomSource
s) ((AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"icon" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ())
-> AtomURI
-> 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 ())
-> (AtomURI -> Text) -> AtomURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> (AtomURI -> ByteString) -> AtomURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef'
  Bool -> ConduitT () Event m () -> ConduitT () Event m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
Text.null (Text -> Bool) -> Text -> Bool
forall a b. (a -> b) -> a -> b
$ AtomSource
sAtomSource -> Getting Text AtomSource Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomSource Text
Lens' AtomSource Text
sourceIdL) (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
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"id" 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 (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomSource
sAtomSource -> Getting Text AtomSource Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomSource Text
Lens' AtomSource Text
sourceIdL
  [AtomLink]
-> (AtomLink -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting [AtomLink] AtomSource [AtomLink] -> [AtomLink]
forall s a. s -> Getting a s a -> a
^.Getting [AtomLink] AtomSource [AtomLink]
Lens' AtomSource [AtomLink]
sourceLinksL) AtomLink -> ConduitT () Event m ()
forall (m :: * -> *). Monad m => AtomLink -> ConduitT () Event m ()
renderAtomLink
  Maybe AtomURI
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource -> Maybe AtomURI
sourceLogo AtomSource
s) ((AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"logo" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ())
-> AtomURI
-> 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 ())
-> (AtomURI -> Text) -> AtomURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> (AtomURI -> ByteString) -> AtomURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef'
  Maybe AtomText
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting (Maybe AtomText) AtomSource (Maybe AtomText)
-> Maybe AtomText
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomText) AtomSource (Maybe AtomText)
Lens' AtomSource (Maybe AtomText)
sourceRightsL) ((AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"rights"
  Maybe AtomText
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting (Maybe AtomText) AtomSource (Maybe AtomText)
-> Maybe AtomText
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomText) AtomSource (Maybe AtomText)
Lens' AtomSource (Maybe AtomText)
sourceSubtitleL) ((AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"subtitle"
  Maybe AtomText
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomSource
sAtomSource
-> Getting (Maybe AtomText) AtomSource (Maybe AtomText)
-> Maybe AtomText
forall s a. s -> Getting a s a -> a
^.Getting (Maybe AtomText) AtomSource (Maybe AtomText)
Lens' AtomSource (Maybe AtomText)
sourceTitleL) ((AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomText -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> AtomText -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
"title"
  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_ (AtomSource
sAtomSource
-> Getting (Maybe UTCTime) AtomSource (Maybe UTCTime)
-> Maybe UTCTime
forall s a. s -> Getting a s a -> a
^.Getting (Maybe UTCTime) AtomSource (Maybe UTCTime)
Lens' AtomSource (Maybe UTCTime)
sourceUpdatedL) ((UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (UTCTime -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text -> UTCTime -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text -> UTCTime -> ConduitT () Event m ()
dateTag Text
"updated"

-- | Render an @atom:generator@ element.
renderAtomGenerator :: (Monad m) => AtomGenerator -> ConduitT () Event m ()
renderAtomGenerator :: AtomGenerator -> ConduitT () Event m ()
renderAtomGenerator AtomGenerator
g = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"generator" Attributes
attributes (ConduitT () Event m () -> ConduitT () Event m ())
-> (Refined (Not Null) Text -> ConduitT () Event m ())
-> Refined (Not Null) 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 ())
-> (Refined (Not Null) Text -> Text)
-> Refined (Not Null) Text
-> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Refined (Not Null) Text -> Text
forall p x. Refined p x -> x
unrefine (Refined (Not Null) Text -> ConduitT () Event m ())
-> Refined (Not Null) Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomGenerator
gAtomGenerator
-> Getting
     (Refined (Not Null) Text) AtomGenerator (Refined (Not Null) Text)
-> Refined (Not Null) Text
forall s a. s -> Getting a s a -> a
^.Getting
  (Refined (Not Null) Text) AtomGenerator (Refined (Not Null) Text)
Lens' AtomGenerator (Refined (Not Null) Text)
generatorContentL
  where attributes :: Attributes
attributes = Name -> Maybe Text -> Attributes
optionalAttr Name
"uri" (ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> (AtomURI -> ByteString) -> AtomURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef' (AtomURI -> Text) -> Maybe AtomURI -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AtomGenerator -> Maybe AtomURI
generatorUri AtomGenerator
g)
                     Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"version" (AtomGenerator
gAtomGenerator -> Getting Text AtomGenerator Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomGenerator Text
Lens' AtomGenerator Text
generatorVersionL)

-- | Render an @atom:link@ element.
renderAtomLink :: (Monad m) => AtomLink -> ConduitT () Event m ()
renderAtomLink :: AtomLink -> ConduitT () Event m ()
renderAtomLink AtomLink
l = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"link" Attributes
linkAttrs (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 linkAttrs :: Attributes
linkAttrs = Name -> Text -> Attributes
attr Name
"href" (ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> (AtomURI -> ByteString) -> AtomURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef' (AtomURI -> Text) -> AtomURI -> Text
forall a b. (a -> b) -> a -> b
$ AtomLink -> AtomURI
linkHref AtomLink
l)
                    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"rel" (AtomLink
lAtomLink -> Getting Text AtomLink Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomLink Text
Lens' AtomLink Text
linkRelL)
                    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"type" (AtomLink
lAtomLink -> Getting Text AtomLink Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomLink Text
Lens' AtomLink Text
linkTypeL)
                    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"hreflang" (AtomLink
lAtomLink -> Getting Text AtomLink Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomLink Text
Lens' AtomLink Text
linkLangL)
                    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"title" (AtomLink
lAtomLink -> Getting Text AtomLink Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomLink Text
Lens' AtomLink Text
linkTitleL)
                    Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"length" (AtomLink
lAtomLink -> Getting Text AtomLink Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomLink Text
Lens' AtomLink Text
linkLengthL)

-- | Render an @atom:category@ element.
renderAtomCategory :: (Monad m) => AtomCategory -> ConduitT () Event m ()
renderAtomCategory :: AtomCategory -> ConduitT () Event m ()
renderAtomCategory AtomCategory
c = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"category" 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
"term" (Refined (Not Null) Text -> Text
forall p x. Refined p x -> x
unrefine (Refined (Not Null) Text -> Text)
-> Refined (Not Null) Text -> Text
forall a b. (a -> b) -> a -> b
$ AtomCategory
cAtomCategory
-> Getting
     (Refined (Not Null) Text) AtomCategory (Refined (Not Null) Text)
-> Refined (Not Null) Text
forall s a. s -> Getting a s a -> a
^.Getting
  (Refined (Not Null) Text) AtomCategory (Refined (Not Null) Text)
Lens' AtomCategory (Refined (Not Null) Text)
categoryTermL)
                     Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"scheme" (AtomCategory
cAtomCategory -> Getting Text AtomCategory Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomCategory Text
Lens' AtomCategory Text
categorySchemeL)
                     Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Name -> Text -> Attributes
nonEmptyAttr Name
"label" (AtomCategory
cAtomCategory -> Getting Text AtomCategory Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomCategory Text
Lens' AtomCategory Text
categoryLabelL)

-- | Render an atom person construct.
renderAtomPerson :: (Monad m) => Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson :: Text -> AtomPerson -> ConduitT () Event m ()
renderAtomPerson Text
name AtomPerson
p = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
name 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
  Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"name" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (Refined (Not Null) Text -> ConduitT () Event m ())
-> Refined (Not Null) 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 ())
-> (Refined (Not Null) Text -> Text)
-> Refined (Not Null) Text
-> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Refined (Not Null) Text -> Text
forall p x. Refined p x -> x
unrefine (Refined (Not Null) Text -> ConduitT () Event m ())
-> Refined (Not Null) Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomPerson
pAtomPerson
-> Getting
     (Refined (Not Null) Text) AtomPerson (Refined (Not Null) Text)
-> Refined (Not Null) Text
forall s a. s -> Getting a s a -> a
^.Getting
  (Refined (Not Null) Text) AtomPerson (Refined (Not Null) Text)
Lens' AtomPerson (Refined (Not Null) Text)
personNameL
  Bool -> ConduitT () Event m () -> ConduitT () Event m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
Text.null (Text -> Bool) -> Text -> Bool
forall a b. (a -> b) -> a -> b
$ AtomPerson
pAtomPerson -> Getting Text AtomPerson Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomPerson Text
Lens' AtomPerson Text
personEmailL) (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"email" 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 (Text -> ConduitT () Event m ()) -> Text -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ AtomPerson
pAtomPerson -> Getting Text AtomPerson Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text AtomPerson Text
Lens' AtomPerson Text
personEmailL
  Maybe AtomURI
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (AtomPerson -> Maybe AtomURI
personUri AtomPerson
p) ((AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ()) -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
"uri" Attributes
forall a. Monoid a => a
mempty (ConduitT () Event m () -> ConduitT () Event m ())
-> (AtomURI -> ConduitT () Event m ())
-> AtomURI
-> 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 ())
-> (AtomURI -> Text) -> AtomURI -> ConduitT () Event m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> (AtomURI -> ByteString) -> AtomURI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. URIRef a -> ByteString) -> AtomURI -> ByteString
forall b. (forall a. URIRef a -> b) -> AtomURI -> b
withAtomURI forall a. URIRef a -> ByteString
serializeURIRef'

-- | Render an atom text construct.
renderAtomText :: Monad m => Text -> AtomText -> ConduitT () Event m ()
renderAtomText :: Text -> AtomText -> ConduitT () Event m ()
renderAtomText Text
name (AtomXHTMLText Element
element) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
name (Name -> Text -> Attributes
attr Name
"type" Text
"xhtml") (ConduitT () Event m () -> ConduitT () Event m ())
-> ConduitT () Event m () -> ConduitT () Event m ()
forall a b. (a -> b) -> a -> b
$ [Event] -> ConduitT () (Element [Event]) m ()
forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldMany ([Event] -> ConduitT () (Element [Event]) m ())
-> [Event] -> ConduitT () (Element [Event]) m ()
forall a b. (a -> b) -> a -> b
$ Element -> [Event]
Unresolved.elementToEvents Element
element
renderAtomText Text
name (AtomPlainText TextType
TypeHTML Text
t) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
name (Name -> Text -> Attributes
attr Name
"type" Text
"html") (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
renderAtomText Text
name (AtomPlainText TextType
TypeText Text
t) = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
name 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

atomTag :: Monad m => Text -> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag :: Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
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 (Text -> Maybe Text -> Maybe Text -> Name
Name Text
name (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"http://www.w3.org/2005/Atom") (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"atom"))

dateTag :: (Monad m) => Text -> UTCTime -> ConduitT () Event m ()
dateTag :: Text -> UTCTime -> ConduitT () Event m ()
dateTag Text
name = Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
forall (m :: * -> *).
Monad m =>
Text
-> Attributes -> ConduitT () Event m () -> ConduitT () Event m ()
atomTag Text
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
formatTimeRFC3339 (ZonedTime -> Text) -> (UTCTime -> ZonedTime) -> UTCTime -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc

nonEmptyAttr :: Name -> Text -> Attributes
nonEmptyAttr :: Name -> Text -> Attributes
nonEmptyAttr Name
name Text
value
  | Text
value Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
forall a. Monoid a => a
mempty = Attributes
forall a. Monoid a => a
mempty
  | Bool
otherwise = Name -> Text -> Attributes
attr Name
name Text
value