Almirah 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ require_relative "base_document"
2
+
3
+ class Coverage < BaseDocument
4
+
5
+ attr_accessor :top_doc
6
+ attr_accessor :bottom_doc
7
+ attr_accessor :items
8
+
9
+ def initialize(top_doc)
10
+
11
+ @top_doc = top_doc
12
+ @bottom_doc = bottom_doc
13
+
14
+ @items = Array.new
15
+ @headings = Array.new
16
+
17
+ @id = top_doc.id + "-" + "tests"
18
+ @title = "Coverage Matrix: " + @id
19
+ end
20
+
21
+ def to_console
22
+ puts "\e[35m" + "Traceability: " + @id + "\e[0m"
23
+ end
24
+
25
+ def to_html(nav_pane, output_file_path)
26
+
27
+ html_rows = Array.new
28
+
29
+ html_rows.append('')
30
+ s = "<h1>#{@title}</h1>\n"
31
+ s += "<table class=\"controlled\">\n"
32
+ s += "\t<thead> <th>#</th> <th style='font-weight: bold;'>#{@top_doc.title}</th> <th>#</th> <th style='font-weight: bold;'>Test CaseId.StepId</th> </thead>\n"
33
+ html_rows.append s
34
+
35
+ sorted_items = @top_doc.controlled_items.sort_by { |w| w.id }
36
+
37
+ sorted_items.each do |top_item|
38
+ row = render_table_row top_item
39
+ html_rows.append row
40
+ end
41
+ html_rows.append "</table>\n"
42
+
43
+ self.save_html_to_file(html_rows, nav_pane, output_file_path)
44
+
45
+ end
46
+
47
+ def render_table_row(top_item)
48
+ s = ""
49
+ if top_item.coverage_links
50
+ if top_item.coverage_links.length > 1
51
+ id_color = "" # "style='background-color: #fff8c5;'" # disabled for now
52
+ else
53
+ id_color = ""
54
+ end
55
+ top_item.coverage_links.each do |bottom_item|
56
+ s += "\t<tr>\n"
57
+ 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"
58
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'>#{top_item.text}</td>\n"
59
+
60
+ if bottom_item.columns[-2].text.downcase == "pass"
61
+ test_step_color = "style='background-color: #cfc;'"
62
+ elsif bottom_item.columns[-2].text.downcase == "fail"
63
+ test_step_color = "style='background-color: #fcc;'"
64
+ else
65
+ test_step_color = ""
66
+ end
67
+
68
+ s += "\t\t<td class=\"item_id\" #{test_step_color}><a href=\"./../../tests/protocols/#{bottom_item.parent_doc.id}/#{bottom_item.parent_doc.id}.html##{bottom_item.id}\" class=\"external\">#{bottom_item.id}</a></td>\n"
69
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'>#{bottom_item.columns[1].text}</td>\n"
70
+ s += "\t</tr>\n"
71
+ end
72
+ else
73
+ s += "\t<tr>\n"
74
+ 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"
75
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'>#{top_item.text}</td>\n"
76
+ s += "\t\t<td class=\"item_id\"></td>\n"
77
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'></td>\n"
78
+ s += "\t</tr>\n"
79
+ end
80
+ return s
81
+ end
82
+ end
@@ -0,0 +1,37 @@
1
+ require_relative "base_document"
2
+
3
+ class Protocol < BaseDocument
4
+
5
+ attr_accessor :up_link_doc_id
6
+ #attr_accessor :dictionary
7
+ attr_accessor :controlled_items
8
+
9
+ def initialize(fele_path)
10
+
11
+ @path = fele_path
12
+ @title = ""
13
+ @items = Array.new
14
+ @headings = Array.new
15
+ @controlled_items = Array.new
16
+ #@dictionary = Hash.new
17
+
18
+ @id = File.basename(fele_path, File.extname(fele_path)).downcase
19
+ @up_link_doc_id = ""
20
+ end
21
+
22
+ def to_html(nav_pane, output_file_path)
23
+
24
+ html_rows = Array.new
25
+
26
+ html_rows.append('')
27
+
28
+ @items.each do |item|
29
+ a = item.to_html
30
+ html_rows.append a
31
+ end
32
+
33
+ self.save_html_to_file(html_rows, nav_pane, output_file_path)
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,77 @@
1
+ require_relative "base_document"
2
+
3
+ class Specification < BaseDocument
4
+
5
+ attr_accessor :up_link_doc_id
6
+ attr_accessor :dictionary
7
+ attr_accessor :controlled_items
8
+
9
+ attr_accessor :items_with_uplinks_number
10
+ attr_accessor :items_with_downlinks_number
11
+ attr_accessor :items_with_coverage_number
12
+ attr_accessor :duplicated_ids_number
13
+ attr_accessor :last_used_id
14
+ attr_accessor :last_used_id_number
15
+
16
+ def initialize(fele_path)
17
+
18
+ @path = fele_path
19
+ @title = ""
20
+ @items = Array.new
21
+ @headings = Array.new
22
+ @controlled_items = Array.new
23
+ @dictionary = Hash.new
24
+
25
+ @items_with_uplinks_number = 0
26
+ @items_with_downlinks_number = 0
27
+ @items_with_coverage_number = 0
28
+ @duplicated_ids_number = 0
29
+ @last_used_id = ""
30
+ @last_used_id_number = 0
31
+
32
+ @id = File.basename(fele_path, File.extname(fele_path)).downcase
33
+ @up_link_doc_id = ""
34
+ end
35
+
36
+ def to_console
37
+ puts ""
38
+ puts "\e[33m" + "Specification: " + @title + "\e[0m"
39
+ puts "-" * 53
40
+ puts "| Number of Controlled Items | %10d |" % @controlled_items.length
41
+ puts "| Number of Items w/ Up-links | %10d |" % @items_with_uplinks_number
42
+ puts "| Number of Items w/ Down-links | %10d |" % @items_with_downlinks_number
43
+
44
+ # coverage
45
+ if (@controlled_items.length > 0) && (@controlled_items.length == @items_with_coverage_number)
46
+ puts "| Number of Items w/ Test Coverage |\e[1m\e[32m %10d \e[0m|" % @items_with_coverage_number
47
+ else
48
+ puts "| Number of Items w/ Test Coverage | %10d |" % @items_with_coverage_number
49
+ end
50
+
51
+ # duplicates
52
+ if @duplicated_ids_number >0
53
+ puts "| Duplicated Item Ids found |\e[1m\e[31m %10d \e[0m|" % @duplicated_ids_number
54
+ else
55
+ puts "| Duplicated Item Ids found | %10d |" % @duplicated_ids_number
56
+ end
57
+
58
+ puts "| Last used Item Id |\e[1m\e[37m %10s \e[0m|" % @last_used_id
59
+ puts "-" * 53
60
+ end
61
+
62
+ def to_html(nav_pane, output_file_path)
63
+
64
+ html_rows = Array.new
65
+
66
+ html_rows.append('')
67
+
68
+ @items.each do |item|
69
+ a = item.to_html
70
+ html_rows.append a
71
+ end
72
+
73
+ self.save_html_to_file(html_rows, nav_pane, output_file_path)
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,73 @@
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
+
9
+ def initialize(top_doc, bottom_doc)
10
+
11
+ @top_doc = top_doc
12
+ @bottom_doc = bottom_doc
13
+
14
+ @items = Array.new
15
+ @headings = Array.new
16
+
17
+ @id = top_doc.id + "-" + bottom_doc.id
18
+ @title = "Traceability Matrix: " + @id
19
+ end
20
+
21
+ def to_console
22
+ puts "\e[35m" + "Traceability: " + @id + "\e[0m"
23
+ end
24
+
25
+ def to_html(nav_pane, output_file_path)
26
+
27
+ html_rows = Array.new
28
+
29
+ html_rows.append('')
30
+ s = "<h1>#{@title}</h1>\n"
31
+ s += "<table class=\"controlled\">\n"
32
+ s += "\t<thead> <th>#</th> <th style='font-weight: bold;'>#{@top_doc.title}</th> <th>#</th> <th style='font-weight: bold;'>#{@bottom_doc.title}</th> </thead>\n"
33
+ html_rows.append s
34
+
35
+ sorted_items = @top_doc.controlled_items.sort_by { |w| w.id }
36
+
37
+ sorted_items.each do |top_item|
38
+ row = render_table_row top_item
39
+ html_rows.append row
40
+ end
41
+ html_rows.append "</table>\n"
42
+
43
+ self.save_html_to_file(html_rows, nav_pane, output_file_path)
44
+
45
+ end
46
+
47
+ def render_table_row(top_item)
48
+ s = ""
49
+ if top_item.down_links
50
+ if top_item.down_links.length > 1
51
+ id_color = "style='background-color: #fff8c5;'"
52
+ else
53
+ id_color = ""
54
+ end
55
+ top_item.down_links.each do |bottom_item|
56
+ s += "\t<tr>\n"
57
+ 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"
58
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'>#{top_item.text}</td>\n"
59
+ 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"
60
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'>#{bottom_item.text}</td>\n"
61
+ s += "\t</tr>\n"
62
+ end
63
+ else
64
+ s += "\t<tr>\n"
65
+ 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"
66
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'>#{top_item.text}</td>\n"
67
+ s += "\t\t<td class=\"item_id\"></td>\n"
68
+ s += "\t\t<td class=\"item_text\" style='width: 42%;'></td>\n"
69
+ s += "\t</tr>\n"
70
+ end
71
+ return s
72
+ end
73
+ end
@@ -1,5 +1,3 @@
1
- require_relative "doc_items/doc_item"
2
- require_relative "specification"
3
1
 
4
2
  class NavigationPane
5
3
 
@@ -12,10 +10,10 @@ class NavigationPane
12
10
  def to_html
13
11
  s = "<ul class=\"fa-ul\">\n"
14
12
  @specifications.each do |spec|
15
- s += "\t<li><span class=\"fa-li\"><i class=\"fa fa-folder-open-o\"> </i></span> #{spec.key.downcase}\n"
13
+ s += "\t<li><span class=\"fa-li\"><i class=\"fa fa-folder-open-o\"> </i></span> #{spec.id}\n"
16
14
  s += "\t\t<ul class=\"fa-ul\">\n"
17
15
  s += "\t\t\t<li><span class=\"fa-li\"><i class=\"fa fa-plus-square-o\"> </i></span>\n"
18
- s += "\t\t\t\t<a href=\".\\..\\#{spec.key.downcase }\\#{spec.key.downcase }.html\">#{spec.title}</a>\n"
16
+ s += "\t\t\t\t<a href=\".\\..\\#{spec.id }\\#{spec.id }.html\">#{spec.title}</a>\n"
19
17
  s += "\t\t\t</li>\n"
20
18
  s += "\t\t</ul>\n"
21
19
  s += "\t</li>\n"
@@ -1,57 +1,99 @@
1
- require_relative "doc_items/doc_item"
2
- require_relative "specification"
3
- require_relative "html_render"
1
+ require_relative "doc_fabric"
4
2
  require_relative "navigation_pane"
3
+ require_relative "doc_types/traceability"
4
+ require_relative "doc_types/coverage"
5
5
 
6
6
  class Project
7
7
 
8
8
  attr_accessor :specifications
9
+ attr_accessor :protocols
9
10
  attr_accessor :project_root_directory
10
- attr_accessor :gem_root
11
11
  attr_accessor :specifications_dictionary
12
12
 
13
- def initialize(path, gem_root)
13
+ def initialize(path)
14
14
  @project_root_directory = path
15
15
  @specifications = Array.new
16
- @gem_root = gem_root
16
+ @protocols = Array.new
17
17
  @specifications_dictionary = Hash.new
18
18
 
19
- parse_all_documents()
20
- link_all_specifications()
21
- render_all_specifications()
22
-
19
+ FileUtils.remove_dir(@project_root_directory + "/build", true)
23
20
  end
24
21
 
25
- def parse_all_documents
26
-
27
- Dir.glob( "#{@project_root_directory}/**/*.md" ).each do |f|
28
- puts f
29
- spec = Specification.new(f)
30
- @specifications.append(spec)
22
+ def specifications_and_protocols
23
+
24
+ parse_all_specifications
25
+ parse_all_protocols
26
+ link_all_specifications
27
+ link_all_protocols
28
+ render_all_specifications
29
+ render_all_protocols
30
+ end
31
+
32
+ def specifications_and_results( test_run )
33
+
34
+ parse_all_specifications
35
+ parse_test_run test_run
36
+ link_all_specifications
37
+ link_all_protocols
38
+ render_all_specifications
39
+ render_all_protocols
40
+ end
41
+
42
+ def parse_all_specifications
43
+ Dir.glob( "#{@project_root_directory}/specifications/**/*.md" ).each do |f|
44
+ puts "Spec: " + f
45
+ doc = DocFabric.create_specification(f)
46
+ @specifications.append(doc)
47
+ end
48
+ end
49
+
50
+ def parse_all_protocols
51
+ Dir.glob( "#{@project_root_directory}/tests/protocols/**/*.md" ).each do |f|
52
+ puts "Prot: " + f
53
+ doc = DocFabric.create_protocol(f)
54
+ @protocols.append(doc)
55
+ end
56
+ end
57
+
58
+ def parse_test_run( test_run )
59
+ Dir.glob( "#{@project_root_directory}/tests/runs/#{test_run}/**/*.md" ).each do |f|
60
+ puts "Run: " + f
61
+ doc = DocFabric.create_protocol(f)
62
+ @protocols.append(doc)
31
63
  end
