aboutsummaryrefslogtreecommitdiff
path: root/src/View
diff options
context:
space:
mode:
Diffstat (limited to 'src/View')
-rw-r--r--src/View/Ad.hs42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/View/Ad.hs b/src/View/Ad.hs
index 6f094ee..acf0839 100644
--- a/src/View/Ad.hs
+++ b/src/View/Ad.hs
@@ -1,7 +1,8 @@
{-# LANGUAGE OverloadedStrings #-}
module View.Ad
- ( renderAds
+ ( renderConsoleAds
+ , renderAds
) where
import Data.List (intersperse)
@@ -16,8 +17,43 @@ import qualified Model.Resume as Resume
import Model.Detail (Detail(..))
import qualified Model.Detail as Detail
-renderAds :: [Ad] -> Text
-renderAds = T.intercalate "\n\n" . map renderAd
+renderConsoleAds :: Text -> [Ad] -> Text
+renderConsoleAds time ads =
+ let (title, message) = renderAds ads
+ titleWithTime =
+ T.concat
+ [ "\n["
+ , time
+ , "] "
+ , title
+ ]
+ line = T.map (\_ -> '-') title
+ in T.intercalate
+ "\n"
+ [ titleWithTime
+ , line
+ , ""
+ , message
+ ]
+
+renderAds :: [Ad] -> (Text, Text)
+renderAds ads =
+ let titleMessage = renderTitle $ length ads
+ adsMessage = T.intercalate "\n\n" . map renderAd $ ads
+ in (titleMessage, adsMessage)
+
+renderTitle :: Int -> Text
+renderTitle count =
+ T.concat
+ [ T.pack . show $ count
+ , agreement " nouvelle"
+ , agreement " annonce"
+ ]
+ where agreement word =
+ T.concat
+ [ word
+ , if count > 1 then "s" else ""
+ ]
renderAd :: Ad -> Text
renderAd ad =