Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Pagination links in list mode

#170

Hey there

I've just downloaded and installed the will_paginate plugin, which

works great on my blog app. and I'd like to thank you for creating it :)

I wanted to extend the functionality of the plugin to support a

rendering mode with an unordered list rather than a DIV with spans /

links inside it, as some XHTML developers like to render a list of

links that way.

My fix adds the option to pass :list_mode => true as a parameter to

the will_pagination plugin, which will render the pagination as an

unordered list. The default value of this parameter is :list_mode =>

false so that it behaves as before if not told otherwise.

Additionally, I added an optional :id parameter, which will add an "id" attribute to the pagination wrapping element (whether UL or DIV) for easier targeting via JavaScript.

I hope that you consider updating the plugin to support the above, or

grant me permission to upload it to my webspace with this amendment.

Reported by Zohar Arad · December 16th, 2007 @ 09:41 PM

State: resolved
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Mislav
    Mislav
    • State changed from new to open
    • Title changed from will_paginate enhancement to list mode enhancement

    Hi, thanks for the suggestion/patch!

    I've been planing to make a list mode for some time now, your code might help me to do it faster :)

    December 19th, 2007 @ 03:24 PM

  2. Zohar Arad
    Zohar Arad

    Hey

    Hope my code helps :)

    Please let me know if there's anything else I can do regarding this.

    Regards

    Zohar

    December 19th, 2007 @ 10:28 PM

  3. Mislav
    Mislav
    • Title changed from list mode enhancement to [idea] list mode
    • Assigned user changed from Chris Wanstrath to Mislav

    December 25th, 2007 @ 04:32 AM

  4. omarqureshi
    omarqureshi
    • Tag set to will_paginate

    Sounds like a good idea, would definately be up for this patch

    July 3rd, 2008 @ 01:36 PM

  5. Mislav
    Mislav
    • Title changed from [idea] list mode to Pagination links in list mode
    • State changed from open to resolved
    • Tag changed from will_paginate to html, will_paginate

    I've given this a lot of thought and resolved not to support list mode in core. I just don't see the semantic advantage, particularly when considering an unordered list.

    Here is a drop-in link renderer that can do what you wanted. (This works on the "agnostic" branch of will_paginate, soon to be released.)

    
    class ListRenderer < WillPaginate::ViewHelpers::LinkRenderer
    
      def to_html
        html = pagination.map do |item|
          item_html = item.is_a?(Fixnum) ? page_number(item) : send(item)
          tag(:li, item_html)
        end.join(@options[:separator])
    
        @options[:container] ? html_container(html) : html
      end
    
      def html_container(html)
        tag(:ol, html, container_attributes)
      end
    
    end
    

    October 13th, 2008 @ 02:47 AM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.