diff options
Diffstat (limited to 'src/View')
-rw-r--r-- | src/View/Html/Ad.hs | 48 | ||||
-rw-r--r-- | src/View/Html/Design.hs | 1 | ||||
-rw-r--r-- | src/View/Plain/Ad.hs | 38 |
3 files changed, 43 insertions, 44 deletions
diff --git a/src/View/Html/Ad.hs b/src/View/Html/Ad.hs index 2d6bdb5..d8a3bae 100644 --- a/src/View/Html/Ad.hs +++ b/src/View/Html/Ad.hs @@ -7,8 +7,7 @@ module View.Html.Ad import Data.Text (Text) import qualified Data.Text as T import Data.Text.Lazy (toStrict) -import Data.Maybe (fromMaybe, catMaybes) -import Data.String (fromString) +import Data.Maybe (catMaybes) import Data.List (intersperse) import Data.Map (Map) import qualified Data.Map as M @@ -20,39 +19,40 @@ import qualified Text.Blaze.Html5.Attributes as A import Text.Blaze.Html.Renderer.Text (renderHtml) import Text.Blaze.Internal (textValue) -import Model.Ad -import qualified Model.Ad as A +import Model.Ad (Ad) +import qualified Model.Ad as Ad import Model.Resume (Resume) -import qualified Model.Resume as R +import qualified Model.Resume as Resume import Model.Detail (Detail) -import qualified Model.Detail as D +import qualified Model.Detail as Detail import Model.URL -import Model.Config +import Conf (Conf) +import qualified Conf import View.Html.Design -renderAds :: Config -> [Ad] -> Text -renderAds config = toStrict . renderHtml . (adsHtml config) +renderAds :: Conf -> [Ad] -> Text +renderAds conf = toStrict . renderHtml . (adsHtml conf) -adsHtml :: Config -> [Ad] -> Html -adsHtml config ads = do mapM_ (adHtml config) ads +adsHtml :: Conf -> [Ad] -> Html +adsHtml conf ads = do mapM_ (adHtml conf) ads -adHtml :: Config -> Ad -> Html -adHtml config ad = - let resume = A.resume ad - detail = A.detail ad +adHtml :: Conf -> Ad -> Html +adHtml conf ad = + let resume = Ad.resume ad + detail = Ad.detail ad in do resumeHtml resume - detailHtml config detail + detailHtml conf detail resumeHtml :: Resume -> Html resumeHtml resume = do H.h1 $ do - (toHtml . R.name $ resume) - case R.price resume of + (toHtml . Resume.name $ resume) + case Resume.price resume of Just price -> H.span ! A.class_ "price" @@ -60,17 +60,17 @@ resumeHtml resume = do $ toHtml price Nothing -> H.span "" - linkHtml (R.url resume) + linkHtml (Resume.url resume) -detailHtml :: Config -> Detail -> Html -detailHtml config detail = do - propertiesHtml (properties config) (D.properties detail) - case D.description detail of +detailHtml :: Conf -> Detail -> Html +detailHtml conf detail = do + propertiesHtml (Conf.properties conf) (Detail.properties detail) + case Detail.description detail of Just description -> descriptionHtml description Nothing -> H.div "" - mapM_ imageLinkHtml (D.images detail) + mapM_ imageLinkHtml (Detail.images detail) propertiesHtml :: [Text] -> Map Text Text -> Html propertiesHtml keys properties = diff --git a/src/View/Html/Design.hs b/src/View/Html/Design.hs index c33d991..6ef5659 100644 --- a/src/View/Html/Design.hs +++ b/src/View/Html/Design.hs @@ -8,7 +8,6 @@ module View.Html.Design import Data.Text.Lazy (Text) import qualified Data.Text.Lazy as T -import Data.Monoid ((<>)) import Clay diff --git a/src/View/Plain/Ad.hs b/src/View/Plain/Ad.hs index 5120226..75e35e2 100644 --- a/src/View/Plain/Ad.hs +++ b/src/View/Plain/Ad.hs @@ -5,7 +5,6 @@ module View.Plain.Ad , renderAds ) where -import Data.List (intersperse) import Data.Maybe (fromMaybe, catMaybes) import Data.Map (Map) import qualified Data.Map as M @@ -22,12 +21,13 @@ import qualified Model.Resume as Resume import Model.Detail (Detail) import qualified Model.Detail as Detail -import Model.URL -import Model.Config +import Model.URL (URL) +import Conf (Conf) +import qualified Conf -renderConsoleAds :: Config -> Text -> [Ad] -> Text -renderConsoleAds config time ads = - let (title, message) = renderAds config ads +renderConsoleAds :: Conf -> Text -> [Ad] -> Text +renderConsoleAds conf time ads = + let (title, message) = renderAds conf ads titleWithTime = T.concat [ "\n[" @@ -44,10 +44,10 @@ renderConsoleAds config time ads = , message ] -renderAds :: Config -> [Ad] -> (Text, Text) -renderAds config ads = +renderAds :: Conf -> [Ad] -> (Text, Text) +renderAds conf ads = let titleMessage = renderTitle $ length ads - adsMessage = T.intercalate "\n\n" . map (renderAd config) $ ads + adsMessage = T.intercalate "\n\n" . map (renderAd conf) $ ads in (titleMessage, adsMessage) renderTitle :: Int -> Text @@ -63,31 +63,31 @@ renderTitle count = , if count > 1 then "s" else "" ] -renderAd :: Config -> Ad -> Text -renderAd config ad = +renderAd :: Conf -> Ad -> Text +renderAd conf ad = T.concat [ renderResume (Ad.resume ad) , "\n" - , renderDetail config (Ad.detail ad) + , renderDetail conf (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] + getPrice = fromMaybe "" . fmap formatPrice . Resume.price $ resume + titleLine = T.concat [Resume.name resume, getPrice] in T.intercalate "\n" [titleLine, Resume.url resume] -renderDetail :: Config -> Detail -> Text -renderDetail config detail = +renderDetail :: Conf -> Detail -> Text +renderDetail conf detail = T.concat - [ renderProperties (properties config) (Detail.properties detail) + [ renderProperties (Conf.properties conf) (Detail.properties detail) , fromMaybe "−" (Detail.description detail) , renderURLs "\n\nImages:" (Detail.images detail) ] renderProperties :: [Text] -> Map Text Text -> Text -renderProperties [] properties = "" +renderProperties [] _ = "" renderProperties keys properties = T.concat [ "\n" @@ -102,6 +102,6 @@ renderProperty properties key = (M.lookup key properties) renderURLs :: Text -> [URL] -> Text -renderURLs title [] = "" +renderURLs _ [] = "" renderURLs title urls = T.intercalate "\n" (title:urls) |