add anchorWidget

This commit is contained in:
Andrew Martin 2017-02-25 15:40:07 -05:00
parent c646c467c9
commit c188d728bb

View File

@ -13,6 +13,7 @@ module Yesod.Colonnade
, textCell , textCell
, builderCell , builderCell
, anchorCell , anchorCell
, anchorWidget
-- * Apply -- * Apply
, encodeHeadedWidgetTable , encodeHeadedWidgetTable
, encodeHeadlessWidgetTable , encodeHeadlessWidgetTable
@ -68,14 +69,23 @@ textCell = cell . toWidget . toHtml
builderCell :: TBuilder.Builder -> Cell site builderCell :: TBuilder.Builder -> Cell site
builderCell = cell . toWidget . toHtml . LText.toStrict . TBuilder.toLazyText 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 @\<a\>@. -- it in an @\<a\>@.
anchorCell :: anchorCell ::
(a -> Route site) -- ^ Route that will go in @href@ attribute (a -> Route site) -- ^ Route that will go in @href@ attribute
-> (a -> WidgetT site IO ()) -- ^ Content wrapped by @<a>@ tag -> (a -> WidgetT site IO ()) -- ^ Content wrapped by @<a>@ tag
-> a -- ^ Value -> a -- ^ Value
-> Cell site -> 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 @\<a\>@.
anchorWidget ::
(a -> Route site) -- ^ Route that will go in @href@ attribute
-> (a -> WidgetT site IO ()) -- ^ Content wrapped by @<a>@ tag
-> a -- ^ Value
-> WidgetT site IO ()
anchorWidget getRoute getContent a = do
urlRender <- getUrlRender urlRender <- getUrlRender
a_ (HA.href (toValue (urlRender (getRoute a)))) (getContent a) a_ (HA.href (toValue (urlRender (getRoute a)))) (getContent a)