aboutsummaryrefslogtreecommitdiff
path: root/src/View/Html
diff options
context:
space:
mode:
Diffstat (limited to 'src/View/Html')
-rw-r--r--src/View/Html/Ad.hs38
1 files changed, 28 insertions, 10 deletions
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