Merge pull request #2 from andrewthad/add_thing

add helper for anchors
This commit is contained in:
Andrew Martin 2016-11-16 16:49:02 -05:00 committed by GitHub
commit 8ed64f1d2b

View File

@ -9,6 +9,7 @@ module Yesod.Colonnade
, stringCell
, textCell
, builderCell
, anchorCell
) where
import Yesod.Core
@ -18,6 +19,7 @@ import Control.Monad
import Data.Monoid
import Data.String (IsString(..))
import qualified Colonnade.Encoding as Encoding
import qualified Data.Text as Text
import qualified Data.Text.Lazy as LText
import qualified Data.Text.Lazy.Builder as TBuilder
@ -45,6 +47,11 @@ textCell = cell . toWidget . toHtml
builderCell :: TBuilder.Builder -> Cell site
builderCell = cell . toWidget . toHtml . LText.toStrict . TBuilder.toLazyText
anchorCell :: (a -> Route site) -> (a -> WidgetT site IO ()) -> a -> Cell site
anchorCell getRoute getContent a = cell $ do
urlRender <- getUrlRender
aTag [(Text.pack "href",urlRender (getRoute a))] (getContent a)
-- | This determines the attributes that are added
-- to the individual @li@s by concatenating the header\'s
-- attributes with the data\'s attributes.
@ -99,7 +106,7 @@ widgetFromCell ::
widgetFromCell f (Cell attrs contents) =
f attrs contents
tr,tbody,thead,tableEl,td,th,ul,li ::
tr,tbody,thead,tableEl,td,th,ul,li,aTag ::
[(Text,Text)] -> WidgetT site IO () -> WidgetT site IO ()
tableEl str b = [whamlet|
<table *{str}>^{b}
@ -125,4 +132,7 @@ ul str b = [whamlet|
li str b = [whamlet|
<li *{str}>^{b}
|]
aTag str b = [whamlet|
<a *{str}>^{b}
|]