32
64
  end
33
65
 
34
66
  def link_all_specifications
35
67
  combList = @specifications.combination(2)
36
68
  combList.each do |c|
37
- self.link_two_specifications(c[0], c[1])
69
+ link_two_specifications(c[0], c[1])
70
+ end
71
+ end
72
+
73
+ def link_all_protocols
74
+ @protocols.each do |p|
75
+ @specifications.each do |s|
76
+ if s.id == p.up_link_doc_id
77
+ link_protocol_to_spec(p,s)
78
+ end
79
+ end
38
80
  end
39
81
  end
40
82
 
41
83
  def link_two_specifications(doc_A, doc_B)
42
84
 
43
- if doc_A.key == doc_B.up_link_key
85
+ if doc_A.id == doc_B.up_link_doc_id
44
86
  top_document = doc_A
45
87
  bottom_document = doc_B
46
- elsif doc_B.key == doc_A.up_link_key
88
+ elsif doc_B.id == doc_A.up_link_doc_id
47
89
  top_document = doc_B
48
90
  bottom_document = doc_A
49
91
  else
50
92
  puts "No Links"
51
93
  return # no links
52
94
  end
53
-
54
- bottom_document.controlledParagraphs.each do |item|
95
+
96
+ bottom_document.controlled_items.each do |item|
55
97
 
56
98
  if top_document.dictionary.has_key?(item.up_link.to_s)
57
99
 
@@ -59,14 +101,37 @@ class Project
59
101
 
60
102
  unless topItem.down_links
61
103
  topItem.down_links = Array.new
104
+ top_document.items_with_downlinks_number += 1 # for statistics
62
105
  end
63
106
  topItem.down_links.append(item)
107
+ end
108
+ end
109
+ # create treceability document
110
+ trx = Traceability.new top_document, bottom_document
111
+ @specifications.append trx
112
+ end
113
+
114
+ def link_protocol_to_spec(protocol, specification)
115
+
116
+ top_document = specification
117
+ bottom_document = protocol
64
118
 
