3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/helpers/rails_pulse/breadcrumbs_helper.rb', line 3
def breadcrumbs
mount_point = RailsPulse::Engine.routes.find_script_name({}).sub(/^\//, "")
path_segments = request.path.split("/").reject(&:empty?)
mount_point_index = path_segments.index(mount_point)
return [] if mount_point_index.nil? || mount_point_index == path_segments.length - 1
path_segments = path_segments[(mount_point_index + 1)..-1]
crumbs = [ {
title: "Home",
path: main_app.rails_pulse_path,
current: path_segments.empty?
} ]
return crumbs if path_segments.empty?
current_path = main_app.rails_pulse_path.chomp("/")
path_segments.each_with_index do |segment, index|
current_path += "/#{segment}"
title = if segment =~ /^\d+$/
resource_name = path_segments[index - 1]&.singularize
resource_class = "RailsPulse::#{resource_name&.classify}".safe_constantize
if resource_class
resource = resource_class.find(segment)
resource.try(:to_breadcrumb) || resource.to_s
else
segment
end
else
segment.titleize
end
is_last = index == path_segments.length - 1
crumbs << {
title: title,
path: current_path,
current: is_last
}
end
crumbs
end
|