aboutsummaryrefslogtreecommitdiff
path: root/src/View/Plain
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-04-18 21:59:22 +0200
committerJoris Guyonvarch2015-04-18 21:59:22 +0200
commit389d979eb3eaa18beb8a6da9f4a03bdb6acc1722 (patch)
tree9d475b868ad13162c0ecba42b2138058c2e2e68b /src/View/Plain
parent86f9991deeb44a6cc81044e61a9ad3ee001c5ced (diff)
Parsing utag_list from a detail page and showing the keys that are given in the configuration file
Diffstat (limited to 'src/View/Plain')
-rw-r--r--src/View/Plain/Ad.hs53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/View/Plain/Ad.hs b/src/View/Plain/Ad.hs
index 9dc5289..5120226 100644
--- a/src/View/Plain/Ad.hs
+++ b/src/View/Plain/Ad.hs
@@ -6,25 +6,28 @@ module View.Plain.Ad
) where
import Data.List (intersperse)
-import Data.Maybe (fromMaybe)
+import Data.Maybe (fromMaybe, catMaybes)
+import Data.Map (Map)
+import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Text as T
-import Model.Ad (Ad(..))
+import Model.Ad (Ad)
import qualified Model.Ad as Ad
-import Model.Resume (Resume(..))
+import Model.Resume (Resume)
import qualified Model.Resume as Resume
-import Model.Detail (Detail(..))
+import Model.Detail (Detail)
import qualified Model.Detail as Detail
import Model.URL
+import Model.Config
-renderConsoleAds :: Text -> [Ad] -> Text
-renderConsoleAds time ads =
- let (title, message) = renderAds ads
+renderConsoleAds :: Config -> Text -> [Ad] -> Text
+renderConsoleAds config time ads =
+ let (title, message) = renderAds config ads
titleWithTime =
T.concat
[ "\n["
@@ -41,10 +44,10 @@ renderConsoleAds time ads =
, message
]
-renderAds :: [Ad] -> (Text, Text)
-renderAds ads =
+renderAds :: Config -> [Ad] -> (Text, Text)
+renderAds config ads =
let titleMessage = renderTitle $ length ads
- adsMessage = T.intercalate "\n\n" . map renderAd $ ads
+ adsMessage = T.intercalate "\n\n" . map (renderAd config) $ ads
in (titleMessage, adsMessage)
renderTitle :: Int -> Text
@@ -60,12 +63,12 @@ renderTitle count =
, if count > 1 then "s" else ""
]
-renderAd :: Ad -> Text
-renderAd ad =
+renderAd :: Config -> Ad -> Text
+renderAd config ad =
T.concat
[ renderResume (Ad.resume ad)
- , "\n\n"
- , renderDetail (Ad.detail ad)
+ , "\n"
+ , renderDetail config (Ad.detail ad)
]
renderResume :: Resume -> Text
@@ -75,13 +78,29 @@ renderResume resume =
titleLine = T.concat [Resume.name resume, price]
in T.intercalate "\n" [titleLine, Resume.url resume]
-renderDetail :: Detail -> Text
-renderDetail detail =
+renderDetail :: Config -> Detail -> Text
+renderDetail config detail =
T.concat
- [ fromMaybe "−" (Detail.description detail)
+ [ renderProperties (properties config) (Detail.properties detail)
+ , fromMaybe "−" (Detail.description detail)
, renderURLs "\n\nImages:" (Detail.images detail)
]
+renderProperties :: [Text] -> Map Text Text -> Text
+renderProperties [] properties = ""
+renderProperties keys properties =
+ T.concat
+ [ "\n"
+ , T.concat (catMaybes $ map (renderProperty properties) keys)
+ , "\n"
+ ]
+
+renderProperty :: Map Text Text -> Text -> Maybe Text
+renderProperty properties key =
+ fmap
+ (\value -> T.concat [key, ": ", value, "\n"])
+ (M.lookup key properties)
+
renderURLs :: Text -> [URL] -> Text
renderURLs title [] = ""
renderURLs title urls =