Almirah 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/almirah/doc_fabric.rb +221 -0
- data/lib/almirah/doc_items/blockquote.rb +2 -2
- data/lib/almirah/doc_items/controlled_paragraph.rb +21 -14
- data/lib/almirah/doc_items/controlled_table.rb +175 -0
- data/lib/almirah/doc_items/controlled_table_row.rb +23 -0
- data/lib/almirah/doc_items/doc_item.rb +4 -0
- data/lib/almirah/doc_items/heading.rb +2 -2
- data/lib/almirah/doc_items/image.rb +1 -1
- data/lib/almirah/doc_items/markdown_list.rb +4 -4
- data/lib/almirah/doc_items/markdown_table.rb +19 -8
- data/lib/almirah/doc_types/base_document.rb +45 -0
- data/lib/almirah/doc_types/coverage.rb +82 -0
- data/lib/almirah/doc_types/protocol.rb +37 -0
- data/lib/almirah/doc_types/specification.rb +77 -0
- data/lib/almirah/doc_types/traceability.rb +73 -0
- data/lib/almirah/navigation_pane.rb +2 -4
- data/lib/almirah/project.rb +120 -31
- data/lib/almirah/templates/page.html +8 -1
- data/lib/almirah.rb +21 -7
- metadata +10 -4
- data/lib/almirah/html_render.rb +0 -55
- data/lib/almirah/specification.rb +0 -194
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1841cdb6a5d88bcbe36d8ed926fd8f659e9a630d58763ead2b78e8b7f17281dd
|
4
|
+
data.tar.gz: 13b91603331fe68ff13f4b1917806551f94f11d98084ce773a1e247abb4b1abb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed609c1862a9f33b46c2379ae8f08904c30a00767939418e28600267ccc449aa88b7bcf96efc661c1c3d39d9a720a12491c01eed4c0c30034623f342a47d5d70
|
7
|
+
data.tar.gz: e5c91e4efbd5d96d915ad2228b22982391ccc91eae8afc545dc8c1fd1a8f077a690d9da988e47794df470eda560e7f6a0a99ec7a173d33660c0cc532de1c5e97
|
@@ -0,0 +1,221 @@
|
|
1
|
+
#
|
2
|
+
require_relative "doc_types/base_document"
|
3
|
+
require_relative "doc_types/specification"
|
4
|
+
require_relative "doc_types/protocol"
|
5
|
+
#
|
6
|
+
require_relative "doc_items/doc_item"
|
7
|
+
require_relative "doc_items/heading"
|
8
|
+
require_relative "doc_items/paragraph"
|
9
|
+
require_relative "doc_items/blockquote"
|
10
|
+
require_relative "doc_items/controlled_paragraph"
|
11
|
+
require_relative "doc_items/markdown_table"
|
12
|
+
require_relative "doc_items/controlled_table"
|
13
|
+
require_relative "doc_items/image"
|
14
|
+
require_relative "doc_items/markdown_list"
|
15
|
+
|
16
|
+
class DocFabric
|
17
|
+
|
18
|
+
def self.create_specification(path)
|
19
|
+
doc = Specification.new path
|
20
|
+
DocFabric.parse_document doc
|
21
|
+
return doc
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create_protocol(path)
|
25
|
+
doc = Protocol.new path
|
26
|
+
DocFabric.parse_document doc
|
27
|
+
return doc
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.parse_document(doc)
|
31
|
+
|
32
|
+
tempMdTable = nil
|
33
|
+
tempMdList = nil
|
34
|
+
|
35
|
+
file = File.open( doc.path )
|
36
|
+
file_lines = file.readlines
|
37
|
+
file.close
|
38
|
+
|
39
|
+
file_lines.each do |s|
|
40
|
+
if s.lstrip != ""
|
41
|
+
if res = /^([#]{1,})\s(.*)/.match(s) # Heading
|
42
|
+
|
43
|
+
if tempMdTable
|
44
|
+
doc.items.append tempMdTable
|
45
|
+
tempMdTable = nil
|
46
|
+
end
|
47
|
+
if tempMdList
|
48
|
+
doc.items.append tempMdList
|
49
|
+
tempMdList = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
level = res[1].length
|
53
|
+
value = res[2]
|
54
|
+
item = Heading.new(value, level)
|
55
|
+
item.parent_doc = doc
|
56
|
+
doc.items.append(item)
|
57
|
+
doc.headings.append(item)
|
58
|
+
|
59
|
+
if level == 1 && doc.title == ""
|
60
|
+
doc.title = value
|
61
|
+
end
|
62
|
+
|
63
|
+
elsif res = /^\[(\S*)\]\s+(.*)/.match(s) # Controlled Paragraph
|
64
|
+
|
65
|
+
if tempMdTable
|
66
|
+
doc.items.append tempMdTable
|
67
|
+
tempMdTable = nil
|
68
|
+
end
|
69
|
+
if tempMdList
|
70
|
+
doc.items.append tempMdList
|
71
|
+
tempMdList = nil
|
72
|
+
end
|
73
|
+
|
74
|
+
id = res[1]
|
75
|
+
text = res[2]
|
76
|
+
|
77
|
+
#check if it contains the uplink
|
78
|
+
if tmp = /(.*)\s+>\[(\S*)\]$/.match(text) # >[SRS-001]
|
79
|
+
|
80
|
+
text = tmp[1]
|
81
|
+
up_link = tmp[2]
|
82
|
+
|
83
|
+
if tmp = /^([a-zA-Z]+)[-]\d+/.match(up_link) # SRS
|
84
|
+
doc.up_link_doc_id = tmp[1].downcase
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
item = ControlledParagraph.new( text, id )
|
89
|
+
item.parent_doc = doc
|
90
|
+
if up_link
|
91
|
+
item.up_link = up_link
|
92
|
+
doc.items_with_uplinks_number += 1 #for statistics
|
93
|
+
end
|
94
|
+
|
95
|
+
doc.items.append(item)
|
96
|
+
doc.dictionary[ id.to_s ] = item #for fast search
|
97
|
+
doc.controlled_items.append(item) #for fast search
|
98
|
+
|
99
|
+
#for statistics
|
100
|
+
n = /\d+/.match(id)[0].to_i
|
101
|
+
if n == doc.last_used_id_number
|
102
|
+
doc.duplicated_ids_number += 1
|
103
|
+
elsif n > doc.last_used_id_number
|
104
|
+
doc.last_used_id = id
|
105
|
+
doc.last_used_id_number = n
|
106
|
+
end
|
107
|
+
|
108
|
+
elsif res = /^[!]\[(.*)\]\((.*)\)/.match(s) # Image
|
109
|
+
|
110
|
+
if tempMdTable
|
111
|
+
doc.items.append tempMdTable
|
112
|
+
tempMdTable = nil
|
113
|
+
end
|
114
|
+
if tempMdList
|
115
|
+
doc.items.append tempMdList
|
116
|
+
tempMdList = nil
|
117
|
+
end
|
118
|
+
|
119
|
+
img_text = res[1]
|
120
|
+
img_path = res[2]
|
121
|
+
|
122
|
+
item = Image.new( img_text, img_path )
|
123
|
+
item.parent_doc = doc
|
124
|
+
|
125
|
+
doc.items.append(item)
|
126
|
+
|
127
|
+
elsif res = /^(\*\s?)+(.*)/.match(s) #check if bullet list
|
128
|
+
|
129
|
+
if tempMdTable
|
130
|
+
doc.items.append tempMdTable
|
131
|
+
tempMdTable = nil
|
132
|
+
end
|
133
|
+
|
134
|
+
row = res[2]
|
135
|
+
|
136
|
+
if tempMdList
|
137
|
+
tempMdList.addRow(row)
|
138
|
+
else
|
139
|
+
item = MarkdownList.new(row)
|
140
|
+
item.parent_doc = doc
|
141
|
+
tempMdList = item
|
142
|
+
end
|
143
|
+
|
144
|
+
elsif s[0] == '|' #check if table
|
145
|
+
|
146
|
+
if tempMdList
|
147
|
+
doc.items.append tempMdList
|
148
|
+
tempMdList = nil
|
149
|
+
end
|
150
|
+
|
151
|
+
if res = /^[|](-{3,})[|]/.match(s) #check if it is a separator first
|
152
|
+
|
153
|
+
if tempMdTable
|
154
|
+
#separator is found after heading - just skip it
|
155
|
+
else
|
156
|
+
#separator out of table scope consider it just as a regular paragraph
|
157
|
+
item = Paragraph.new(s)
|
158
|
+
item.parent_doc = doc
|
159
|
+
doc.items.append(item)
|
160
|
+
end
|
161
|
+
|
162
|
+
elsif res = /^[|](.*[|])/.match(s) #check if it looks as a table
|
163
|
+
|
164
|
+
row = res[1]
|
165
|
+
|
166
|
+
if tempMdTable
|
167
|
+
# check if it is a controlled table
|
168
|
+
unless tempMdTable.addRow(row)
|
169
|
+
tempMdTable = ControlledTable.new(tempMdTable, doc)
|
170
|
+
tempMdTable.parent_doc = doc
|
171
|
+
tempMdTable.addRow(row)
|
172
|
+
end
|
173
|
+
else
|
174
|
+
#start table from heading
|
175
|
+
tempMdTable = MarkdownTable.new(row)
|
176
|
+
tempMdTable.parent_doc = doc
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
elsif res = /^[>](.*)/.match(s) #check if blockquote
|
181
|
+
|
182
|
+
if tempMdTable
|
183
|
+
doc.items.append tempMdTable
|
184
|
+
tempMdTable = nil
|
185
|
+
end
|
186
|
+
if tempMdList
|
187
|
+
doc.items.append tempMdList
|
188
|
+
tempMdList = nil
|
189
|
+
end
|
190
|
+
|
191
|
+
item = Blockquote.new(res[1])
|
192
|
+
item.parent_doc = doc
|
193
|
+
doc.items.append(item)
|
194
|
+
|
195
|
+
else # Reqular Paragraph
|
196
|
+
if tempMdTable
|
197
|
+
doc.items.append tempMdTable
|
198
|
+
tempMdTable = nil
|
199
|
+
end
|
200
|
+
if tempMdList
|
201
|
+
doc.items.append tempMdList
|
202
|
+
tempMdList = nil
|
203
|
+
end
|
204
|
+
|
205
|
+
item = Paragraph.new(s)
|
206
|
+
item.parent_doc = doc
|
207
|
+
doc.items.append(item)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
# Finalize non-closed elements
|
212
|
+
if tempMdTable
|
213
|
+
doc.items.append tempMdTable
|
214
|
+
tempMdTable = nil
|
215
|
+
end
|
216
|
+
if tempMdList
|
217
|
+
doc.items.append tempMdList
|
218
|
+
tempMdList = nil
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
@@ -11,11 +11,11 @@ class Blockquote < DocItem
|
|
11
11
|
def to_html
|
12
12
|
s = ''
|
13
13
|
if @@htmlTableRenderInProgress
|
14
|
-
s += "</table>\n
|
14
|
+
s += "</table>\n"
|
15
15
|
@@htmlTableRenderInProgress = false
|
16
16
|
end
|
17
17
|
|
18
|
-
s += "<div class=\"blockquote\"><p>#{@text}</div>\n
|
18
|
+
s += "<div class=\"blockquote\"><p>#{@text}</div>\n"
|
19
19
|
return s
|
20
20
|
end
|
21
21
|
end
|
@@ -5,47 +5,54 @@ class ControlledParagraph < Paragraph
|
|
5
5
|
attr_accessor :id
|
6
6
|
attr_accessor :up_link
|
7
7
|
attr_accessor :down_links
|
8
|
+
attr_accessor :coverage_links
|
8
9
|
|
9
10
|
def initialize(text, id)
|
10
|
-
@text = text
|
11
|
+
@text = text.strip
|
11
12
|
@id = id
|
12
13
|
@up_link = nil
|
13
14
|
@down_links = nil
|
15
|
+
@coverage_links = nil
|
14
16
|
end
|
15
17
|
|
16
18
|
def to_html
|
17
19
|
s = ''
|
18
20
|
unless @@htmlTableRenderInProgress
|
19
|
-
s += "<table class=\"controlled\">\n
|
20
|
-
s += "\t<thead> <th>#</th> <th>Text</th> <th>UL</th> <th>DL</th> <th>COV</th> </thead>\n
|
21
|
+
s += "<table class=\"controlled\">\n"
|
22
|
+
s += "\t<thead> <th>#</th> <th>Text</th> <th>UL</th> <th>DL</th> <th>COV</th> </thead>\n"
|
21
23
|
@@htmlTableRenderInProgress = true
|
22
24
|
end
|
23
|
-
s += "\t<tr>\n
|
24
|
-
s += "\t\t<td class=\"item_id\"> <a name=\"#{@id}\"
|
25
|
-
s += "\t\t<td class=\"item_text\">#{@text}</td>\n
|
25
|
+
s += "\t<tr>\n"
|
26
|
+
s += "\t\t<td class=\"item_id\"> <a name=\"#{@id}\" id=\"#{@id}\" href=\"##{@id}\">#{@id}</a></td>\n"
|
27
|
+
s += "\t\t<td class=\"item_text\">#{@text}</td>\n"
|
26
28
|
|
27
29
|
if @up_link
|
28
30
|
if tmp = /^([a-zA-Z]+)[-]\d+/.match(@up_link)
|
29
31
|
up_link_doc_name = tmp[1].downcase
|
30
32
|
end
|
31
|
-
s += "\t\t<td class=\"item_id\"><a href=\"./../#{up_link_doc_name}/#{up_link_doc_name}.html\" class=\"external\">#{@up_link}</a></td>\n
|
33
|
+
s += "\t\t<td class=\"item_id\"><a href=\"./../#{up_link_doc_name}/#{up_link_doc_name}.html##{@up_link}\" class=\"external\">#{@up_link}</a></td>\n"
|
32
34
|
else
|
33
|
-
s += "\t\t<td class=\"item_id\"></td>\n
|
35
|
+
s += "\t\t<td class=\"item_id\"></td>\n"
|
34
36
|
end
|
35
37
|
|
36
38
|
if @down_links
|
37
39
|
if tmp = /^([a-zA-Z]+)[-]\d+/.match(@down_links[0].id) # guessing that all the links refer to one document
|
38
40
|
down_link_doc_name = tmp[1].downcase
|
39
41
|
end
|
40
|
-
s += "\t\t<td class=\"item_id\"><a href=\"./../#{down_link_doc_name}/#{down_link_doc_name}.html\" class=\"external\">#{@down_links.length}</a></td>\n
|
42
|
+
s += "\t\t<td class=\"item_id\"><a href=\"./../#{down_link_doc_name}/#{down_link_doc_name}.html\" class=\"external\">#{@down_links.length}</a></td>\n"
|
41
43
|
else
|
42
|
-
s += "\t\t<td class=\"item_id\"></td>\n
|
44
|
+
s += "\t\t<td class=\"item_id\"></td>\n"
|
43
45
|
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
if @coverage_links
|
48
|
+
if tmp = /^(.+)[.]\d+/.match(@coverage_links[0].id) # guessing that all the links refer to one document
|
49
|
+
cov_link_doc_name = tmp[1].downcase
|
50
|
+
end
|
51
|
+
s += "\t\t<td class=\"item_id\"><a href=\"./../../tests/protocols/#{cov_link_doc_name}/#{cov_link_doc_name}.html\" class=\"external\">#{@coverage_links.length}</a></td>\n"
|
52
|
+
else
|
53
|
+
s += "\t\t<td class=\"item_id\"></td>\n"
|
54
|
+
end
|
55
|
+
s += "\t</tr>\n"
|
49
56
|
return s
|
50
57
|
end
|
51
58
|
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require_relative "controlled_table_row"
|
2
|
+
|
3
|
+
|
4
|
+
class ControlledTableColumn
|
5
|
+
|
6
|
+
attr_accessor :text
|
7
|
+
|
8
|
+
def initialize(text)
|
9
|
+
@text = text.strip
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_html
|
13
|
+
"\t\t<td>#{@text}</td>\n\r"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
class RegualrColumn < ControlledTableColumn
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
class TestStepNumberColumn < ControlledTableColumn
|
24
|
+
|
25
|
+
attr_accessor :step_number
|
26
|
+
attr_accessor :row_id
|
27
|
+
|
28
|
+
def initialize(text)
|
29
|
+
text = text.strip
|
30
|
+
@step_number = text.to_i
|
31
|
+
@text = text
|
32
|
+
@row_id = ""
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_html
|
36
|
+
"\t\t<td style=\"text-align: center;\"><a name=\"#{@row_id}\" id=\"#{@row_id}\" href=\"##{@row_id}\">#{@text}</a></td>\n\r"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
class TestStepResultColumn < ControlledTableColumn
|
42
|
+
|
43
|
+
def to_html
|
44
|
+
if @text.downcase == "pass"
|
45
|
+
"\t\t<td style=\"background-color: #cfc;\">#{@text}</td>\n\r"
|
46
|
+
elsif @text.downcase == "fail"
|
47
|
+
"\t\t<td style=\"background-color: #fcc;\">#{@text}</td>\n\r"
|
48
|
+
else
|
49
|
+
"\t\t<td>#{@text}</td>\n\r"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
class TestStepReferenceColumn < ControlledTableColumn
|
56
|
+
|
57
|
+
attr_accessor :up_link
|
58
|
+
attr_accessor :up_link_doc_id
|
59
|
+
|
60
|
+
def initialize(text)
|
61
|
+
|
62
|
+
@up_link = nil
|
63
|
+
@up_link_doc_id = nil
|
64
|
+
|
65
|
+
if tmp = />\[(\S*)\]/.match(text) # >[SRS-001]
|
66
|
+
@up_link = tmp[1]
|
67
|
+
if tmp = /^([a-zA-Z]+)[-]\d+/.match(@up_link) # SRS
|
68
|
+
@up_link_doc_id = tmp[1].downcase
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_html
|
74
|
+
if @up_link
|
75
|
+
"\t\t<td class=\"item_id\"><a href=\"./../../../specifications/#{@up_link_doc_id}/#{@up_link_doc_id}.html##{@up_link}\" class=\"external\">#{@up_link}</a></td>\n\r"
|
76
|
+
else
|
77
|
+
"\t\t<td style=\"text-align: center;\"></td>\n\r"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
class ControlledTable < DocItem
|
85
|
+
|
86
|
+
attr_accessor :column_names
|
87
|
+
attr_accessor :rows
|
88
|
+
|
89
|
+
def initialize(markdown_table, parent_doc)
|
90
|
+
@parent_doc = parent_doc
|
91
|
+
@column_names = markdown_table.column_names
|
92
|
+
# copy and re-format existing rows
|
93
|
+
@rows = Array.new
|
94
|
+
|
95
|
+
markdown_table.rows.each do |r|
|
96
|
+
@rows.append(format_columns(r))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def addRow(row)
|
101
|
+
|
102
|
+
columns = row.split('|')
|
103
|
+
|
104
|
+
@rows.append(format_columns(columns))
|
105
|
+
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
|
109
|
+
def format_columns(columns)
|
110
|
+
|
111
|
+
new_row = ControlledTableRow.new
|
112
|
+
new_row.parent_doc = @parent_doc
|
113
|
+
|
114
|
+
columns.each_with_index do | element, index |
|
115
|
+
|
116
|
+
if index == 0 # it is expected that test step id is placed in the first columl
|
117
|
+
|
118
|
+
col = TestStepNumberColumn.new element
|
119
|
+
new_row.columns.append col
|
120
|
+
new_row.id = @parent_doc.id + '.' + col.text
|
121
|
+
col.row_id = new_row.id
|
122
|
+
|
123
|
+
elsif index + 1 == columns.length # it is expected that a link is placed to the last column only
|
124
|
+
|
125
|
+
col = TestStepReferenceColumn.new element
|
126
|
+
new_row.columns.append col
|
127
|
+
# save uplink key but do not rewrite
|
128
|
+
if col.up_link_doc_id != nil
|
129
|
+
if @parent_doc.up_link_doc_id == ""
|
130
|
+
@parent_doc.up_link_doc_id = col.up_link_doc_id
|
131
|
+
end
|
132
|
+
# save reference to the test step
|
133
|
+
new_row.up_link = col.up_link
|
134
|
+
@parent_doc.controlled_items.append new_row
|
135
|
+
end
|
136
|
+
|
137
|
+
elsif index + 2 == columns.length # it is expected that test step result is placed to the pre-last column only
|
138
|
+
|
139
|
+
col = TestStepResultColumn.new element
|
140
|
+
new_row.columns.append col
|
141
|
+
|
142
|
+
else
|
143
|
+
col = RegualrColumn.new element
|
144
|
+
new_row.columns.append col
|
145
|
+
end
|
146
|
+
end
|
147
|
+
return new_row
|
148
|
+
end
|
149
|
+
|
150
|
+
def to_html
|
151
|
+
s = ''
|
152
|
+
if @@htmlTableRenderInProgress
|
153
|
+
s += "</table>\n"
|
154
|
+
@@htmlTableRenderInProgress = false
|
155
|
+
end
|
156
|
+
|
157
|
+
s += "<table class=\"markdown_table\">\n"
|
158
|
+
s += "\t<thead>"
|
159
|
+
|
160
|
+
@column_names.each do |h|
|
161
|
+
s += " <th>#{h}</th>"
|
162
|
+
end
|
163
|
+
|
164
|
+
s += " </thead>\n"
|
165
|
+
|
166
|
+
@rows.each do |row|
|
167
|
+
s += row.to_html
|
168
|
+
end
|
169
|
+
|
170
|
+
s += "</table>\n"
|
171
|
+
|
172
|
+
return s
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "doc_item"
|
2
|
+
|
3
|
+
class ControlledTableRow < DocItem
|
4
|
+
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :up_link
|
7
|
+
attr_accessor :columns
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@id = ""
|
11
|
+
@up_link = ""
|
12
|
+
@columns = Array.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_html
|
16
|
+
s = ""
|
17
|
+
s += "\t<tr>\n"
|
18
|
+
@columns.each do |col|
|
19
|
+
s += col.to_html # "\t\t<td>#{col}</td>\n\r"
|
20
|
+
end
|
21
|
+
s += "\t</tr>\n"
|
22
|
+
end
|
23
|
+
end
|
@@ -14,11 +14,11 @@ class Heading < Paragraph
|
|
14
14
|
def to_html
|
15
15
|
s = ''
|
16
16
|
if @@htmlTableRenderInProgress
|
17
|
-
s += "</table
|
17
|
+
s += "</table>\n"
|
18
18
|
@@htmlTableRenderInProgress = false
|
19
19
|
end
|
20
20
|
headingLevel = level.to_s
|
21
|
-
s += "<a name=\"#{@anchor_id}\"></a>\n
|
21
|
+
s += "<a name=\"#{@anchor_id}\"></a>\n"
|
22
22
|
s += "<h#{headingLevel}> #{@text} <a href=\"\##{@anchor_id}\" class=\"heading_anchor\">"
|
23
23
|
s += "¶</a></h#{headingLevel}>"
|
24
24
|
return s
|
@@ -16,15 +16,15 @@ class MarkdownList < DocItem
|
|
16
16
|
def to_html
|
17
17
|
s = ''
|
18
18
|
if @@htmlTableRenderInProgress
|
19
|
-
s += "</table
|
19
|
+
s += "</table>\n"
|
20
20
|
@@htmlTableRenderInProgress = false
|
21
21
|
end
|
22
22
|
|
23
|
-
s += "<ul>\n
|
23
|
+
s += "<ul>\n"
|
24
24
|
@rows.each do |r|
|
25
|
-
s += "\t<li>#{r}</li>\n
|
25
|
+
s += "\t<li>#{r}</li>\n"
|
26
26
|
end
|
27
|
-
s += "</ul>\n
|
27
|
+
s += "</ul>\n"
|
28
28
|
|
29
29
|
return s
|
30
30
|
end
|
@@ -11,35 +11,46 @@ class MarkdownTable < DocItem
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def addRow(row)
|
14
|
+
#check if row contains a link
|
15
|
+
if tmp = /(.*)\s+>\[(\S*)\]/.match(row)
|
16
|
+
return false # this is not a regular Markdown table.
|
17
|
+
# so the table type shall be changed and this row shall be passed one more time
|
18
|
+
end
|
19
|
+
|
14
20
|
columns = row.split('|')
|
15
|
-
@rows.append(columns)
|
21
|
+
@rows.append(columns.map!{ |x| x.strip })
|
22
|
+
return true
|
16
23
|
end
|
17
24
|
|
18
25
|
def to_html
|
19
26
|
s = ''
|
20
27
|
if @@htmlTableRenderInProgress
|
21
|
-
s += "</table
|
28
|
+
s += "</table>\n"
|
22
29
|
@@htmlTableRenderInProgress = false
|
23
30
|
end
|
24
31
|
|
25
|
-
s += "<table class=\"markdown_table\">\n
|
32
|
+
s += "<table class=\"markdown_table\">\n"
|
26
33
|
s += "\t<thead>"
|
27
34
|
|
28
35
|
@column_names.each do |h|
|
29
36
|
s += " <th>#{h}</th>"
|
30
37
|
end
|
31
38
|
|
32
|
-
s += " </thead>\n
|
39
|
+
s += " </thead>\n"
|
33
40
|
|
34
41
|
@rows.each do |row|
|
35
|
-
s += "\t<tr>\n
|
42
|
+
s += "\t<tr>\n"
|
36
43
|
row.each do |col|
|
37
|
-
|
44
|
+
if col.to_i > 0 && col.to_i.to_s == col # autoalign cells with numbers
|
45
|
+
s += "\t\t<td style=\"text-align: center;\">#{col}</td>\n"
|
46
|
+
else
|
47
|
+
s += "\t\t<td>#{col}</td>\n"
|
48
|
+
end
|
38
49
|
end
|
39
|
-
s += "\t</tr>\n
|
50
|
+
s += "\t</tr>\n"
|
40
51
|
end
|
41
52
|
|
42
|
-
s += "</table>\n
|
53
|
+
s += "</table>\n"
|
43
54
|
|
44
55
|
return s
|
45
56
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
class BaseDocument
|
3
|
+
|
4
|
+
attr_accessor :path
|
5
|
+
attr_accessor :items
|
6
|
+
attr_accessor :headings
|
7
|
+
attr_accessor :title
|
8
|
+
attr_accessor :id
|
9
|
+
|
10
|
+
def initialize(fele_path)
|
11
|
+
|
12
|
+
@path = fele_path
|
13
|
+
@items = Array.new
|
14
|
+
@headings = Array.new
|
15
|
+
@title = ""
|
16
|
+
@id = ""
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_html_to_file html_rows, nav_pane, output_file_path
|
20
|
+
|
21
|
+
gem_root = File.expand_path './../../..', File.dirname(__FILE__)
|
22
|
+
template_file = gem_root + "/lib/almirah/templates/page.html"
|
23
|
+
|
24
|
+
file = File.open( template_file )
|
25
|
+
file_data = file.readlines
|
26
|
+
file.close
|
27
|
+
|
28
|
+
output_file_path += "#{@id}/#{@id}.html"
|
29
|
+
file = File.open( output_file_path, "w" )
|
30
|
+
file_data.each do |s|
|
31
|
+
if s.include?('{{CONTENT}}')
|
32
|
+
html_rows.each do |r|
|
33
|
+
file.puts r
|
34
|
+
end
|
35
|
+
elsif s.include?('{{NAV_PANE}}')
|
36
|
+
if nav_pane
|
37
|
+
file.puts nav_pane.to_html
|
38
|
+
end
|
39
|
+
else
|
40
|
+
file.puts s
|
41
|
+
end
|
42
|
+
end
|
43
|
+
file.close
|
44
|
+
end
|
45
|
+
end
|