forked from pivotal-cf/bookbinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive_drop_down_menu.rb
50 lines (39 loc) · 948 Bytes
/
archive_drop_down_menu.rb
1
2
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
module Bookbinder
class ArchiveDropDownMenu
def initialize(config, current_path: nil)
@config = config_with_default(config)
@current_path = current_path
end
def title
directory_config.first
end
def dropdown_links
versions_to_paths.map { |version_path|
{version_path.keys.first => "/#{version_path.values.first}"}
}
end
def empty?
title.nil? && dropdown_links.empty?
end
private
attr_reader :config, :current_path
def versions_to_paths
directory_config[1..-1]
end
def directory_config
config.fetch(directory, config.fetch(root_menu_reference)) || empty_menu
end
def directory
File.dirname(current_path)
end
def config_with_default(config)
{ root_menu_reference => empty_menu }.merge(config || {})
end
def empty_menu
[nil]
end
def root_menu_reference
'.'
end
end
end