Skip to content

Commit ce6ed77

Browse files
committed
feat: 麵包屑改用新的 gem
1 parent 17cf827 commit ce6ed77

File tree

8 files changed

+46
-23
lines changed

8 files changed

+46
-23
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ gem 'omniauth-oauth2'
131131
gem 'jquery-ui-rails'
132132

133133
# SEO
134-
gem 'crummy'
134+
gem 'breadcrumbs_on_rails'
135135
gem 'meta-tags', require: 'meta_tags'
136136
gem 'sitemap_generator'
137137

Gemfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ GEM
8181
aws-sigv4 (1.0.2)
8282
bcrypt (3.1.11)
8383
bindex (0.5.0)
84+
breadcrumbs_on_rails (3.0.1)
8485
builder (3.2.3)
8586
byebug (9.1.0)
8687
capistrano (3.9.1)
@@ -117,7 +118,6 @@ GEM
117118
connection_pool (2.2.1)
118119
crack (0.4.3)
119120
safe_yaml (~> 1.0.0)
120-
crummy (1.8.0)
121121
dalli (2.7.6)
122122
database_cleaner (1.6.1)
123123
devise (4.3.0)
@@ -470,6 +470,7 @@ DEPENDENCIES
470470
annotate
471471
asset_sync
472472
aws-sdk-rails
473+
breadcrumbs_on_rails
473474
byebug
474475
capistrano-rails
475476
capistrano-rbenv
@@ -479,7 +480,6 @@ DEPENDENCIES
479480
carrierwave_backgrounder!
480481
coffee-rails (~> 4.2)
481482
connection_pool
482-
crummy
483483
dalli
484484
database_cleaner
485485
devise
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ref: https://github.com/weppos/breadcrumbs_on_rails/blob/master/lib/breadcrumbs_on_rails/breadcrumbs.rb#L72
2+
class AdminBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
3+
def render
4+
@context.content_tag(:ol, class: 'breadcrumb') do
5+
@elements.collect do |element|
6+
render_element(element)
7+
end.join('').html_safe
8+
end
9+
end
10+
11+
private
12+
13+
def render_element(element)
14+
last = element == @elements.last
15+
@context.content_tag(:li, class: "breadcrumb-item #{'active' if last}") do
16+
if element.path == nil || last
17+
compute_name(element)
18+
else
19+
@context.link_to_unless_current(compute_name(element), compute_path(element), element.options)
20+
end
21+
end
22+
end
23+
end
File renamed without changes.

app/controllers/admin/base_controller.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ class Admin::BaseController < ApplicationController
66
before_action :authenticate_admin_user!
77
before_action :set_meta
88

9-
before_action do
10-
add_crumb 'Admin', admin_root_path
11-
end
9+
add_breadcrumb 'Admin', :admin_root_path
1210

1311
def index
1412
@admin_page_title = 'Admin'

app/controllers/admin/categories_controller.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
class Admin::CategoriesController < Admin::BaseController
22
before_action :category
3-
before_action { add_crumb('Categories', admin_categories_path) }
3+
add_breadcrumb('Categories', :admin_categories_path)
4+
before_action do
5+
add_breadcrumb(@category.name, admin_category_path(@category)) if @category.try(:id)
6+
end
47

58
def index
69
@admin_page_title = 'Categories'
@@ -11,23 +14,21 @@ def index
1114

1215
def show
1316
@admin_page_title = "##{@category.id} #{@category.name}"
14-
add_crumb @admin_page_title, '#'
1517
end
1618

1719
def new
18-
@admin_page_title = 'New Category'
19-
add_crumb @admin_page_title, '#'
20+
@admin_page_title = 'New'
21+
add_breadcrumb @admin_page_title
2022
end
2123

2224
def edit
23-
@admin_page_title = 'Edit Category'
24-
add_crumb @admin_page_title, '#'
25+
@admin_page_title = 'Edit'
26+
add_breadcrumb @admin_page_title
2527
end
2628

2729
def revisions
2830
@admin_page_title = "##{@category.id} #{@category.name} - revisions"
29-
add_crumb @category.name, admin_category_path(@category)
30-
add_crumb 'revisions', '#'
31+
add_breadcrumb 'Revisions'
3132
@versions = @category.versions
3233
end
3334

app/controllers/admin/users_controller.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
class Admin::UsersController < Admin::BaseController
22
before_action :user
3-
before_action(except: [:index]) { add_crumb('Users', admin_users_path) }
3+
add_breadcrumb('Users', :admin_users_path)
4+
before_action do
5+
add_breadcrumb(@user.name, admin_user_path(@user)) if @user.try(:id)
6+
end
47

58
def index
69
@admin_page_title = 'Users'
7-
add_crumb @admin_page_title, '#'
810
@q = Admin::User.ransack(params[:q])
9-
@users = @q.result.order('id DESC').page(params[:page]).per(1)
11+
@users = @q.result.order('id DESC').page(params[:page]).per(30)
1012
respond_with @users
1113
end
1214

1315
def show
1416
@admin_page_title = "##{@user.id}"
15-
add_crumb @admin_page_title, '#'
1617
end
1718

1819
def new
19-
@admin_page_title = 'New User'
20-
add_crumb @admin_page_title, '#'
20+
@admin_page_title = 'New'
21+
add_breadcrumb @admin_page_title
2122
end
2223

2324
def edit
24-
@admin_page_title = 'Edit User'
25-
add_crumb @admin_page_title, '#'
25+
@admin_page_title = 'Edit'
26+
add_breadcrumb @admin_page_title
2627
end
2728

2829
def create

app/views/layouts/admin.html.slim

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ html
2626
.title_right
2727
= yield :btns
2828
.clearfix
29-
= render_crumbs separator: ' > '
29+
= render_breadcrumbs builder: AdminBreadcrumbsBuilder
3030
.clearfix
3131
br/
3232
= render partial: 'admin/base/flash'

0 commit comments

Comments
 (0)