-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathentries.rb
More file actions
63 lines (51 loc) · 1.13 KB
/
entries.rb
File metadata and controls
63 lines (51 loc) · 1.13 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
module Docs
class EntriesFilter < Filter
def call
result[:entries] = entries
doc
end
def entries
entries = []
entries << default_entry if root_page? || include_default_entry?
entries.concat(additional_entries)
build_entries(entries)
end
def include_default_entry?
true
end
def default_entry
[name]
end
def additional_entries
[]
end
def name
return @name if defined? @name
@name = root_page? ? nil : get_name
end
def get_name
slug.to_s.gsub('_', ' ').gsub('/', '.').squish!
end
def type
return @type if defined? @type
@type = root_page? ? nil : get_type
end
def get_type
nil
end
def path
result[:path]
end
def build_entries(entries)
entries.map do |attributes|
build_entry(*attributes)
end
end
def build_entry(name, frag = nil, type = nil)
type ||= self.type
path = frag ? (frag.include?('#') ? frag : "#{self.path}##{frag}") : self.path
Entry.new(name, path, type)
end
end
end