-
Notifications
You must be signed in to change notification settings - Fork 164
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
Global config for slug builder #166
Comments
An alternative solution might be to include a module in your models to extend them.
|
That would work as well, but I see the config approach in many other gems, think it's cleaner overall. |
@johnnyshields I agree that a global configuration for this is better and I am very interested in such a pull request. A few thoughts on the API:
That said I believe stringex should be an optional dependency since it is rather heavy and not applicable in all settings. Can you think of a way to make stringex an optional dependency that is pulled in by default? |
@astjohn I agree that this solution would work, but if a user forget to include the module then it will silently "fail". That is why I think a global configuration is better. |
@digitalplaywright agreed on all your points above. For making Stringex optional, what I would propose is that if |
By the way, I'm not sure when I'll get around to this PR, but it definitely is on my to-do list. |
One more note--are there any other settings which should be made globally configurable (+ locally overrideable)? |
@johnnyshields Your solution for making stringex optional seems reasonable. It breaks the API though and would require a major version change. However, instead of truncating all non-alpha-numberic-chars we could use URI::Escape (see http://apidock.com/ruby/URI/Escape/escape) together with converting any punctuation/whitespace to '-' char. @astjohn What do you think? The find strategy should also be globally configurable (see https://github.com/digitalplaywright/mongoid-slug#custom-find-strategies). Otherwise I can't think of any obvious candidates. |
@digitalplaywright, I think if this is something that should have exposure in the API, then it's a great approach. You're correct on the major version change as well if you'd like to drop stringex completely. |
Agreed on URI::Escape. |
@johnnyshields I noticed that URI::encode is deprecated in favor of ERB::Util.url_encode (See http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB/Util.html#method-c-url_encode). @astjohn I think the URL encoding mechanism should be exposed in the API, which is why we already have custom slugging, but I am on the fence about dropping stringex as a dependency. Why drop stringex:
Why not:
@astjohn @johnnyshields Any thoughts on pro/cons of dropping the stringex dependency? |
I agree to drop it with graceful degradation. The only con I can think of is that if users don't pay attention when upgrading it may bite them, but a major version bump is fair enough to cover this. |
@johnnyshields We should implement this change. I think it will be a great addition. |
Yep, I think so too. I have a reference implementation of this sort of config in the Mongoid Userstamp gem. Unfortunately I'm a bit swamped at my startup at the moment, but may be able to find some time mid-next month. It's on my todo-list. |
Issue mongoid#166 Global slug builder
@johnnyshields: I added above feature. Thanks for this discussion. It helped me to implement the solution. I hope this will help. |
Ref #166 Global config for slug builder
@dblock I think we can close this issue. |
Closed via #196. |
FYI was released in 5.3.0 |
I'd like to raise a PR for a global config for alternate slug generation (currently it must be configured in each model.) Something like the following in an initializer:
In most cases, I would think users (like myself) would want the slug logic to be consistent across their app. In my case, I need to convert Japanese to alphabet and current stringex logic doesn't do a good job (it assumes the characters as Chinese, not Japanese)
Please confirm you'd accept this PR if raised?
The text was updated successfully, but these errors were encountered: