Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for specifying alternate views directory #1026

Open
mokolabs opened this issue May 20, 2020 · 4 comments
Open

Add config option for specifying alternate views directory #1026

mokolabs opened this issue May 20, 2020 · 4 comments

Comments

@mokolabs
Copy link

Currently, if you need to specify an alternate directory for Kaminari templates, you must do so by passing an option to the paginate helper.

<%= paginate @users, views_prefix: 'templates' %>

While this option does work, it's not especially DRY. Most folks probably need to change templates for their entire application, so adding this option every time you add pagination to a view seems a bit repetitive.

So, to DRY things up, it would be nice if Kaminari supported a config option for the views prefix.

Kaminari.configure do |config|
  config.views_prefix = 'templates'
end

It would also be nice to allow full customization here. So, instead of changing just the parent directory of the kaminari directory with the views prefix, you should be able to change the complete path to your templates.

Kaminari.configure do |config|
 config.views_path = 'app/views/pagination'
end

This could replace views_prefix entirely... or they could co-exist if there's still a good reason to keep the prefix in place.

@yuki24
Copy link
Member

yuki24 commented May 27, 2020

We already have a conventional way for organizing the default pagination templates. Have you tried putting the templates in app/views/kaminari/? Or did you run into any problems with it?

@mokolabs
Copy link
Author

No problem. I'm already putting my templates in app/views/kaminari. It works fine. 👍

I'm just suggesting that it would also be nice to have complete control over where kaminari templates are stored within app/views via a custom config option.

To be clear, in my example above, the templates would be stored in app/views/pagination -- with no 'kaminari' subfolder.

For bigger apps with larger teams, folks may not be familiar with kaminari (as awesome as it is), so it would be nice to store the templates in a directory with a more obvious and generic name that describes their function and that has no connection to the gem itself.

Make sense?

@yuki24
Copy link
Member

yuki24 commented May 28, 2020

The view_prefix and theme options definitely have some overlapping areas and there is definitely room for improvement. We've added view_prefix exclusively for the cells gem (and its plugin) but I wonder how important it is today.

For bigger apps with larger teams, folks may not be familiar with kaminari (as awesome as it is), so it would be nice to store the templates in a directory with a more obvious and generic name that describes their function and that has no connection to the gem itself.

That makes sense. It shouldn't be too difficult to do that as it's basically a single line change(see the line below). If we were to allow for changing that, it should probably be only a global option since having these similar options are quite confusing.

Another minor concern is conflict with other pagination gems like will_paginate. If you have multiple projects that depend on a different paginator then having a consistent directory name could actually be confusing, because the APIs are not exactly the same.

@ruurd
Copy link
Contributor

ruurd commented Dec 21, 2020

@mokolabs, @yuki24 no actually in the face of convention over configuration it does not make sense at all. The view templates are in the place they should be given the convention. Any developer using Rails for a bit knows what is inside /app/views and it's not that hard to guess that kaminari templates are in /app/views/kaminari.

Making it configurable mandates getting the configured value every time making finding templates slower even if by a tiny amount. For what? A single use-case? Not worth it I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants