aboutsummaryrefslogtreecommitdiff
path: root/src/View/Plain
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-04-18 15:46:44 +0200
committerJoris Guyonvarch2015-04-18 15:46:44 +0200
commit86f9991deeb44a6cc81044e61a9ad3ee001c5ced (patch)
tree8c9e33635b2fea682b9c4cfb0f5fb5f2517c5563 /src/View/Plain
parenta14b3c3d4447cbeb77e4146fba7e0d31393e625e (diff)
Send both plain text and html in mail notifications
Diffstat (limited to 'src/View/Plain')
-rw-r--r--src/View/Plain/Ad.hs88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/View/Plain/Ad.hs b/src/View/Plain/Ad.hs
new file mode 100644
index 0000000..9dc5289
--- /dev/null
+++ b/src/View/Plain/Ad.hs
@@ -0,0 +1,88 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module View.Plain.Ad
+ ( renderConsoleAds
+ , renderAds
+ ) where
+
+import Data.List (intersperse)
+import Data.Maybe (fromMaybe)
+
+import Data.Text (Text)
+import qualified Data.Text as T
+
+import Model.Ad (Ad(..))
+import qualified Model.Ad as Ad
+
+import Model.Resume (Resume(..))
+import qualified Model.Resume as Resume
+
+import Model.Detail (Detail(..))
+import qualified Model.Detail as Detail
+
+import Model.URL
+
+renderConsoleAds :: Text -> [Ad] -> Text
+renderConsoleAds time ads =
+ let (title, message) = renderAds ads
+ titleWithTime =
+ T.concat
+ [ "\n["
+ , time
+ , "] "
+ , title
+ ]
+ line = T.map (\_ -> '-') titleWithTime
+ 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 =
+ T.concat
+ [ renderResume (Ad.resume ad)
+ , "\n\n"
+ , renderDetail (Ad.detail ad)
+ ]
+
+renderResume :: Resume -> Text
+renderResume resume =
+ let formatPrice price = T.concat [" - ", price]
+ price = fromMaybe "" . fmap formatPrice . Resume.price $ resume
+ titleLine = T.concat [Resume.name resume, price]
+ in T.intercalate "\n" [titleLine, Resume.url resume]
+
+renderDetail :: Detail -> Text
+renderDetail detail =
+ T.concat
+ [ fromMaybe "−" (Detail.description detail)
+ , renderURLs "\n\nImages:" (Detail.images detail)
+ ]
+
+renderURLs :: Text -> [URL] -> Text
+renderURLs title [] = ""
+renderURLs title urls =
+ T.intercalate "\n" (title:urls)