-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: master
Are you sure you want to change the base?
Changes from all commits
a491c87
288cb8c
bbea64a
47d50b7
989462d
2299ded
f94f272
9fa3f45
b8478a0
aa45ffa
64aa93d
e28ea0f
72b1590
b94519a
c074e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ tmp | |
*.o | ||
*.a | ||
mkmf.log | ||
.byebug_history |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.7.3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,11 @@ def breadcrumb_trail(options = {}) | |
_breadcrumbs.each do |crumb| | ||
name = title_for(crumb.name) | ||
path = url_for(_expand_url(crumb.url)) | ||
current = current_crumb?(path, options.fetch(:match) { crumb.match }) | ||
current = current_crumb?( | ||
path, | ||
options.fetch(:match) { crumb.match }, | ||
request_methods: options.fetch(:request_methods) { crumb.request_methods } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [84/80] |
||
) | ||
|
||
yield(Loaf::Breadcrumb[name, path, current]) | ||
end | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [103/80] |
||
return false unless match_request_methods(request_methods) | ||
|
||
origin_path = URI::DEFAULT_PARSER.unescape(path).force_encoding(Encoding::BINARY) | ||
|
||
|
@@ -128,5 +132,16 @@ def _expand_url(url) | |
url | ||
end | ||
end | ||
|
||
# Check if the HTTP request methods are allowed | ||
# | ||
# @retun [Boolean] | ||
# | ||
# @api private | ||
def match_request_methods(request_methods) | ||
return true if request_methods == :all | ||
|
||
request_methods.any? { |method| request.try("#{method}?") } | ||
end | ||
end # ViewExtensions | ||
end # Loaf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# encoding: utf-8 | ||
|
||
RSpec.describe 'setting configuration options' do | ||
RSpec.describe "setting configuration options" do | ||
it "contains 'selected' inside the breadcrumb markup" do | ||
visit posts_path | ||
page.within '#breadcrumbs' do | ||
expect(page).to have_selector('.selected') | ||
within "#breadcrumbs" do | ||
expect(page).to have_selector(".selected") | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/Lambda: Use the -> { ... } lambda literal syntax for single line lambdas. |
||
match: :exact | ||
|
||
breadcrumb -> { find_article(params[:post_id]).title + " No Controller" }, | ||
-> { post_comments_path(params[:post_id], no_controller: true) } | ||
-> { post_comments_path(params[:post_id], no_controller: true) }, | ||
match: :exact | ||
|
||
def index | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
hoppergee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class OnboardController < ApplicationController | ||
breadcrumb "Onboard", :onboard_path, match: :exact | ||
|
||
def setup | ||
case params[:step] | ||
when "1" | ||
breadcrumb "Step 1", onboard_step_path(step: 1), | ||
match: :exact, request_methods: %i[get] | ||
render :step1 | ||
when "2" | ||
breadcrumb "Step 2", onboard_step_path(step: 2), | ||
match: :exact, request_methods: %i[get post] | ||
render :step2 | ||
when "3" | ||
breadcrumb "Step 3", onboard_step_path(step: 3), | ||
match: :exact, request_methods: %i[get put] | ||
render :step3 | ||
when "4" | ||
breadcrumb "Step 4", onboard_step_path(step: 4), | ||
match: :exact, request_methods: %i[get patch] | ||
render :step4 | ||
when "5" | ||
breadcrumb "Step 5", onboard_step_path(step: 5), | ||
match: :exact, request_methods: %i[get delete] | ||
render :step5 | ||
when "6" | ||
breadcrumb "Step 6", onboard_step_path(step: 6), | ||
match: :exact, request_methods: :all | ||
render :step6 | ||
else | ||
render :setup | ||
end | ||
end | ||
end | ||
piotrmurach marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>Onboard</h1> | ||
|
||
<%= link_to "Step 1", onboard_step_path(step: 1) %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Step 1</h1> | ||
<%= button_to "Save & Next", onboard_step_path(step: 2), method: :post %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Step 2</h1> | ||
<%= button_to "Save & Next", onboard_step_path(step: 3), method: :put %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Step 3</h1> | ||
<% if Rails.version >= "4.0.0" %> | ||
<%= button_to "Save & Next", onboard_step_path(step: 4), method: :patch %> | ||
<% else %> | ||
<%= button_to "Save & Next", onboard_step_path(step: 5), method: :delete %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Step 4</h1> | ||
<%= button_to "Save & Next", onboard_step_path(step: 5), method: :delete %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Step 5</h1> | ||
<%= button_to "Save & Next", onboard_step_path(step: 6), method: :get %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Step 6</h1> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
RailsApp::Application.routes.draw do | ||
root :to => 'home#index' | ||
root to: "home#index" | ||
|
||
resources :posts do | ||
resources :comments | ||
end | ||
|
||
get "/onboard", to: "onboard#setup", as: :onboard | ||
get "/onboard/step/:step", to: "onboard#setup", as: :onboard_step | ||
post "/onboard/step/:step", to: "onboard#setup" | ||
if Rails.version >= "4.0.0" | ||
patch "/onboard/step/:step", to: "onboard#setup" | ||
end | ||
put "/onboard/step/:step", to: "onboard#setup" | ||
delete "/onboard/step/:step", to: "onboard#setup" | ||
end |
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.
Metrics/LineLength: Line is too long. [92/80]