yesod-paginator 0.10.1 → 0.11.0
raw patch · 2 files changed
+32/−4 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Yesod.Paginator.Widget: Disabled :: Text -> Text -> PageLink
+ Yesod.Paginator.Widget: Enabled :: Int -> Text -> Text -> PageLink
+ Yesod.Paginator.Widget: data PageLink
+ Yesod.Paginator.Widget: showLink :: [(Text, Text)] -> PageLink -> WidgetT m IO ()
+ Yesod.Paginator.Widget: simplePaginationWidget :: Yesod m => PageWidgetConfig -> PageWidget m
Files
- src/Yesod/Paginator/Widget.hs +31/−3
- yesod-paginator.cabal +1/−1
src/Yesod/Paginator/Widget.hs view
@@ -7,8 +7,11 @@ , paginationWidget , defaultWidget , defaultPageWidgetConfig+ , simplePaginationWidget , PageWidget , PageWidgetConfig(..)+ , PageLink(..)+ , showLink ) where import Yesod@@ -49,7 +52,7 @@ where updateGetParam :: [(Text,Text)] -> (Text,Text) -> Text- updateGetParam getParams (p, n) = (T.cons '?') . T.intercalate "&"+ updateGetParam getParams (p, n) = T.cons '?' . T.intercalate "&" . map (\(k,v) -> k `T.append` "=" `T.append` v) . (++ [(p, n)]) . filter ((/= p) . fst) $ getParams @@ -75,9 +78,9 @@ -- | A widget showing pagination links. Follows bootstrap principles. -- Utilizes a \"p\" GET param but leaves all other GET params intact. paginationWidget :: Yesod m => PageWidgetConfig -> PageWidget m-paginationWidget (PageWidgetConfig {..}) page per tot = do+paginationWidget PageWidgetConfig {..} page per tot = do -- total / per + 1 for any remainder- let pages = (\(n, r) -> n + (min r 1)) $ tot `divMod` per+ let pages = (\(n, r) -> n + min r 1) $ tot `divMod` per when (pages > 1) $ do curParams <- handlerToWidget $ liftM reqGetParams getRequest@@ -131,6 +134,31 @@ , lastLink , nextLink ]++-- | A simple widget that only shows next and previous links. Follows bootstrap+-- principles. Utilizes a \"p\" GET param but leaves all other GET params+-- intact. Uses the same config data type as the main pagination widget, but+-- ignores all of the values with the exception of the text for the next and+-- previous links.+simplePaginationWidget :: Yesod m => PageWidgetConfig -> PageWidget m+simplePaginationWidget PageWidgetConfig {..} page per tot = do+ -- total number of pages+ let pages = (\(n, r) -> n + min r 1) $ tot `divMod` per++ when (pages > 1) $ do+ curParams <- handlerToWidget $ liftM reqGetParams getRequest++ [whamlet|$newline never+ <ul class="pagination">+ $forall link <- buildLinks page pages+ ^{showLink curParams link}+ |]++ where+ buildLinks :: Int -> Int -> [PageLink]+ buildLinks pg pgs =+ [ Enabled (pg - 1) prevText "prev" | pg > 1 ] +++ [ Enabled (pg + 1) nextText "next" | pg < pgs ] -- | looks up the \"p\" GET param and converts it to an Int. returns a -- default of 1 when conversion fails.
yesod-paginator.cabal view
@@ -1,5 +1,5 @@ name: yesod-paginator-version: 0.10.1+version: 0.11.0 synopsis: A pagination approach for yesod description: Paginate a list showing a per-item widget and links to other pages homepage: http://github.com/pbrisbin/yesod-paginator