From 389d979eb3eaa18beb8a6da9f4a03bdb6acc1722 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 18 Apr 2015 21:59:22 +0200 Subject: Parsing utag_list from a detail page and showing the keys that are given in the configuration file --- src/View/Html/Ad.hs | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/View/Html') diff --git a/src/View/Html/Ad.hs b/src/View/Html/Ad.hs index fce164e..f3d9ece 100644 --- a/src/View/Html/Ad.hs +++ b/src/View/Html/Ad.hs @@ -7,9 +7,11 @@ module View.Html.Ad import Data.Text (Text) import qualified Data.Text as T import Data.Text.Lazy (toStrict) -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe, catMaybes) import Data.String (fromString) import Data.List (intersperse) +import Data.Map (Map) +import qualified Data.Map as M import Text.Blaze.Html import Text.Blaze.Html5 (Html) @@ -28,20 +30,21 @@ import Model.Detail (Detail) import qualified Model.Detail as D import Model.URL +import Model.Config -renderAds :: [Ad] -> Text -renderAds = toStrict . renderHtml . adsHtml +renderAds :: Config -> [Ad] -> Text +renderAds config = toStrict . renderHtml . (adsHtml config) -adsHtml :: [Ad] -> Html -adsHtml ads = H.div (mapM_ adHtml ads) +adsHtml :: Config -> [Ad] -> Html +adsHtml config ads = H.div (mapM_ (adHtml config) ads) -adHtml :: Ad -> Html -adHtml ad = +adHtml :: Config -> Ad -> Html +adHtml config ad = let resume = A.resume ad detail = A.detail ad in do resumeHtml resume - detailHtml detail + detailHtml config detail resumeHtml :: Resume -> Html resumeHtml resume = @@ -55,8 +58,9 @@ resumeHtml resume = H.h1 (toHtml title) linkHtml url -detailHtml :: Detail -> Html -detailHtml detail = do +detailHtml :: Config -> Detail -> Html +detailHtml config detail = do + propertiesHtml (properties config) (D.properties detail) case D.description detail of Just description -> descriptionHtml description @@ -64,6 +68,20 @@ detailHtml detail = do H.div "" mapM_ imageLinkHtml (D.images detail) +propertiesHtml :: [Text] -> Map Text Text -> Html +propertiesHtml keys properties = + H.dl $ + sequence_ $ catMaybes $ map (propertyHtml properties) keys + +propertyHtml :: Map Text Text -> Text -> Maybe Html +propertyHtml properties key = + fmap + (\value -> do + H.dt (toHtml key) + H.dd (toHtml value) + ) + (M.lookup key properties) + descriptionHtml :: Text -> Html descriptionHtml = H.p . sequence_ . intersperse H.br . fmap toHtml . T.lines -- cgit v1.2.3