diff options
Diffstat (limited to 'src/Pages.hs')
| -rw-r--r-- | src/Pages.hs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/Pages.hs b/src/Pages.hs new file mode 100644 index 0000000..4efd8fe --- /dev/null +++ b/src/Pages.hs @@ -0,0 +1,71 @@ +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE NoFieldSelectors #-} +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} +module Pages ( + renderPageLog, LogData(..), + renderPageCalendarDay, CalendarDayData(..), + PickerData(..), EventData(..), +) where + +import Control.Monad.IO.Class (liftIO) +import Data.Text (Text) +import Data.Text.IO qualified as T +import Language.Haskell.TH.Syntax (addDependentFile) +import System.Directory (makeAbsolute) +import Text.Mustache.Compile qualified as M + +import Pages.TH + + +data LogData = LogData + { network :: Text + , channel :: Text + , alias :: Text + , totalevents :: Text + , picker :: PickerData + , events :: [EventData () Text] + } + +data CalendarDayData = CalendarDayData + { network :: Text + , channel :: Text + , alias :: Text + , date :: Text + , events :: [EventData Text ()] + } + +data PickerData = PickerData + { prevpage :: Maybe Int + , nextpage :: Maybe Int + , firstpage :: Bool + , leftdots :: Bool + , rightdots :: Bool + , lastpage :: Bool + , leftnums :: [Int] + , curnum :: Int + , rightnums :: [Int] + , npages :: Int + } + +data EventData tm dttm = EventData + { classlist :: Maybe Text + , time :: tm + , datetime :: dttm + , linkid :: Text + , nickwrap1 :: Maybe Text + , nick :: Text + , nickwrap2 :: Maybe Text + , message :: Text + } + +$(do let readTemplate name = do + path <- liftIO $ makeAbsolute ("pages/" ++ name ++ ".mustache") + tplSrc <- liftIO $ T.readFile path + addDependentFile path + case M.compileTemplate name tplSrc of + Right tpl -> return tpl + Left err -> fail $ "Reading " ++ path ++ ": " ++ show err + concat <$> mapM (\(name, ty) -> (`makeRender` ty) =<< readTemplate name) + [("log", ''LogData) + ,("calendar-day", ''CalendarDayData)]) |
