Skip to content

Commit

Permalink
cant truncate the remainder
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed May 7, 2011
1 parent 912df55 commit f6c395b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Yesod/Goodies/Paginate.hs
Expand Up @@ -50,23 +50,29 @@ paginate opts xs = do
displayPage (showItems opts) page

determinePage :: Int -> Int -> [a] -> Page a
determinePage p per xs = go $ length xs `div` per
determinePage p per xs = go $ length xs `divPlus` per
where
go pages
| pages <= 1 = Page (1, xs) [] []
| pages < p = determinePage pages per xs
| otherwise = let items = take per $ drop ((p - 1) * per) xs
in Page (p, items) [1..p-1] [p+1..pages]

displayPage :: ([a] -> GWidget s m()) -> Page a -> GWidget s m ()
divPlus :: Int -> Int -> Int
x `divPlus` y = (\(n, r) -> if r == 0 then n else n + 1) $ x `divMod` y

displayPage :: ([a] -> GWidget s m ()) -> Page a -> GWidget s m ()
displayPage doShow (Page (this, items) prev next) = do
-- make the page listing a bit more apprope
addCassius [cassius|
ul.pagination
margin: 5px 0px;
padding: 0px;
text-align: center
.pagination li
display: inline
list-style-type: none
margin: 0px;
padding: 0px 3px
text-align: center
.pagination li.this_page
Expand Down

0 comments on commit f6c395b

Please sign in to comment.