yesod-paginator 0.4.1 → 0.9
raw patch · 3 files changed
+32/−16 lines, 3 files
Files
- Yesod/Paginator.hs +5/−1
- Yesod/Paginator/Widget.hs +26/−14
- yesod-paginator.cabal +1/−1
Yesod/Paginator.hs view
@@ -62,7 +62,11 @@ paginate :: Yesod m => Int -> [a] -> HandlerT m IO ([a], WidgetT m IO ()) paginate = paginateWith defaultWidget -paginateWith :: Yesod m => (Int -> Int -> Int -> t) -> Int -> [a] -> HandlerT m IO ([a], t)+paginateWith :: Yesod m+ => PageWidget m+ -> Int+ -> [a]+ -> HandlerT m IO ([a], WidgetT m IO ()) paginateWith widget per items = do p <- getCurrentPage
Yesod/Paginator/Widget.hs view
@@ -6,6 +6,7 @@ ( getCurrentPage , paginationWidget , defaultWidget+ , defaultPageWidgetConfig , PageWidget , PageWidgetConfig(..) ) where@@ -17,15 +18,18 @@ import qualified Data.Text as T +-- | currentPage, itemsPerPage, totalItems -> widget type PageWidget m = Int -> Int -> Int -> WidgetT m IO () data PageWidgetConfig = PageWidgetConfig- { prevText :: Text -- ^ The text for the 'previous page' link.- , nextText :: Text -- ^ The text for the 'next page' link.- , pageCount :: Int -- ^ The number of page links to show- , ascending :: Bool -- ^ Whether to list pages in ascending order.- , showEllipsis :: Bool -- ^ Whether to show an ellipsis if there are- } -- more pages than pageCount+ { prevText :: Text -- ^ The text for the 'previous page' link.+ , nextText :: Text -- ^ The text for the 'next page' link.+ , pageCount :: Int -- ^ The number of page links to show+ , ascending :: Bool -- ^ Whether to list pages in ascending order.+ , showEllipsis :: Bool -- ^ Whether to show an ellipsis if there are+ -- more pages than pageCount+ , listClasses :: [Text] -- ^ Additional classes for top level list+ } -- | Individual links to pages need to follow strict (but sane) markup -- to be styled correctly by bootstrap. This type allows construction@@ -55,17 +59,22 @@ <a>#{cnt} |] +-- | Default widget config provided for easy overriding of only some fields.+defaultPageWidgetConfig :: PageWidgetConfig+defaultPageWidgetConfig = PageWidgetConfig { prevText = "«"+ , nextText = "»"+ , pageCount = 9+ , ascending = True+ , showEllipsis = True+ , listClasses = ["pagination"]+ }+ defaultWidget :: Yesod m => PageWidget m-defaultWidget = paginationWidget $ PageWidgetConfig { prevText = "«"- , nextText = "»"- , pageCount = 9- , ascending = True- , showEllipsis = True- }+defaultWidget = paginationWidget defaultPageWidgetConfig -- | A widget showing pagination links. Follows bootstrap principles. -- Utilizes a \"p\" GET param but leaves all other GET params intact.-paginationWidget :: Yesod m => PageWidgetConfig -> Int -> Int -> Int -> WidgetT m IO ()+paginationWidget :: Yesod m => PageWidgetConfig -> PageWidget m paginationWidget (PageWidgetConfig {..}) page per tot = do -- total / per + 1 for any remainder let pages = (\(n, r) -> n + (min r 1)) $ tot `divMod` per@@ -74,12 +83,15 @@ curParams <- handlerToWidget $ liftM reqGetParams getRequest [whamlet|$newline never- <ul>+ <ul class="#{cls}"> $forall link <- buildLinks page pages ^{showLink curParams link} |] where+ -- | Concatenate all additional classes.+ cls = T.intercalate " " listClasses+ -- | Build up each component of the overall list of links. We'll -- use empty lists to denote ommissions along the way then -- concatenate.
yesod-paginator.cabal view
@@ -1,5 +1,5 @@ name: yesod-paginator-version: 0.4.1+version: 0.9 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