Just create kaminari-hanami gem! And let me know! I'm happy to put it under /kaminari organization (if you'd like to) This should be much easier now, I guess
my own problems Dealing with PRs/issues is to deal with other people's problems (Without being paid) Which is not always fun Maybe I'm not a very good gem maintainer
configure for the plugin Don't let the users include some special Modules from the plugin Don't let the users call some weird method to let the plugin work These could be done via callbacks that Rails provides
A decorator is essentially a view helper (alternative to app/helpers/*_helper.rb) A Decorator is a pure Ruby Module Mixed in to model instances via `Module#extend` Automagically only in Action View's context
# app/decorators/article_decorator.rb class ArticleDecorator < Draper::Decorator delegate_all def publication_status published? ? "Published at #{published_date}" : "Unpublished" end def published_date object.published_at.strftime("%A, %B %e") end def emphatic h.content_tag(:strong, "Awesome") end end
Your Own? You just found a bug, and you could fix it => send a PR You basically liked it, but you wanted to add big changes => fork You didn't like its design/philosophy => build your own
in the Controller layer Which is IMO wrong Decorators should automatically work in view files Just like *_helpers.rb Who wants to write `include ApplicationHelper` in every view file? Explicitly calling `.decorate` method is like doing this
be named ArticleDecorator, and be placed in app/decorators/article_decorator.rb The Rails way that you're all familiar with Everyone likes this over writing something like "config/decorators.xml", right?
that are passed from controllers to views Also, we want to decorate collections Decorate each model instance in AR::Relation objects that are passed from controllers to views But we don't want ActiveDecorator to kick AR queries because of doing this
do |v| if v.is_a? ActiveRecord::Relation v.each do |record| ActiveDecorator::Decorator.instance.decorate record end else ActiveDecorator::Decorator.instance.decorate v end end hash ennd
defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation) && !obj.is_a? (ActiveDecorator::RelationDecorator) if obj.respond_to?(:records) obj.extend ActiveDecorator::RelationDecorator end else d = decorator_for obj.class return obj unless d obj.extend d unless obj.is_a? d end end module RelationDecorator def records super.tap do |arr| ActiveDecorator::Decorator.instance.decorate arr end end ennd
= Article.find(params[:id]) end # app/decorators/article_decorator.rb class ArticleDecorator def publication_status published? ? "Published at #{published_date}" : "Unpublished" end def published_date published_at.strftime("%A, %B %e") end def emphatic content_tag(:strong, "Awesome") end end
end # app/decorators/article_decorator.rb class ArticleDecorator < Draper::Decorator delegate_all def publication_status published? ? "Published at #{published_date}" : "Unpublished" end def published_date object.published_at.strftime("%A, %B %e") end def emphatic h.content_tag(:strong, "Awesome") end end
app/controllers/articles_controller.rb def show @article = Article.find(params[:id]).decorate end # app/decorators/article_decorator.rb class ArticleDecorator < Draper::Decorator delegate_all def publication_status published? ? "Published at #{published_date}" : "Unpublished" end def published_date object.published_at.strftime("%A, %B %e") end def emphatic h.content_tag(:strong, "Awesome") end end
from scratch statuful_enum stands on shoulders of AR::Enum And we don't support multiple ORMs If we need to, we probably will follow the same strategy with kaminari
At least, a new major release doesn't have to support unsupported versions of Ruby / Rails Rails aggressively bumps supporting Ruby versions To keep the codebase maintainable To move the community forward I really this attitude Let's do this for your Rails plugins as well!
actions You can call the original action from the Engine via super Automatically fallbacks to super on error So we can deploy unstable code to production
strong default stack which is called "Omakase" Rails allows users to choose alternative libs, e.g. Sequel instead of AR, Haml instead of ERB I want to expand this a little bit more
too huge and slow I sometimes miss Rails 1.x simplicity We don't need all Rails features for each of our apps As we're deploying the whole framework, we're loading so many unused things in production Just like Kaminari's case that I showed in this presentation
that are compatible with the default Rails parts Just like DOS/V PC parts You can choose Intel or AMD, ATI or nvidia, just combine them then that'll make a PC Mainly for speed, memory usage
the speed of AR1 query I want a simpler I18n that runs faster. I don't use String interpolations. Our language doesn't have pluralization form. So I18n can be simpler I want English only Rails. No I18n is needed for my app I want AR model instance not to create tons of Objects per each attribute. Just a Hash like AR3 was enough My app doesn't have to support Windows. I want Rails that deals JSON only. My Rails app has no HTML view I don't care about Thread-safeness. I don't use threaded servers
to AR queries A simpler and faster I18n alternative A routing engine Faster view template resolver Faster template renderer that cannot handle any other encodings than UTF8 Faster `url_for` Faster HashWithIndifferentAccess