diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-12-04 08:36:02 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-12-05 06:07:41 +0100 |
commit | 1b1c3faabae530229eb675a2e70e744c2f45cbbe (patch) | |
tree | acc3e8eede9053fb5e639deeb553aa600c994598 /app/Issue/Render.hs | |
parent | 3a76b6f0fc0c9c23000dd82870922c885c34ffa6 (diff) |
feat: add experimental render api
Diffstat (limited to 'app/Issue/Render.hs')
-rw-r--r-- | app/Issue/Render.hs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/app/Issue/Render.hs b/app/Issue/Render.hs new file mode 100644 index 0000000..ea504d5 --- /dev/null +++ b/app/Issue/Render.hs @@ -0,0 +1,88 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Issue.Render + ( IssueTitle (..), + IssueDescription (..), + IssueTags (..), + IssueOpenedOn (..), + IssueOpenedBy (..), + ) +where + +import Data.List (intersperse) +import Data.Map qualified as M +import Data.Text qualified as T +import Data.Time.Clock (UTCTime (utctDay)) +import Issue (Issue (..)) +import Issue.Provenance (Author (..), Commit (..), Provenance (..)) +import Render ((<<<)) +import Render qualified as P + +instance P.Render (P.Detailed Issue) where + render (P.Detailed issue) = P.renderAsMarkdown issue.rawText + +instance P.Render Issue where + render = P.render . P.Detailed + +newtype IssueTitle = IssueTitle {unIssueTitle :: Issue} + +instance P.Render IssueTitle where + render (IssueTitle issue) + | issue.closed = P.styled [P.colorDull P.Red] $ P.render issue.title + | otherwise = P.styled [(P.color P.Green)] $ P.render issue.title + +newtype IssueDescription = IssueDescription {unIssueDescription :: Issue} + +instance P.Render IssueDescription where + render (IssueDescription issue) = maybe P.emptyDoc P.pretty issue.description + +instance P.Render (P.Linked Issue) where + render (P.Linked issue) + | issue.closed = + P.styled [P.underlined, P.colorDull P.Red] $ + ("(closed)" :: T.Text) <<< P.render issue.id + | otherwise = + P.styled [P.underlined, (P.color P.Green)] $ + P.render issue.id + +instance P.Render (P.Summarized Issue) where + render (P.Summarized issue) = + P.nest 4 $ + IssueTitle issue + <<< IssueTags issue + <<< IssueOpenedOn issue + <<< IssueOpenedBy issue + +newtype IssueTags = IssueTags {unIssueTags :: Issue} + +instance P.Render IssueTags where + render (IssueTags issue) = P.render issue.tags + +newtype IssueOpenedBy = IssueOpenedBy {unIssueOpenedBy :: Issue} + +instance P.Render IssueOpenedBy where + render (IssueOpenedBy issue) = + ("by" :: T.Text) <<< issue.provenance.first.author.name + +newtype IssueOpenedOn = IssueOpenedOn {unIssueOpenedOn :: Issue} + +instance P.Render IssueOpenedOn where + render (IssueOpenedOn issue) = + ("on" :: T.Text) <<< utctDay issue.provenance.first.date + +instance P.Render (T.Text, M.Map T.Text [Issue]) where + render (tagKey, groupedIssues) = + (P.vsep . intersperse ("" :: P.Doc ann)) $ + concatMap + ( \(name, issues) -> + ( P.styled [P.underlined] $ + ("@" <> tagKey) + <<< name + <<< P.parens @P.AnsiStyle (P.pretty (length issues)) + ) + : map + (P.indent 4) + ( map (P.render . IssueTitle) issues + ) + ) + (M.toList groupedIssues) |