65
- #if tmp = /^([a-zA-Z]+)[-]\d+/.match(item.id)
66
- # top_document.downlinkKey = tmp[1].upcase
67
- #end
119
+ bottom_document.controlled_items.each do |item|
120
+
121
+ if top_document.dictionary.has_key?(item.up_link.to_s)
122
+
123
+ topItem = top_document.dictionary[item.up_link.to_s]
124
+
125
+ unless topItem.coverage_links
126
+ topItem.coverage_links = Array.new
127
+ top_document.items_with_coverage_number += 1 # for statistics
128
+ end
129
+ topItem.coverage_links.append(item)
68
130
  end
69
131
  end
132
+ # create coverage document
133
+ trx = Coverage.new top_document
134
+ @specifications.append trx
70
135
  end
71
136
 
72
137
  def render_all_specifications
@@ -76,13 +141,39 @@ class Project
76
141
 
77
142
  pass = @project_root_directory
78
143
 
79
- FileUtils.remove_dir(pass + "/build", true)
80
144
  FileUtils.mkdir_p(pass + "/build/specifications")
81
145
 
82
- @specifications.each do |spec|
146
+ @specifications.each do |doc|
147
+
148
+ doc.to_console
149
+
150
+ img_src_dir = pass + "/specifications/" + doc.id + "/img"
151
+ img_dst_dir = pass + "/build/specifications/" + doc.id + "/img"
152
+
153
+ FileUtils.mkdir_p(img_dst_dir)
154
+
155
+ if File.directory?(img_src_dir)
156
+ FileUtils.copy_entry( img_src_dir, img_dst_dir )
157
+ end
158
+
159
+ doc.to_html( nav_pane, "#{pass}/build/specifications/" )
160
+ end
161
+ end
162
+
163
+ def render_all_protocols
164
+
165
+ # create a sidebar first
166
+ nav_pane = NavigationPane.new(@specifications)
167
+
168
+ pass = @project_root_directory
169
+
170
+ # FileUtils.remove_dir(pass + "/build/tests", true)
171
+ FileUtils.mkdir_p(pass + "/build/tests/protocols")
172
+
173
+ @protocols.each do |doc|
83
174
 
84
- img_src_dir = pass + "/specifications/" + spec.key.downcase + "/img"
85
- img_dst_dir = pass + "/build/specifications/" + spec.key.downcase + "/img"
175
+ img_src_dir = pass + "/tests/protocols/" + doc.id + "/img"
176
+ img_dst_dir = pass + "/build/tests/protocols/" + doc.id + "/img"
86
177
 
87
178
  FileUtils.mkdir_p(img_dst_dir)
88
179
 
@@ -90,9 +181,7 @@ class Project
90
181
  FileUtils.copy_entry( img_src_dir, img_dst_dir )
91
182
  end
92
183
 
93
- HtmlRender.new( spec, nav_pane,
94
- @gem_root + "/lib/almirah/templates/page.html",
95
- "#{pass}/build/specifications/#{spec.key.downcase}/#{spec.key.downcase}.html" )
184
+ doc.to_html( nav_pane, "#{pass}/build/tests/protocols/" )
96
185
  end
97
186
  end
98
187
  end
@@ -89,7 +89,7 @@
89
89
  background-color:#e1f1fa;
90
90
  padding: 4px;
91
91
  white-space:nowrap;
92
- font-weight:bold;
92
+ font-weight:normal;
93
93
  border: 1px solid #bbb;
94
94
  }
95
95
  table.controlled td {
@@ -126,6 +126,13 @@
126
126
  a, a:link, a:visited {
127
127
  color: #169;
128
128
  text-decoration: none;
129
+ display: inline-block;
130
+ }
131
+ a:active {
132
+ color: #555;
133
+ background-color:#deb887;
134
+ text-decoration: none;
135
+ display: inline-block;
129
136
  }
130
137
  div.blockquote {
131
138
  display: block;
data/lib/almirah.rb CHANGED
@@ -2,22 +2,36 @@ require "thor"
2
2
  require_relative "almirah/project"
3
3
 
4
4
  class CLI < Thor
5
- desc "please <pass>", "say <pass>"
6
- def please(pass)
7
- Almirah.new().start(pass)
5
+ desc "please <project_folder>", "say <project_folder>"
6
+ option :results
7
+ def please(project_folder)
8
+ a = Almirah.new project_folder
9
+ if options[:results]
10
+ a.results options[:results]
11
+ else
12
+ a.default
13
+ end
8
14
  end
9
15
  end
10
16
 
11
17
  class Almirah
12
18
 
13
- def getGemRoot
14
- File.expand_path './..', File.dirname(__FILE__)
19
+ attr_accessor :project
20
+
21
+ def initialize(project_folder)
22
+ @project = Project.new project_folder
15
23
  end
16
24
 
17
- def start(pass)
25
+ def getGemRoot()
26
+ File.expand_path './..', File.dirname(__FILE__)
27
+ end
18
28
 
19
- prj = Project.new pass, getGemRoot
29
+ def results( test_run )
30
+ @project.specifications_and_results test_run
31
+ end
20
32
 
33
+ def default()
34
+ @project.specifications_and_protocols
21
35
  end
22
36
 
23
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Almirah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksandr Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-31 00:00:00.000000000 Z
11
+ date: 2024-02-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The software part of the Almirah system
14
14
  email: oleksandr.ivanov.development@gmail.com
@@ -19,18 +19,24 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/almirah
21
21
  - lib/almirah.rb
22
+ - lib/almirah/doc_fabric.rb
22
23
  - lib/almirah/doc_items/blockquote.rb
23
24
  - lib/almirah/doc_items/controlled_paragraph.rb
25
+ - lib/almirah/doc_items/controlled_table.rb
26
+ - lib/almirah/doc_items/controlled_table_row.rb
24
27
  - lib/almirah/doc_items/doc_item.rb
25
28
  - lib/almirah/doc_items/heading.rb
26
29
  - lib/almirah/doc_items/image.rb
27
30
  - lib/almirah/doc_items/markdown_list.rb
28
31
  - lib/almirah/doc_items/markdown_table.rb
29
32
  - lib/almirah/doc_items/paragraph.rb
30
- - lib/almirah/html_render.rb
33
+ - lib/almirah/doc_types/base_document.rb
34
+ - lib/almirah/doc_types/coverage.rb
35
+ - lib/almirah/doc_types/protocol.rb
36
+ - lib/almirah/doc_types/specification.rb
37
+ - lib/almirah/doc_types/traceability.rb
31
38
  - lib/almirah/navigation_pane.rb
32
39
  - lib/almirah/project.rb
33
- - lib/almirah/specification.rb
34
40
  - lib/almirah/templates/page.html
35
41
  homepage: http://almirah.site
36
42
  licenses:
@@ -1,55 +0,0 @@
1
- require_relative "specification"
2
- require_relative "doc_items/doc_item"
3
- require_relative "navigation_pane"
4
-
5
- class HtmlRender
6
-
7
- attr_accessor :template
8
- attr_accessor :htmlRows
9
- attr_accessor :outputFile
10
- attr_accessor :document
11
- attr_accessor :nav_pane
12
-
13
- def initialize(document, nav_pane, template, outputFile)
14
-
15
- @template = template
16
- @outputFile = outputFile
17
- @htmlRows = Array.new
18
- @document = document
19
- @nav_pane = nav_pane
20
-
21
- self.render()
22
- self.saveRenderToFile()
23
- end
24
-
25
- def render()
26
- self.htmlRows.append('')
27
-
28
- self.document.docItems.each do |item|
29
- a = item.to_html
30
- self.htmlRows.append a
31
- end
32
- end
33
-
34
- def saveRenderToFile()
35
-
36
- file = File.open( self.template )
37
- file_data = file.readlines
38
- file.close
39
-
40
- file = File.open( self.outputFile, "w" )
41
- file_data.each do |s|
42
- if s.include?('{{CONTENT}}')
43
- self.htmlRows.each do |r|
44
- file.puts r
45
- end
46
- elsif s.include?('{{NAV_PANE}}')
47
- file.puts self.nav_pane.to_html
48
- else
49
- file.puts s
50
- end
51
- end
52
- file.close
53
- end
54
-
55
- end