From c188d728bbdd56e5b7b536837f7840d3c17929be Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Sat, 25 Feb 2017 15:40:07 -0500 Subject: [PATCH] add anchorWidget --- yesod-colonnade/src/Yesod/Colonnade.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/yesod-colonnade/src/Yesod/Colonnade.hs b/yesod-colonnade/src/Yesod/Colonnade.hs index 31e5df6..b54ac2a 100644 --- a/yesod-colonnade/src/Yesod/Colonnade.hs +++ b/yesod-colonnade/src/Yesod/Colonnade.hs @@ -13,6 +13,7 @@ module Yesod.Colonnade , textCell , builderCell , anchorCell + , anchorWidget -- * Apply , encodeHeadedWidgetTable , encodeHeadlessWidgetTable @@ -68,14 +69,23 @@ textCell = cell . toWidget . toHtml builderCell :: TBuilder.Builder -> Cell site builderCell = cell . toWidget . toHtml . LText.toStrict . TBuilder.toLazyText --- | Creata a 'Cell' whose content is hyperlinked by wrapping +-- | Create a 'Cell' whose content is hyperlinked by wrapping -- it in an @\@. anchorCell :: (a -> Route site) -- ^ Route that will go in @href@ attribute -> (a -> WidgetT site IO ()) -- ^ Content wrapped by @@ tag -> a -- ^ Value -> Cell site -anchorCell getRoute getContent a = cell $ do +anchorCell getRoute getContent = cell . anchorWidget getRoute getContent + +-- | Create a widget whose content is hyperlinked by wrapping +-- it in an @\@. +anchorWidget :: + (a -> Route site) -- ^ Route that will go in @href@ attribute + -> (a -> WidgetT site IO ()) -- ^ Content wrapped by @@ tag + -> a -- ^ Value + -> WidgetT site IO () +anchorWidget getRoute getContent a = do urlRender <- getUrlRender a_ (HA.href (toValue (urlRender (getRoute a)))) (getContent a)