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
|
# File 'lib/nexmo/oas/renderer/helpers/navigation.rb', line 18
def navigation_from_content(content:, title: nil)
content = "<h0 class='injected'>#{title}</h0>\n" + content if title
document = build_document(content)
nodes = ['<ul class="Vlt-sidemenu Vlt-sidemenu--rounded Vlt-sidemenu--flat navigation js-navigation">']
last_node = nil
document.css('.reveal').remove
document.css('h0,h2,h3,h4,h5,h6').each do |heading|
next unless heading.ancestors('.Vlt-tabs').empty?
next unless heading.ancestors('.Vlt-callout').empty?
if last_node.nil? || heading.name == last_node.name
elsif heading.name >= last_node.name nodes << '<ul>'
else (HEADING_TAG_DEPTHS[last_node.name] - HEADING_TAG_DEPTHS[heading.name]).times do
nodes << '</li></ul>'
end
end
nodes << <<~HEREDOC
<li>
<a class="Vlt-sidemenu__link Vlt-grey-darker" href="##{heading.attributes['id']}" data-scrollspy-id="#{heading['data-id']}">
#{heading.text}
</a>
HEREDOC
last_node = heading
end
nodes << '</li></ul>'
nodes.join("\n").html_safe
end
|