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

Remove stringex as a dependency of core #2383

Merged
merged 3 commits into from
Nov 25, 2017
Merged

Remove stringex as a dependency of core #2383

merged 3 commits into from
Nov 25, 2017

Conversation

swcraig
Copy link
Contributor

@swcraig swcraig commented Nov 17, 2017

We already have ActiveSupport as part of Solidus, and stringex doesn't
do much else that ActiveSupport doesn't already do. We lose support for
translating non-ascii characters, but ActiveSupport#parameterize does
a pretty good job of replacing special characters for ones that can be
used in a valid URL.

This PR also introduces a pluggable taxon_url_parametizer_class that defaults to ActiveSupport::Inflector.

@@ -363,6 +363,15 @@ def payment_canceller
# Spree::CurrentStoreSelector
class_name_attribute :current_store_selector_class, default: 'Spree::StoreSelector::ByServerName'


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line detected.

permalink_tail ||= name.to_url
self.permalink_part = permalink_tail
permalink_tail ||= Spree::Config.string_inflection_class.parameterize(name)
self.permalink_part = Spree::Config.string_inflection_class.dasherize(permalink_tail)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why we are using two different methods here. Previously we only used one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stringex would "dasherize" everything as part of its to_url method. ActiveSupport::Inflector doesn't do that, so some specs related to this would fail (t2_child is expected to be convereted to t2-child, which ActiveSupport#parameterize alone does not do).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say delete the specs... but thats just me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can either create a new class which calls parameterize then dasherize, or we can just use parameterize.

Since we're already changing behaviour here I think it is fine to just use parameterize and update the specs to pass.

# @!attribute [rw] string_inflection_class
# @return [Class] a class that provides `#parameterize`, and `#dasherize`
# methods that both return Strings
class_name_attribute :string_inflection_class, default: 'ActiveSupport::Inflector'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a name more clearly scoped to what it does. We (through rials) use ActiveSupport::Inflector heavily for other things and this name shouldn't imply that we are overriding that. It should be clear that this is for URL parameterization only.

The question here is do we intend to use this for. If we intend to only use this class from Taxon, it should be called taxon_parametizer_class (or maybe taxon_url_parametizer_class). If we intend to move everything else over, we could call it parametizer_class (or maybe url_parametizer_class).

It's worth noting that friendly_id has some of its own logic and configuration for parameterization (though I believe it relies on Inflector.parameterize). I'm not sure we would want to lose that logic, but it would be nice if we generated URLs consistently.

Copy link
Contributor

@cbrunsdon cbrunsdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am good with this, whether or not we use two calls or one for dasherize/parameterize.

We can use this in `Taxon#set_permalink` to create valid url encoded
strings.
We already have ActiveSupport as part of Solidus, and stringex doesn't
do much else that ActiveSupport doesn't already do. We lose support for
translating non-ascii characters, but `ActiveSupport#parameterize` does
a pretty good job of replacing special characters for ones that can be
used in a valid URL.

This commit also updates some specs. `#parameterize` does not
"dasherize" the string like stringex used to.
We can use ActiveSupport instead.

`Spree::Config.taxon_url_parametizer_class` defaults to being
`ActiveSupport::Inflector`. This can be customized.
Copy link
Contributor

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks

@mamhoff mamhoff merged commit 94a9159 into solidusio:master Nov 25, 2017
@swcraig swcraig deleted the kill-stringex branch November 25, 2017 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants