ruhoh / ruhoh.rb

http://ruhoh.com
616 stars 69 forks source link

Paginators should support sort order independently from their collections (plugin, gist) #255

Open indolent-gnathostome opened 10 years ago

indolent-gnathostome commented 10 years ago

I have a collection that needs to:

This is a friendlier way to display some content, and makes each paginated url more bookmark-friendly.

The config.yml could support this with an optional 'sort' parameter within a collection's paginator:

# ...in config.yml:
posts:
  sort: ["date", "desc"]
  paginator:
    enable: true
    sort: 'asc' # <-- NEW OPTION (default: 'desc' )
# ...and so on

I've implemented this behavior as a plugin (+cucumber test), available in this gist:

Ideally, this would be a feature of the core paginator.

indolent-gnathostome commented 10 years ago

I updated the gist with a 'paginator_data' helper method. It moves the sorting logic out of the paginator method and returns a mustache-friendly data structure. Tests still pass.

plusjade commented 10 years ago

@indolent-gnathostome sorry for the long dely. I definitely appreciate the detailed gist. I am looking to include this functionality in ruhoh 3.0 so I'm currently studying your code, thanks!