Skip to content

Instantly share code, notes, and snippets.

@Gabriella439
Created November 4, 2021 00:27
Show Gist options
  • Save Gabriella439/da35ac50c010ad74aec429c58632a943 to your computer and use it in GitHub Desktop.
Save Gabriella439/da35ac50c010ad74aec429c58632a943 to your computer and use it in GitHub Desktop.
lucid example
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE RecordWildCards #-}
module Main where
import Data.Foldable (traverse_)
import Data.Map (Map)
import Data.Text (Text)
import Lucid
import qualified Data.Map as Map
type Branch = Text
type PR = Int
data Status = Status
{ batches :: Map Branch [PR]
, candidates :: [PR]
}
exampleStatus :: Status
exampleStatus =
Status
{ batches = [ ("main", [ 1, 2, 3]), ("release-4.1", [ 4, 5, 6 ]) ]
, candidates = [ 7, 8, 9 ]
}
main :: IO ()
main = renderToFile "example.html" (renderStatus exampleStatus)
renderPR :: PR -> Html ()
renderPR pr = do
li_ [ class_ "list-group-item" ] ("#" <> toHtml (show pr))
renderPRs :: [PR] -> Html ()
renderPRs prs = do
ul_ [ class_ "list-group" ] do
traverse_ renderPR prs
renderStatus :: Status -> Html ()
renderStatus Status{..} = do
html_ do
head_ do
link_
[ href_ "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
, rel_ "stylesheet"
, integrity_ "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
, crossorigin_ "anonymous"
]
title_ "Merge automation status"
body_ do
div_ [ class_ "container" ] do
h1_ "Merge automation status"
h2_ "Batches"
let renderBatch :: Branch -> [PR] -> Html ()
renderBatch branch prs = do
dt_ [ class_ "col-sm-1" ] (toHtml branch)
dd_ [ class_ "col-sm-11" ] do
renderPRs prs
dl_ [ class_ "row" ]do
_ <- Map.traverseWithKey renderBatch batches
return ()
h2_ "Candidates"
renderPRs candidates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment