-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support the new starter frontend installation #276
Conversation
c65773f
to
485b404
Compare
@@ -15,6 +16,30 @@ def add_javascripts | |||
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_subscriptions\n" | |||
end | |||
|
|||
def copy_starter_frontend_files | |||
return if options[:frontend] != 'starter' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho return unless options[:frontend] == 'starter'
is better for readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestions @Naokimi. I tend to use unless only when the condition doesn't contain a negation, that's because it would be a double negation, IMO, always harder to read. I think I took this reasoning line from this blog post years ago: https://signalvnoise.com/posts/2699-making-sense-with-rubys-unless. BTW, I'm open to invert it, let me know your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'm also of the school that you should avoid negations as much as possible, so since return if options[:frontend] != 'starter'
contains a negation (NOT equal to) I'm suggesting removing the negation (-> equal to) while using unless
but in any case in this specific case what you wrote is still readable enough, so it wouldn't be a big deal to leave it as it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you are right. Personally, I still prefer the negation to be on the condition, so I think I'll leave it as is for now. But appreciate the conversation around this topic. Thanks again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kennyadsl. I left some comments. Interested in your thoughts.
@@ -6,6 +6,7 @@ class InstallGenerator < Rails::Generators::Base | |||
source_root File.expand_path('templates', __dir__) | |||
|
|||
class_option :auto_run_migrations, type: :boolean, default: false | |||
class_option :frontend, type: :string, default: 'legacy' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use the 'legacy'
value anywhere. What about following the same pattern that @elia used in solidus_paypal_commerce_platform and, instead, have a starter_frontend
boolean option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a string instead of a boolean looks better to me, since more things could end up being frontends (api, graphql, etc) and being able to select the right integration seems like a better choice.
Anyways the name is classic
in the solidus installer, and I'm fine with both fixing it or moving it to a boolean, we can change later if necessary 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this format to follow the main installer. For sure I should at least change legacy
to classic
to follow that convention. Not sure which approach is best at this point, @elia do you have any thought?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we posted at the same time, but I'll restate my take: while right now I see using a string as the way forward I'm fine with both.
I other words I think we'll have a better understanding on how things "should be done" in a month or two, and we'll be able to codify it somewhere (e.g. in solidus_dev_support).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to classic
, but open to change while I wait for @waiting-for-dev opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also thought about the potential for adding new storefronts. However, I see it as a premature optimization, plus we won't add any other new frontend in the near future. Having code that does nothing looks off. We've been discussing whether to call it classic
or legacy
, but we could call it potato
, and it'd make no difference 😆 But I'm not super-against it, as it could help in the future to avoid breaking changes. However, I'd try to be consistent throughout the extension ecosystems, so we should do the same here and in the PayPal one.
lib/generators/solidus_subscriptions/install/install_generator.rb
Outdated
Show resolved
Hide resolved
RUBY | ||
end | ||
insert_into_file 'app/controllers/cart_line_items_controller.rb', after: "private\n" do | ||
<<-RUBY.strip_heredoc.indent(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same suggestion to use Ruby's built-in heredoc syntax to remove indentation.
<<-RUBY.strip_heredoc.indent(2) | ||
|
||
include SolidusSubscriptions::SubscriptionLineItemBuilder | ||
after_action :handle_subscription_line_items, only: :create, if: ->{ params[:subscription_line_item] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about moving the injected code to a module and including that module in the host application? That would make it less brittle to installations that have already been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waiting-for-dev I'm not sure I understand, looks like it's already in a module being injected in the host application, what am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful idea, working on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elia I'm working on a concern (that will be copied along to the host app), so that its inclusion is the only thing we inject in the controller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a new version that uses a Rails concern, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
I hope we'll be able to also add testing soon, but for now this is great!
pending the nits pointed out in other reviews
@@ -6,6 +6,7 @@ class InstallGenerator < Rails::Generators::Base | |||
source_root File.expand_path('templates', __dir__) | |||
|
|||
class_option :auto_run_migrations, type: :boolean, default: false | |||
class_option :frontend, type: :string, default: 'legacy' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a string instead of a boolean looks better to me, since more things could end up being frontends (api, graphql, etc) and being able to select the right integration seems like a better choice.
Anyways the name is classic
in the solidus installer, and I'm fine with both fixing it or moving it to a boolean, we can change later if necessary 👍
<<-RUBY.strip_heredoc.indent(2) | ||
|
||
include SolidusSubscriptions::SubscriptionLineItemBuilder | ||
after_action :handle_subscription_line_items, only: :create, if: ->{ params[:subscription_line_item] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waiting-for-dev I'm not sure I understand, looks like it's already in a module being injected in the host application, what am I missing?
0436be2
to
6a2ba92
Compare
...tors/solidus_subscriptions/install/templates/app/controllers/concerns/create_subscription.rb
Show resolved
Hide resolved
This works out of the box only for fresh install of the starter frontend because we can't anticipate what changed in each storefront, but should be a good starting point.
This way they will be loaded only when solidus_frontend is in use.
Auth devise is already installed with the new storefront, so we can remove a couple of options from solidus:install and the inclusion of the gem in the sandbox Gemfile. Also, we can remove enforce_available_locales, which is deprecated.
6a2ba92
to
a1a2c0c
Compare
Summary
This works out of the box only for a fresh installation of the starter frontend because we can't anticipate what changed in each storefront, but should be a good starting point.
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed (
cross them outif they are not):