[Catalyst] Re: OT: Better TT pager?

Aristotle Pagaltzis pagaltzis at gmx.de
Wed Dec 24 23:18:32 GMT 2008


* Jesse Sheidlower <jester at panix.com> [2008-12-23 12:45]:
> Does someone have a model I can steal from?

I have something pretty close to that. Not entirely happy insofar
as that I want to add the ability show a few links to skip 10 and
20 pages as appropriate, and it’s not abstracted as it should be,
but as a starting point it should work.

    USE decimal = format('%d') ;
    BLOCK pagination ;
      IF NOT page ; page = 0 ; END ;
      last_page = decimal( ( num_trials - 1 ) / per_page );

      IF last_page ;
        %]<div class="pagination">[%
        %]<a href="[% c.req.uri_with( page = [] ) %]"[% ' class="current"' IF NOT page %]>1</a>[%

        linked_page = page - 4 ;
        IF linked_page < 1 ; linked_page = 1 ; END ;

        until_page = linked_page + 7 ;
        IF last_page <= until_page ;
          until_page = last_page - 1 ;
          linked_page = until_page - 7 ;
          IF linked_page < 1 ; linked_page = 1 ; END ;
        END ;

        '<i>&#x2026;</i>' IF 1 < linked_page ;

        WHILE ( linked_page <= until_page ) AND ( linked_page < last_page ) ;
          %]<a href="[% c.req.uri_with( page = linked_page ) %]"[% ' class="current"' IF page == linked_page %]>[% linked_page + 1 %]</a>[%
          linked_page = linked_page + 1 ;
        END ;

        '<i>&#x2026;</i>' IF linked_page < last_page ;
        %]<a href="[% c.req.uri_with( page = last_page ) %]"[% ' class="current"' IF page == last_page %]>[% last_page + 1 %]</a>[%

        %]</div>[%
      END ;
    END ;

This is also a perfect demonstration of why I say that TT sucks.
This should by all rights be handled in the template since it’s
display logic, but writing it in that TT mini-language rather
than Perl is fugly. And PERL and RAWPERL blocks have their own
problems. Anyway. Someday I’ll quit yapping and write some code.

The CSS for styling that looks like this:

    div.pagination {
        margin: 1.1em 0 0.5em;
        text-align: right;
        padding: 0.2em 0;
    }

    div.pagination i {
        font-style: normal;
    }

    div.pagination a:link,
    div.pagination a:visited {
        border: 1px solid #359;
        background-color: #f0f0e6;
        padding: 0.1em 0.3em;
        margin: 0 0.2em;
    }

    div.pagination a.current,
    div.pagination a:focus,
    div.pagination a:hover,
    div.pagination a:active {
        background-color: #47b;
        color: #fff;
    }

I’m not sure how selfcontained that is, but I can’t be bothered
to dig through the rest of my stylesheets right now.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list