aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2015-03-16 05:52:03 +0000
committerSean Whitton <spwhitton@spwhitton.name>2015-03-16 05:52:12 +0000
commit9f49ac7284bacc50ffb2c953917abe18880addfc (patch)
tree8ca9a576bfe02999c25f38e40b7056bfbbe52f0c
parent6673d1a5994761d97119e6f2a5bb1f31c07f007b (diff)
downloadsariulclocks-9f49ac7284bacc50ffb2c953917abe18880addfc.tar.gz
pass calendar time to cgiMain for cookie-setting
-rw-r--r--sariulclocks.cabal2
-rw-r--r--src/sariulclocks.hs13
2 files changed, 11 insertions, 4 deletions
diff --git a/sariulclocks.cabal b/sariulclocks.cabal
index a3841a9..23d2888 100644
--- a/sariulclocks.cabal
+++ b/sariulclocks.cabal
@@ -20,7 +20,7 @@ executable sariulclocks.cgi
main-is: sariulclocks.hs
-- other-modules:
-- other-extensions:
- build-depends: base, cgi, xhtml, time, directory, filepath, split
+ build-depends: base, cgi, xhtml, time, directory, filepath, split, old-time
hs-source-dirs: src
default-language: Haskell2010
ld-options: -static -pthread
diff --git a/src/sariulclocks.hs b/src/sariulclocks.hs
index ad13c05..523a540 100644
--- a/src/sariulclocks.hs
+++ b/src/sariulclocks.hs
@@ -5,6 +5,7 @@ import Types.Classes
import Types.Scores
import Data.Classes
import Data.List.Split (splitOn)
+import System.Time (getClockTime, CalendarTime, toCalendarTime)
templateInject :: String -> Html -> String
templateInject template body = templateBefore ++ (prettyHtmlFragment body) ++ templateAfter
@@ -14,17 +15,23 @@ templateInject template body = templateBefore ++ (prettyHtmlFragment body) ++ te
page :: ScoresList -> Html
page scores = (h1 << "Hello World!") +++ rankings (Just $ lookupSariulClass 5 3) scores
-cgiMain :: String -> ScoresList -> (ScoresList, CGI CGIResult)
-cgiMain template scores = (scores, output $ templateInject template (page scores))
+cgiMain :: CalendarTime -> String -> ScoresList -> (ScoresList, CGI CGIResult)
+cgiMain calendarTime template scores = (scores, output $ templateInject template (page scores))
main :: IO ()
main = do
htmlTemplate <- readFile "html/main.html"
+
+ -- handle scores file
scores <- readScoresFile
let scores' = case scores of
Just s -> s
_ -> zeroScores
- let (newScores, cgi) = cgiMain htmlTemplate scores'
+
+ clockTime <- getClockTime
+ calendarTime <- toCalendarTime clockTime
+
+ let (newScores, cgi) = cgiMain calendarTime htmlTemplate scores'
if scores' /= newScores
then writeScoresFile newScores
else return ()