add helper for anchors
This commit is contained in:
parent
8d2e834cf5
commit
a7e56dc39b
@ -9,6 +9,7 @@ module Yesod.Colonnade
|
|||||||
, stringCell
|
, stringCell
|
||||||
, textCell
|
, textCell
|
||||||
, builderCell
|
, builderCell
|
||||||
|
, anchorCell
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
@ -18,6 +19,7 @@ import Control.Monad
|
|||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
import Data.String (IsString(..))
|
import Data.String (IsString(..))
|
||||||
import qualified Colonnade.Encoding as Encoding
|
import qualified Colonnade.Encoding as Encoding
|
||||||
|
import qualified Data.Text as Text
|
||||||
import qualified Data.Text.Lazy as LText
|
import qualified Data.Text.Lazy as LText
|
||||||
import qualified Data.Text.Lazy.Builder as TBuilder
|
import qualified Data.Text.Lazy.Builder as TBuilder
|
||||||
|
|
||||||
@ -45,6 +47,11 @@ 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
|
||||||
|
|
||||||
|
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
|
-- | This determines the attributes that are added
|
||||||
-- to the individual @li@s by concatenating the header\'s
|
-- to the individual @li@s by concatenating the header\'s
|
||||||
-- attributes with the data\'s attributes.
|
-- attributes with the data\'s attributes.
|
||||||
@ -99,7 +106,7 @@ widgetFromCell ::
|
|||||||
widgetFromCell f (Cell attrs contents) =
|
widgetFromCell f (Cell attrs contents) =
|
||||||
f 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 ()
|
[(Text,Text)] -> WidgetT site IO () -> WidgetT site IO ()
|
||||||
tableEl str b = [whamlet|
|
tableEl str b = [whamlet|
|
||||||
<table *{str}>^{b}
|
<table *{str}>^{b}
|
||||||
@ -125,4 +132,7 @@ ul str b = [whamlet|
|
|||||||
li str b = [whamlet|
|
li str b = [whamlet|
|
||||||
<li *{str}>^{b}
|
<li *{str}>^{b}
|
||||||
|]
|
|]
|
||||||
|
aTag str b = [whamlet|
|
||||||
|
<a *{str}>^{b}
|
||||||
|
|]
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user