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 :http_verbs option #50

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

hoppergee
Copy link

Describe the change

Add :http_verbs option to breadcrumb parameters

Why are we doing this?

When I use this gem on some legacy projects, I met a circumstance which I have to show breadcrumbs on POST/PATCH action. I tried to add an option :http_only at #49. But @piotrmurach suggest me to use http_verbs.

Benefits

Now the current breadcrumb can match with multiple HTTP methods

breadcrumb 'Step 1', onboard_step_path(step: 1), http_verbs: [:get]
breadcrumb 'Step 2', onboard_step_path(step: 2), http_verbs: [:get, :post, :delete]
breadcrumb 'Step 3', onboard_step_path(step: 3), http_verbs: :all

Example:
  http_verbs: %w[get head]
  http_verbs: %w[post get head put patch delete]
  http_verbs: :all
Gemfile Outdated Show resolved Hide resolved
lib/loaf/configuration.rb Outdated Show resolved Hide resolved
lib/loaf/view_extensions.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
@hoppergee hoppergee mentioned this pull request Jul 19, 2021
Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

This is looking very promising! Thanks for a quick turnaround on this issue. 🙏 I left few comments. Could you please also use double-quoted strings everywhere? Sorry for the confusion, there is a mixture of both styles but going forward I'd like to keep them double-quoted.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lib/loaf/configuration.rb Outdated Show resolved Hide resolved
lib/loaf/view_extensions.rb Outdated Show resolved Hide resolved
Gemfile Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lib/loaf/configuration.rb Outdated Show resolved Hide resolved
lib/loaf/configuration.rb Outdated Show resolved Hide resolved
lib/loaf/view_extensions.rb Outdated Show resolved Hide resolved
lib/loaf/view_extensions.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Show resolved Hide resolved
spec/rails_app/app/controllers/onboard_controller.rb Outdated Show resolved Hide resolved
spec/rails_app/app/controllers/onboard_controller.rb Outdated Show resolved Hide resolved
spec/rails_app/config/routes.rb Outdated Show resolved Hide resolved
spec/rails_app/config/routes.rb Outdated Show resolved Hide resolved
Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

Things are looking good! Would you please address the remaining 'houndci' style issues? There are still some single-quoted strings left, arrays that can be converted to symbol arrays etc. Also, there are some tests failures in Rails 3.2. I know it's old Rails - sorry! But I don't want to break things in this release. I will consider dropping support later on in a separate release. Thank you!

lib/loaf/configuration.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Show resolved Hide resolved
spec/rails_app/config/routes.rb Outdated Show resolved Hide resolved
spec/support/capybara.rb Outdated Show resolved Hide resolved
spec/support/dummy_view.rb Outdated Show resolved Hide resolved
spec/support/dummy_view.rb Outdated Show resolved Hide resolved
spec/support/dummy_view.rb Outdated Show resolved Hide resolved
spec/support/dummy_view.rb Outdated Show resolved Hide resolved
spec/unit/view_extensions/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/unit/view_extensions/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

Thank you Hopper for making these changes! Things are looking really good. There is a small style issue left.

There is one dilemma that I'm 'debating' which is the name of the parameter :http_verbs. The verbs term is kind of inaccurate because these are not all verbs and also it is rather 'colloquial' usage. The HTTP rfc talks about HTTP methods. It feels more appropriate to use methods. I'm equally debating whether it should be request_methods or http_methods? What're your thoughts on this? I want to make sure we pick the best configuration name.

lib/loaf/view_extensions.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
@hoppergee
Copy link
Author

Thank you Hopper for making these changes! Things are looking really good. There is a small style issue left.

There is one dilemma that I'm 'debating' which is the name of the parameter :http_verbs. The verbs term is kind of inaccurate because these are not all verbs and also it is rather 'colloquial' usage. The HTTP rfc talks about HTTP methods. It feels more appropriate to use methods. I'm equally debating whether it should be request_methods or http_methods? What're your thoughts on this? I want to make sure we pick the best configuration name.

Maybe the request_methods is better, as Rack is using request_method.

https://github.com/rack/rack/blob/d15dd728440710cfc35ed155d66a98dc2c07ae42/lib/rack/request.rb#L174-L202

def initialize(name, url, options = {})
@name = name || raise_name_error
@url = url || raise_url_error
@match = options.fetch(:match, Loaf.configuration.match)
@request_methods = options.fetch(:request_methods, Loaf.configuration.request_methods)

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [92/80]

current = current_crumb?(
path,
options.fetch(:match) { crumb.match },
request_methods: options.fetch(:request_methods) { crumb.request_methods }

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [84/80]

Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

Apologies for not having replied to your request for review earlier. I took a break from open-source. I left a few comments. Let's move this PR forward.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lib/loaf/view_extensions.rb Outdated Show resolved Hide resolved
lib/loaf/view_extensions.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/unit/view_extensions/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/unit/view_extensions/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/unit/view_extensions/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
@piotrmurach piotrmurach linked an issue Feb 21, 2022 that may be closed by this pull request
@hoppergee
Copy link
Author

Apologies for not having replied to your request for review earlier. I took a break from open-source. I left a few comments. Let's move this PR forward.

Glad to hear that! I'll get it done sometime this week.

@@ -65,8 +69,8 @@ def breadcrumb_trail(options = {})
# the pattern to match on
#
# @api public
def current_crumb?(path, pattern = :inclusive)
return false unless request.get? || request.head?
def current_crumb?(path, pattern = :inclusive, request_methods: Loaf.configuration.request_methods)

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [103/80]

spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/breadcrumb_trail_spec.rb Outdated Show resolved Hide resolved
spec/integration/configuration_spec.rb Outdated Show resolved Hide resolved
@hoppergee hoppergee force-pushed the http_verbs_option branch 2 times, most recently from ba3602e to c5d8971 Compare February 25, 2022 10:33
@hoppergee
Copy link
Author

hoppergee commented Feb 25, 2022

I just fixed all those style issues. Also fixed a wrong proc config test issue

@@ -3,10 +3,12 @@ class Article < Struct.new(:id, :title); end
class CommentsController < ApplicationController

breadcrumb lambda { |c| c.find_article(c.params[:post_id]).title },
lambda { |c| c.post_comments_path(c.params[:post_id]) }
lambda { |c| c.post_comments_path(c.params[:post_id]) },

Choose a reason for hiding this comment

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

Style/Lambda: Use the -> { ... } lambda literal syntax for single line lambdas.

@ankalus
Copy link

ankalus commented May 4, 2023

Are there plans to merge these changes?

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.

Crumbs are never current on POST
4 participants