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
|
# File 'app/helpers/trek/page_path_helper.rb', line 3
def page_path(object, **options)
raise "object is nil" if object.nil?
raise "Page is not defined" unless defined?(Page)
suffix = options.delete(:suffix) || "path"
locale = options.delete(:locale)
locale ||= I18n.locale
object = object.page if object.is_a?(Trek::Pageable)
raise "#{object} is not a page" unless object.is_a?(Page)
if object.pageable.present?
klass = object.pageable.class.name.underscore
id = object.slug.presence || object.to_param
id ? send(:"#{klass}_#{suffix}", id:, **options) : nil
else
begin
key = object.key.presence
if key == "root"
if locale == I18n.default_locale
send(:"root_#{suffix}", **options)
else
send(:"localized_root_#{suffix}", locale:, **options)
end
else
send(:"#{key}_path", **options)
end
rescue NoMethodError
I18n.with_locale(locale) do
if locale == I18n.default_locale
send(:"content_page_#{suffix}", path: object.full_path, **options)
else
send(:"localized_content_page_#{suffix}", path: object.full_path, locale:, **options)
end
end
end
end
end
|