Almirah 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/almirah +4 -4
- data/lib/almirah/doc_fabric.rb +65 -65
- data/lib/almirah/doc_items/blockquote.rb +21 -21
- data/lib/almirah/doc_items/code_block.rb +26 -26
- data/lib/almirah/doc_items/controlled_paragraph.rb +112 -112
- data/lib/almirah/doc_items/controlled_table.rb +224 -224
- data/lib/almirah/doc_items/controlled_table_row.rb +22 -22
- data/lib/almirah/doc_items/doc_footer.rb +16 -16
- data/lib/almirah/doc_items/doc_item.rb +22 -20
- data/lib/almirah/doc_items/frontmatter.rb +9 -0
- data/lib/almirah/doc_items/heading.rb +93 -93
- data/lib/almirah/doc_items/image.rb +27 -27
- data/lib/almirah/doc_items/markdown_list.rb +156 -158
- data/lib/almirah/doc_items/markdown_table.rb +61 -63
- data/lib/almirah/doc_items/paragraph.rb +25 -27
- data/lib/almirah/doc_items/text_line.rb +296 -296
- data/lib/almirah/doc_items/todo_block.rb +21 -21
- data/lib/almirah/doc_parser.rb +378 -330
- data/lib/almirah/doc_types/base_document.rb +64 -70
- data/lib/almirah/doc_types/coverage.rb +95 -81
- data/lib/almirah/doc_types/index.rb +173 -169
- data/lib/almirah/doc_types/persistent_document.rb +17 -20
- data/lib/almirah/doc_types/protocol.rb +24 -24
- data/lib/almirah/doc_types/specification.rb +67 -67
- data/lib/almirah/doc_types/traceability.rb +142 -142
- data/lib/almirah/dom/doc_section.rb +25 -25
- data/lib/almirah/dom/document.rb +78 -72
- data/lib/almirah/navigation_pane.rb +16 -16
- data/lib/almirah/project.rb +287 -306
- data/lib/almirah/project_configuration.rb +41 -41
- data/lib/almirah/project_template.rb +298 -0
- data/lib/almirah/project_utility.rb +52 -0
- data/lib/almirah/search/specifications_db.rb +79 -83
- data/lib/almirah/templates/css/main.css +300 -300
- data/lib/almirah/templates/css/search.css +40 -40
- data/lib/almirah/templates/page.html +42 -42
- data/lib/almirah/templates/scripts/main.js +111 -111
- data/lib/almirah/templates/scripts/orama_search.js +138 -138
- data/lib/almirah.rb +93 -49
- metadata +28 -5
@@ -1,142 +1,142 @@
|
|
1
|
-
require_relative "base_document"
|
2
|
-
|
3
|
-
class Traceability < BaseDocument
|
4
|
-
|
5
|
-
attr_accessor :top_doc
|
6
|
-
attr_accessor :bottom_doc
|
7
|
-
attr_accessor :items
|
8
|
-
attr_accessor :is_agregated
|
9
|
-
attr_accessor :traced_items
|
10
|
-
|
11
|
-
def initialize(top_doc, bottom_doc)
|
12
|
-
super()
|
13
|
-
@top_doc = top_doc
|
14
|
-
@bottom_doc = bottom_doc
|
15
|
-
@is_agregated = if bottom_doc
|
16
|
-
false
|
17
|
-
else
|
18
|
-
true
|
19
|
-
end
|
20
|
-
@traced_items = {}
|
21
|
-
|
22
|
-
if @is_agregated
|
23
|
-
@id = top_doc.id + "-all"
|
24
|
-
else
|
25
|
-
@id = top_doc.id + "-" + bottom_doc.id
|
26
|
-
end
|
27
|
-
|
28
|
-
@title = "Traceability Matrix: " + @id
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_console
|
32
|
-
puts "\e[35m" + "Traceability: " + @id + "\e[0m"
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_html(nav_pane, output_file_path)
|
36
|
-
|
37
|
-
html_rows = Array.new
|
38
|
-
|
39
|
-
html_rows.append('')
|
40
|
-
s = "<h1>#{@title}</h1>\n"
|
41
|
-
s += "<table class=\"controlled\">\n"
|
42
|
-
s += "\t<thead> <th>#</th> <th style='font-weight: bold;'>#{@top_doc.title}</th> "
|
43
|
-
if @bottom_doc
|
44
|
-
s += "<th>#</th> <th style='font-weight: bold;'>#{@bottom_doc.title}</th> "
|
45
|
-
else
|
46
|
-
s += "<th>#</th> <th style='font-weight: bold;'>All References</th> "
|
47
|
-
end
|
48
|
-
s += "<th style='font-weight: bold;'>Document Section</th>"
|
49
|
-
s += "</thead>\n"
|
50
|
-
html_rows.append s
|
51
|
-
|
52
|
-
sorted_items = @top_doc.controlled_items.sort_by { |w| w.id }
|
53
|
-
|
54
|
-
sorted_items.each do |top_item|
|
55
|
-
row = render_table_row top_item
|
56
|
-
html_rows.append row
|
57
|
-
end
|
58
|
-
html_rows.append "</table>\n"
|
59
|
-
|
60
|
-
self.save_html_to_file(html_rows, nav_pane, output_file_path)
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def render_table_row(top_item)
|
65
|
-
s = ""
|
66
|
-
top_f_text = top_item.format_string( top_item.text )
|
67
|
-
id_color = ""
|
68
|
-
|
69
|
-
if top_item.down_links
|
70
|
-
|
71
|
-
if @is_agregated
|
72
|
-
|
73
|
-
top_item_rendered = false
|
74
|
-
|
75
|
-
top_item.down_links.each do |bottom_item|
|
76
|
-
id_color = "style='background-color: ##{bottom_item.parent_doc.color};'"
|
77
|
-
bottom_f_text = bottom_item.format_string( bottom_item.text )
|
78
|
-
document_section = bottom_item.parent_heading.get_section_info
|
79
|
-
s += "\t<tr>\n"
|
80
|
-
s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
81
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
82
|
-
s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{bottom_item.parent_doc.id}/#{bottom_item.parent_doc.id}.html##{bottom_item.id}\" class=\"external\">#{bottom_item.id}</a></td>\n"
|
83
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{bottom_f_text}</td>\n"
|
84
|
-
s += "\t\t<td class=\"item_text\" style='width: 16%;'>#{document_section}</td>\n"
|
85
|
-
s += "\t</tr>\n"
|
86
|
-
top_item_rendered = true
|
87
|
-
@traced_items[top_item.id.to_s.downcase] = top_item
|
88
|
-
end
|
89
|
-
unless top_item_rendered
|
90
|
-
s += "\t<tr>\n"
|
91
|
-
s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
92
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
93
|
-
s += "\t\t<td class=\"item_id\"></td>\n"
|
94
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
|
95
|
-
s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
|
96
|
-
s += "\t</tr>\n"
|
97
|
-
end
|
98
|
-
|
99
|
-
else
|
100
|
-
top_item_rendered = false
|
101
|
-
top_item.down_links.each do |bottom_item|
|
102
|
-
|
103
|
-
id_color = ""
|
104
|
-
|
105
|
-
if bottom_item.parent_doc.id == @bottom_doc.id
|
106
|
-
|
107
|
-
bottom_f_text = bottom_item.format_string( bottom_item.text )
|
108
|
-
document_section = bottom_item.parent_heading.get_section_info
|
109
|
-
|
110
|
-
s += "\t<tr>\n"
|
111
|
-
s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
112
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
113
|
-
s += "\t\t<td class=\"item_id\"><a href=\"./../#{bottom_item.parent_doc.id}/#{bottom_item.parent_doc.id}.html##{bottom_item.id}\" class=\"external\">#{bottom_item.id}</a></td>\n"
|
114
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{bottom_f_text}</td>\n"
|
115
|
-
s += "\t\t<td class=\"item_text\" style='width: 16%;'>#{document_section}</td>\n"
|
116
|
-
s += "\t</tr>\n"
|
117
|
-
top_item_rendered = true
|
118
|
-
@traced_items[top_item.id.to_s.downcase] = top_item
|
119
|
-
end
|
120
|
-
end
|
121
|
-
unless top_item_rendered
|
122
|
-
s += "\t<tr>\n"
|
123
|
-
s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
124
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
125
|
-
s += "\t\t<td class=\"item_id\"></td>\n"
|
126
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
|
127
|
-
s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
|
128
|
-
s += "\t</tr>\n"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
else
|
132
|
-
s += "\t<tr>\n"
|
133
|
-
s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
134
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
135
|
-
s += "\t\t<td class=\"item_id\"></td>\n"
|
136
|
-
s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
|
137
|
-
s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
|
138
|
-
s += "\t</tr>\n"
|
139
|
-
end
|
140
|
-
return s
|
141
|
-
end
|
142
|
-
end
|
1
|
+
require_relative "base_document"
|
2
|
+
|
3
|
+
class Traceability < BaseDocument
|
4
|
+
|
5
|
+
attr_accessor :top_doc
|
6
|
+
attr_accessor :bottom_doc
|
7
|
+
attr_accessor :items
|
8
|
+
attr_accessor :is_agregated
|
9
|
+
attr_accessor :traced_items
|
10
|
+
|
11
|
+
def initialize(top_doc, bottom_doc)
|
12
|
+
super()
|
13
|
+
@top_doc = top_doc
|
14
|
+
@bottom_doc = bottom_doc
|
15
|
+
@is_agregated = if bottom_doc
|
16
|
+
false
|
17
|
+
else
|
18
|
+
true
|
19
|
+
end
|
20
|
+
@traced_items = {}
|
21
|
+
|
22
|
+
if @is_agregated
|
23
|
+
@id = top_doc.id + "-all"
|
24
|
+
else
|
25
|
+
@id = top_doc.id + "-" + bottom_doc.id
|
26
|
+
end
|
27
|
+
|
28
|
+
@title = "Traceability Matrix: " + @id
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_console
|
32
|
+
puts "\e[35m" + "Traceability: " + @id + "\e[0m"
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_html(nav_pane, output_file_path)
|
36
|
+
|
37
|
+
html_rows = Array.new
|
38
|
+
|
39
|
+
html_rows.append('')
|
40
|
+
s = "<h1>#{@title}</h1>\n"
|
41
|
+
s += "<table class=\"controlled\">\n"
|
42
|
+
s += "\t<thead> <th>#</th> <th style='font-weight: bold;'>#{@top_doc.title}</th> "
|
43
|
+
if @bottom_doc
|
44
|
+
s += "<th>#</th> <th style='font-weight: bold;'>#{@bottom_doc.title}</th> "
|
45
|
+
else
|
46
|
+
s += "<th>#</th> <th style='font-weight: bold;'>All References</th> "
|
47
|
+
end
|
48
|
+
s += "<th style='font-weight: bold;'>Document Section</th>"
|
49
|
+
s += "</thead>\n"
|
50
|
+
html_rows.append s
|
51
|
+
|
52
|
+
sorted_items = @top_doc.controlled_items.sort_by { |w| w.id }
|
53
|
+
|
54
|
+
sorted_items.each do |top_item|
|
55
|
+
row = render_table_row top_item
|
56
|
+
html_rows.append row
|
57
|
+
end
|
58
|
+
html_rows.append "</table>\n"
|
59
|
+
|
60
|
+
self.save_html_to_file(html_rows, nav_pane, output_file_path)
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def render_table_row(top_item)
|
65
|
+
s = ""
|
66
|
+
top_f_text = top_item.format_string( top_item.text )
|
67
|
+
id_color = ""
|
68
|
+
|
69
|
+
if top_item.down_links
|
70
|
+
|
71
|
+
if @is_agregated
|
72
|
+
|
73
|
+
top_item_rendered = false
|
74
|
+
|
75
|
+
top_item.down_links.each do |bottom_item|
|
76
|
+
id_color = "style='background-color: ##{bottom_item.parent_doc.color};'"
|
77
|
+
bottom_f_text = bottom_item.format_string( bottom_item.text )
|
78
|
+
document_section = bottom_item.parent_heading.get_section_info
|
79
|
+
s += "\t<tr>\n"
|
80
|
+
s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
81
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
82
|
+
s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{bottom_item.parent_doc.id}/#{bottom_item.parent_doc.id}.html##{bottom_item.id}\" class=\"external\">#{bottom_item.id}</a></td>\n"
|
83
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{bottom_f_text}</td>\n"
|
84
|
+
s += "\t\t<td class=\"item_text\" style='width: 16%;'>#{document_section}</td>\n"
|
85
|
+
s += "\t</tr>\n"
|
86
|
+
top_item_rendered = true
|
87
|
+
@traced_items[top_item.id.to_s.downcase] = top_item
|
88
|
+
end
|
89
|
+
unless top_item_rendered
|
90
|
+
s += "\t<tr>\n"
|
91
|
+
s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
92
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
93
|
+
s += "\t\t<td class=\"item_id\"></td>\n"
|
94
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
|
95
|
+
s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
|
96
|
+
s += "\t</tr>\n"
|
97
|
+
end
|
98
|
+
|
99
|
+
else
|
100
|
+
top_item_rendered = false
|
101
|
+
top_item.down_links.each do |bottom_item|
|
102
|
+
|
103
|
+
id_color = ""
|
104
|
+
|
105
|
+
if bottom_item.parent_doc.id == @bottom_doc.id
|
106
|
+
|
107
|
+
bottom_f_text = bottom_item.format_string( bottom_item.text )
|
108
|
+
document_section = bottom_item.parent_heading.get_section_info
|
109
|
+
|
110
|
+
s += "\t<tr>\n"
|
111
|
+
s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
112
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
113
|
+
s += "\t\t<td class=\"item_id\"><a href=\"./../#{bottom_item.parent_doc.id}/#{bottom_item.parent_doc.id}.html##{bottom_item.id}\" class=\"external\">#{bottom_item.id}</a></td>\n"
|
114
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{bottom_f_text}</td>\n"
|
115
|
+
s += "\t\t<td class=\"item_text\" style='width: 16%;'>#{document_section}</td>\n"
|
116
|
+
s += "\t</tr>\n"
|
117
|
+
top_item_rendered = true
|
118
|
+
@traced_items[top_item.id.to_s.downcase] = top_item
|
119
|
+
end
|
120
|
+
end
|
121
|
+
unless top_item_rendered
|
122
|
+
s += "\t<tr>\n"
|
123
|
+
s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
124
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
125
|
+
s += "\t\t<td class=\"item_id\"></td>\n"
|
126
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
|
127
|
+
s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
|
128
|
+
s += "\t</tr>\n"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
else
|
132
|
+
s += "\t<tr>\n"
|
133
|
+
s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
|
134
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
|
135
|
+
s += "\t\t<td class=\"item_id\"></td>\n"
|
136
|
+
s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
|
137
|
+
s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
|
138
|
+
s += "\t</tr>\n"
|
139
|
+
end
|
140
|
+
return s
|
141
|
+
end
|
142
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
class DocSection
|
2
|
-
attr_accessor :sections, :heading, :parent_section
|
3
|
-
|
4
|
-
def initialize(heading)
|
5
|
-
@sections = []
|
6
|
-
@heading = heading
|
7
|
-
@parent_section = nil
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_html # rubocop:disable Metrics/MethodLength
|
11
|
-
s = ''
|
12
|
-
s += "\t<li onclick=\"nav_toggle_expand_list(this, event)\">" \
|
13
|
-
'<span class="fa-li"><i class="fa fa-minus-square-o"> </i></span>'
|
14
|
-
s += "<a href=\"##{@heading.anchor_id}\">#{@heading.get_section_info}</a>\n"
|
15
|
-
unless @sections.empty?
|
16
|
-
s += "\t\t<ul class=\"fa-ul\">\n"
|
17
|
-
@sections.each do |sub_section|
|
18
|
-
s += sub_section.to_html
|
19
|
-
end
|
20
|
-
s += "\t\t</ul>\n"
|
21
|
-
end
|
22
|
-
s += "</li>\n"
|
23
|
-
s
|
24
|
-
end
|
25
|
-
end
|
1
|
+
class DocSection
|
2
|
+
attr_accessor :sections, :heading, :parent_section
|
3
|
+
|
4
|
+
def initialize(heading)
|
5
|
+
@sections = []
|
6
|
+
@heading = heading
|
7
|
+
@parent_section = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_html # rubocop:disable Metrics/MethodLength
|
11
|
+
s = ''
|
12
|
+
s += "\t<li onclick=\"nav_toggle_expand_list(this, event)\">" \
|
13
|
+
'<span class="fa-li"><i class="fa fa-minus-square-o"> </i></span>'
|
14
|
+
s += "<a href=\"##{@heading.anchor_id}\">#{@heading.get_section_info}</a>\n"
|
15
|
+
unless @sections.empty?
|
16
|
+
s += "\t\t<ul class=\"fa-ul\">\n"
|
17
|
+
@sections.each do |sub_section|
|
18
|
+
s += sub_section.to_html
|
19
|
+
end
|
20
|
+
s += "\t\t</ul>\n"
|
21
|
+
end
|
22
|
+
s += "</li>\n"
|
23
|
+
s
|
24
|
+
end
|
25
|
+
end
|
data/lib/almirah/dom/document.rb
CHANGED
@@ -1,72 +1,78 @@
|
|
1
|
-
require_relative 'doc_section'
|
2
|
-
|
3
|
-
class Document
|
4
|
-
attr_accessor :root_section
|
5
|
-
|
6
|
-
def initialize(headings_list)
|
7
|
-
@root_section = nil
|
8
|
-
|
9
|
-
build_sections_tree(headings_list)
|
10
|
-
end
|
11
|
-
|
12
|
-
def build_sections_tree(headings_list)
|
13
|
-
sections_stack = []
|
14
|
-
headings_list.each do |h|
|
15
|
-
if @root_section.nil?
|
16
|
-
|
17
|
-
s = DocSection.new(h)
|
18
|
-
s.parent_section = nil
|
19
|
-
@root_section = s
|
20
|
-
sections_stack.push s
|
21
|
-
# one more artificial section copy if root is not a Document Title (level 0)
|
22
|
-
if h.level.positive?
|
23
|
-
a = DocSection.new(h)
|
24
|
-
a.parent_section = @root_section
|
25
|
-
@root_section.sections.append(a)
|
26
|
-
sections_stack.push a
|
27
|
-
end
|
28
|
-
|
29
|
-
elsif sections_stack[-1].heading.level == h.level
|
30
|
-
|
31
|
-
s = DocSection.new(h)
|
32
|
-
s.parent_section = sections_stack[-1].parent_section
|
33
|
-
sections_stack[-1].parent_section.sections.append(s)
|
34
|
-
sections_stack[-1] = s
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
sections_stack[-1].
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
1
|
+
require_relative 'doc_section'
|
2
|
+
|
3
|
+
class Document
|
4
|
+
attr_accessor :root_section
|
5
|
+
|
6
|
+
def initialize(headings_list)
|
7
|
+
@root_section = nil
|
8
|
+
|
9
|
+
build_sections_tree(headings_list)
|
10
|
+
end
|
11
|
+
|
12
|
+
def build_sections_tree(headings_list)
|
13
|
+
sections_stack = []
|
14
|
+
headings_list.each do |h|
|
15
|
+
if @root_section.nil?
|
16
|
+
|
17
|
+
s = DocSection.new(h)
|
18
|
+
s.parent_section = nil
|
19
|
+
@root_section = s
|
20
|
+
sections_stack.push s
|
21
|
+
# one more artificial section copy if root is not a Document Title (level 0)
|
22
|
+
if h.level.positive?
|
23
|
+
a = DocSection.new(h)
|
24
|
+
a.parent_section = @root_section
|
25
|
+
@root_section.sections.append(a)
|
26
|
+
sections_stack.push a
|
27
|
+
end
|
28
|
+
|
29
|
+
elsif sections_stack[-1].heading.level == h.level
|
30
|
+
|
31
|
+
s = DocSection.new(h)
|
32
|
+
s.parent_section = sections_stack[-1].parent_section
|
33
|
+
sections_stack[-1].parent_section.sections.append(s)
|
34
|
+
sections_stack[-1] = s
|
35
|
+
# for search engine
|
36
|
+
s.heading.parent_heading = s.parent_section.heading
|
37
|
+
|
38
|
+
elsif h.level > sections_stack[-1].heading.level
|
39
|
+
|
40
|
+
s = DocSection.new(h)
|
41
|
+
s.parent_section = sections_stack[-1]
|
42
|
+
sections_stack[-1].sections.append(s)
|
43
|
+
sections_stack.push s
|
44
|
+
# for search engine
|
45
|
+
s.heading.parent_heading = s.parent_section.heading
|
46
|
+
|
47
|
+
else
|
48
|
+
sections_stack.pop while h.level < sections_stack[-1].heading.level
|
49
|
+
sections_stack.push @root_section if sections_stack.empty?
|
50
|
+
s = DocSection.new(h)
|
51
|
+
if h.level == sections_stack[-1].heading.level
|
52
|
+
s.parent_section = sections_stack[-1].parent_section
|
53
|
+
sections_stack[-1].parent_section.sections.append(s)
|
54
|
+
else
|
55
|
+
s.parent_section = sections_stack[-1]
|
56
|
+
sections_stack[-1].sections.append(s)
|
57
|
+
end
|
58
|
+
sections_stack[-1] = s
|
59
|
+
# for search engine
|
60
|
+
s.heading.parent_heading = s.parent_section.heading
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def section_tree_to_html
|
66
|
+
s = ''
|
67
|
+
s += "<a href=\"##{@root_section.heading.anchor_id}\">#{@root_section.heading.get_section_info}</a>\n"
|
68
|
+
unless @root_section.sections.empty?
|
69
|
+
s += "\t<ul class=\"fa-ul\" style=\"margin-top: 2px;\">\n"
|
70
|
+
@root_section.sections.each do |sub_section|
|
71
|
+
s += sub_section.to_html
|
72
|
+
end
|
73
|
+
s += "\t</ul>\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
s
|
77
|
+
end
|
78
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
|
2
|
-
class NavigationPane
|
3
|
-
|
4
|
-
attr_accessor :specifications
|
5
|
-
|
6
|
-
def initialize(specification)
|
7
|
-
@doc = specification
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_html
|
11
|
-
if @doc.dom
|
12
|
-
return @doc.dom.section_tree_to_html()
|
13
|
-
else
|
14
|
-
return ''
|
15
|
-
end
|
16
|
-
end
|
1
|
+
|
2
|
+
class NavigationPane
|
3
|
+
|
4
|
+
attr_accessor :specifications
|
5
|
+
|
6
|
+
def initialize(specification)
|
7
|
+
@doc = specification
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_html
|
11
|
+
if @doc.dom
|
12
|
+
return @doc.dom.section_tree_to_html()
|
13
|
+
else
|
14
|
+
return ''
|
15
|
+
end
|
16
|
+
end
|
17
17
|
end
|