Open summera opened 9 years ago
Cool! Loving the idea + implementation. We have to be careful, though. The pagination I suggest in the blog post doesn't follow any MIME format (like HAL or Collection-JSON), I made it up to demonstrate how Roar works.
Everything we merge into Roar's core will be used by people as they might assume we're following a standard (the only standard we follow is the Roar standard). That's the same with link
- I just added this to Roar core to illustrate how hypermedia could work and people picked it up and now we have a semi-defined "Roar format" specification.
We should either discuss a generic format (I am secretly working on Object-HAL with @mikekelly) or we should move this into a gem (either roar-contrib
or roar-pagination
). If we merge, this will get us into "specification trouble".
Don't get me wrong @summera - I love what you did! We just have to be careful with core additions (lesson learned :wink: ). What you think?
@apotonick Yea! Sounds good to me. ;) I'm cool with discussing a generic format and getting a roar-pagination
gem out there in the mean time.
Am I wrong in thinking that this pagination implementation would follow the HAL standard by simply including Roar::Representer::JSON::HAL
instead of Roar::Representer::JSON
like so?
class VenuesRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include Roar::Rails::PageRepresenter
end
Not sure how pagination is defined in HAL - I don't recall that being specified in the official document at all! That's why I'm cautious about merging this.
I also checked your other PR #92 which could go into your roar-contribs
gem, too. Again, I tend not to merge this generic behaviour into Roar core. This will set a half-baked standard for representing collections which I haven't completely thought through, yet. So it's better to extract that now, work out good practises and then define a standard (otherwise we'd have to deprecate and change-manage all that, which is usually quite some work).
Are you ok with that? Thanks for your work and trying to help others by publishing what you found helpful - this is exactly how Open-Source is meant to work! :heart:
Yep, no problem. I agree :100: . I'll get crankin on a roar-contribs
gem and keep you updated
@apotonick Finally got the time to get started on roar-contrib. Haven't made a release yet. Let me know if you have any comments/suggestions :grinning:
That is incredibly cool, @summera, especially because you set a standard for discussion. This gem will help many people understanding how some things work in Roar.
Please, keep me in the loop and I will promote it. :heart:
This is a
PageRepresenter
based off @apotonick blog post. It can be used with Kaminari or will_paginate to easily include pagination with your Decorator Representers.This can also be used with the
CollectionRepresenter
(https://github.com/apotonick/roar-rails/pull/92) to create a paginated representerI updated the README with an explanation.