aboutsummaryrefslogtreecommitdiff
path: root/src/View
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-04-15 00:10:22 +0200
committerJoris Guyonvarch2015-04-15 00:10:22 +0200
commit4de52f287fd9f0cdae9b6cb55678e85458cbbc04 (patch)
tree4033ac7fa7531a136fab258f88984ca2633b846c /src/View
parentabd0a834f9c523af98fbafa65af82b9416328249 (diff)
Adding a title to the mail
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 =