Almirah 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4e770388ae634e216ef325d7f82a5d32d44bb5405dbea4e32783e3f0d2eea91
4
- data.tar.gz: 20871334c2ba2179e361abd1319634281bde45ba38032ec2fd3dabdea98f6e3a
3
+ metadata.gz: 877a4c7b296af5fa0418113a4287df82661d23903764f73a74b8794d2be22d9a
4
+ data.tar.gz: 4195b1434e0ca4c75177c4af9ea3e97ffa9a373106bda58fa11621ba273df7cf
5
5
  SHA512:
6
- metadata.gz: ad3b925c13c5a6794a82eabb3cfc81894c3f5711e5250cb0cb1dbaee0e79ff56e0e571e1dbcedb969c8384b3db82a021c082017d0cba001cb4ea1a2c314d21cd
7
- data.tar.gz: 38532ef2204233611d5330e5825c0ccc0234043eec49f54f81e768d2caecdbc20df78999a8dfed3b074b924fe7ae6c2bcc6d3658771863f7663ab75b8c5167d4
6
+ metadata.gz: 4425611cadee99f5686c79abbc853d93bbfeb0e729a97168f93842d998daf8e1a879de8e25918fcbd01bd49abe2b842cc192f24d137cd987d77816f606abed15
7
+ data.tar.gz: ca609c497ebde13428c516a0369f860c323f7bcaba740424d125b9a3c4bd2e1955f8f8aec665d6afd088cc44772c4edfaba5dc64f47827be631253111f82a446
@@ -0,0 +1,200 @@
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
+ doc.items.append(item)
56
+ doc.headings.append(item)
57
+
58
+ if level == 1 && doc.title == ""
59
+ doc.title = value
60
+ end
61
+
62
+ elsif res = /^\[(\S*)\]\s+(.*)/.match(s) # Controlled Paragraph
63
+
64
+ if tempMdTable
65
+ doc.items.append tempMdTable
66
+ tempMdTable = nil
67
+ end
68
+ if tempMdList
69
+ doc.items.append tempMdList
70
+ tempMdList = nil
71
+ end
72
+
73
+ id = res[1]
74
+ text = res[2]
75
+
76
+ #check if it contains the uplink
77
+ if tmp = /(.*)\s+>\[(\S*)\]$/.match(text) # >[SRS-001]
78
+
79
+ text = tmp[1]
80
+ up_link = tmp[2]
81
+
82
+ if tmp = /^([a-zA-Z]+)[-]\d+/.match(up_link) # SRS
83
+ doc.up_link_doc_id = tmp[1].downcase
84
+ end
85
+ end
86
+
87
+ item = ControlledParagraph.new( text, id )
88
+ item.up_link = up_link
89
+
90
+ doc.items.append(item)
91
+ doc.dictionary[ id.to_s ] = item #for fast search
92
+ doc.controlled_items.append(item) #for fast search
93
+
94
+ elsif res = /^[!]\[(.*)\]\((.*)\)/.match(s) # Image
95
+
96
+ if tempMdTable
97
+ doc.items.append tempMdTable
98
+ tempMdTable = nil
99
+ end
100
+ if tempMdList
101
+ doc.items.append tempMdList
102
+ tempMdList = nil
103
+ end
104
+
105
+ img_text = res[1]
106
+ img_path = res[2]
107
+
108
+ item = Image.new( img_text, img_path )
109
+
110
+ doc.items.append(item)
111
+
112
+ elsif res = /^(\*\s?)+(.*)/.match(s) #check if bullet list
113
+
114
+ if tempMdTable
115
+ doc.items.append tempMdTable
116
+ tempMdTable = nil
117
+ end
118
+
119
+ row = res[2]
120
+
121
+ if tempMdList
122
+ tempMdList.addRow(row)
123
+ else
124
+ item = MarkdownList.new(row)
125
+ tempMdList = item
126
+ end
127
+
128
+ elsif s[0] == '|' #check if table
129
+
130
+ if tempMdList
131
+ doc.items.append tempMdList
132
+ tempMdList = nil
133
+ end
134
+
135
+ if res = /^[|](-{3,})[|]/.match(s) #check if it is a separator first
136
+
137
+ if tempMdTable
138
+ #separator is found after heading - just skip it
139
+ else
140
+ #separator out of table scope consider it just as a regular paragraph
141
+ item = Paragraph.new(s)
142
+ doc.items.append(item)
143
+ end
144
+
145
+ elsif res = /^[|](.*[|])/.match(s) #check if it looks as a table
146
+
147
+ row = res[1]
148
+
149
+ if tempMdTable
150
+ # check if it is a controlled table
151
+ unless tempMdTable.addRow(row)
152
+ tempMdTable = ControlledTable.new(tempMdTable, doc)
153
+ tempMdTable.addRow(row)
154
+ end
155
+ else
156
+ #start table from heading
157
+ tempMdTable = MarkdownTable.new(row)
158
+ end
159
+ end
160
+
161
+ elsif res = /^[>](.*)/.match(s) #check if blockquote
162
+
163
+ if tempMdTable
164
+ doc.items.append tempMdTable
165
+ tempMdTable = nil
166
+ end
167
+ if tempMdList
168
+ doc.items.append tempMdList
169
+ tempMdList = nil
170
+ end
171
+
172
+ item = Blockquote.new(res[1])
173
+ doc.items.append(item)
174
+
175
+ else # Reqular Paragraph
176
+ if tempMdTable
177
+ doc.items.append tempMdTable
178
+ tempMdTable = nil
179
+ end
180
+ if tempMdList
181
+ doc.items.append tempMdList
182
+ tempMdList = nil
183
+ end
184
+
185
+ item = Paragraph.new(s)
186
+ doc.items.append(item)
187
+ end
188
+ end
189
+ end
190
+ # Finalize non-closed elements
191
+ if tempMdTable
192
+ doc.items.append tempMdTable
193
+ tempMdTable = nil
194
+ end
195
+ if tempMdList
196
+ doc.items.append tempMdList
197
+ tempMdList = nil
198
+ end
199
+ end
200
+ end
@@ -11,11 +11,11 @@ class Blockquote < DocItem
11
11
  def to_html
12
12
  s = ''
13
13
  if @@htmlTableRenderInProgress
14
- s += "</table>\n\r"
14
+ s += "</table>\n"
15
15
  @@htmlTableRenderInProgress = false
16
16
  end
17
17
 
18
- s += "<div class=\"blockquote\"><p>#{@text}</div>\n\r"
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
11
  @text = text
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\r"
20
- s += "\t<thead> <th>#</th> <th>Text</th> <th>UL</th> <th>DL</th> <th>COV</th> </thead>\n\r"
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\r"
24
- s += "\t\t<td class=\"item_id\"> <a name=\"#{@id}\"></a>#{@id} </td>\n\r"
25
- s += "\t\t<td class=\"item_text\">#{@text}</td>\n\r"
25
+ s += "\t<tr>\n"
26
+ s += "\t\t<td class=\"item_id\"> <a name=\"#{@id}\"></a>#{@id} </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\r"
33
+ 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"
32
34
  else
33
- s += "\t\t<td class=\"item_id\"></td>\n\r"
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\r"
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\r"
44
+ s += "\t\t<td class=\"item_id\"></td>\n"
43
45
  end
44
46
 
45
- #s += "\t\t<td></td>\n\r" # UL
46
- #s += "\t\t<td></td>\n\r" # DL
47
- s += "\t\t<td class=\"item_id\"></td>\n\r" # COV
48
- s += "\t</tr>\n\r"
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,172 @@
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
+
27
+ def initialize(text)
28
+ text = text.strip
29
+ @step_number = text.to_i
30
+ @text = text
31
+ end
32
+
33
+ def to_html
34
+ "\t\t<td style=\"text-align: center;\">#{@text}</td>\n\r"
35
+ end
36
+ end
37
+
38
+
39
+ class TestStepResultColumn < ControlledTableColumn
40
+
41
+ def to_html
42
+ if @text.downcase == "pass"
43
+ "\t\t<td style=\"background-color: #cfc;\">#{@text}</td>\n\r"
44
+ elsif @text.downcase == "fail"
45
+ "\t\t<td style=\"background-color: #fcc;\">#{@text}</td>\n\r"
46
+ else
47
+ "\t\t<td>#{@text}</td>\n\r"
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ class TestStepReferenceColumn < ControlledTableColumn
54
+
55
+ attr_accessor :up_link
56
+ attr_accessor :up_link_doc_id
57
+
58
+ def initialize(text)
59
+
60
+ @up_link = nil
61
+ @up_link_doc_id = nil
62
+
63
+ if tmp = />\[(\S*)\]/.match(text) # >[SRS-001]
64
+ @up_link = tmp[1]
65
+ if tmp = /^([a-zA-Z]+)[-]\d+/.match(@up_link) # SRS
66
+ @up_link_doc_id = tmp[1].downcase
67
+ end
68
+ end
69
+ end
70
+
71
+ def to_html
72
+ if @up_link
73
+ "\t\t<td class=\"item_id\"><a href=\"./../../../specifications/#{@up_link_doc_id}/#{@up_link_doc_id}.html\" class=\"external\">#{@up_link}</a></td>\n\r"
74
+ else
75
+ "\t\t<td style=\"text-align: center;\"></td>\n\r"
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+
82
+ class ControlledTable < DocItem
83
+
84
+ attr_accessor :column_names
85
+ attr_accessor :rows
86
+ attr_accessor :parent_doc
87
+
88
+ def initialize(markdown_table, parent_doc)
89
+ @parent_doc = parent_doc
90
+ @column_names = markdown_table.column_names
91
+ # copy and re-format existing rows
92
+ @rows = Array.new
93
+
94
+ markdown_table.rows.each do |r|
95
+ @rows.append(format_columns(r))
96
+ end
97
+ end
98
+
99
+ def addRow(row)
100
+
101
+ columns = row.split('|')
102
+
103
+ @rows.append(format_columns(columns))
104
+
105
+ return true
106
+ end
107
+
108
+ def format_columns(columns)
109
+
110
+ new_row = ControlledTableRow.new
111
+
112
+ columns.each_with_index do | element, index |
113
+
114
+ if index == 0 # it is expected that test step id is placed in the first columl
115
+
116
+ col = TestStepNumberColumn.new element
117
+ new_row.columns.append col
118
+ new_row.id = @parent_doc.id + '.' + col.text
119
+
120
+ elsif index + 1 == columns.length # it is expected that a link is placed to the last column only
121
+
122
+ col = TestStepReferenceColumn.new element
123
+ new_row.columns.append col
124
+ # save uplink key but do not rewrite
125
+ if col.up_link_doc_id != nil
126
+ if @parent_doc.up_link_doc_id == ""
127
+ @parent_doc.up_link_doc_id = col.up_link_doc_id
128
+ end
129
+ # save reference to the test step
130
+ new_row.up_link = col.up_link
131
+ @parent_doc.controlled_items.append new_row
132
+ end
133
+
134
+ elsif index + 2 == columns.length # it is expected that test step result is placed to the pre-last column only
135
+
136
+ col = TestStepResultColumn.new element
137
+ new_row.columns.append col
138
+
139
+ else
140
+ col = RegualrColumn.new element
141
+ new_row.columns.append col
142
+ end
143
+ end
144
+ return new_row
145
+ end
146
+
147
+ def to_html
148
+ s = ''
149
+ if @@htmlTableRenderInProgress
150
+ s += "</table>\n"
151
+ @@htmlTableRenderInProgress = false
152
+ end
153
+
154
+ s += "<table class=\"markdown_table\">\n"
155
+ s += "\t<thead>"
156
+
157
+ @column_names.each do |h|
158
+ s += " <th>#{h}</th>"
159
+ end
160
+
161
+ s += " </thead>\n"
162
+
163
+ @rows.each do |row|
164
+ s += row.to_html
165
+ end
166
+
167
+ s += "</table>\n"
168
+
169
+ return s
170
+ end
171
+
172
+ 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
@@ -3,22 +3,23 @@ require_relative "paragraph"
3
3
  class Heading < Paragraph
4
4
 
5
5
  attr_accessor :level
6
+ attr_accessor :anchor_id
6
7
 
7
8
  def initialize(text, level)
8
9
  @text = text
9
10
  @level = level
11
+ @anchor_id = self.getTextWithoutSpaces()
10
12
  end
11
13
 
12
14
  def to_html
13
15
  s = ''
14
16
  if @@htmlTableRenderInProgress
15
- s += "</table>"
17
+ s += "</table>\n"
16
18
  @@htmlTableRenderInProgress = false
17
19
  end
18
- headingLevel = level.to_s
19
- itemTextNoSpaces = self.getTextWithoutSpaces
20
- s += "<a name=\"#{itemTextNoSpaces}\"></a>\n\r"
21
- s += "<h#{headingLevel}> #{@text} <a href=\"\##{itemTextNoSpaces}\" class=\"heading_anchor\">"
20
+ headingLevel = level.to_s
21
+ s += "<a name=\"#{@anchor_id}\"></a>\n"
22
+ s += "<h#{headingLevel}> #{@text} <a href=\"\##{@anchor_id}\" class=\"heading_anchor\">"
22
23
  s += "&para;</a></h#{headingLevel}>"
23
24
  return s
24
25
  end
@@ -17,7 +17,7 @@ class Image < DocItem
17
17
  def to_html
18
18
  s = ''
19
19
  if @@htmlTableRenderInProgress
20
- s += "</table>\n\r"
20
+ s += "</table>\n"
21
21
  @@htmlTableRenderInProgress = false
22
22
  end
23
23
 
@@ -16,15 +16,15 @@ class MarkdownList < DocItem
16
16
  def to_html
17
17
  s = ''
18
18
  if @@htmlTableRenderInProgress
19
- s += "</table>/n/r"
19
+ s += "</table>\n"
20
20
  @@htmlTableRenderInProgress = false
21
21
  end
22
22
 
23
- s += "<ul>\n\r"
23
+ s += "<ul>\n"
24
24
  @rows.each do |r|
25
- s += "\t<li>#{r}</li>\n\r"
25
+ s += "\t<li>#{r}</li>\n"
26
26
  end
27
- s += "</ul>\n\r"
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\r"
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\r"
39
+ s += " </thead>\n"
33
40
 
34
41
  @rows.each do |row|
35
- s += "\t<tr>\n\r"
42
+ s += "\t<tr>\n"
36
43
  row.each do |col|
37
- s += "\t\t<td>#{col}</td>\n\r"
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\r"
50
+ s += "\t</tr>\n"
40
51
  end
41
52
 
42
- s += "</table>\n\r"
53
+ s += "</table>\n"
43
54
 
44
55
  return s
45
56
  end
@@ -0,0 +1,18 @@
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
+ end
@@ -0,0 +1,22 @@
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
+ end
@@ -0,0 +1,22 @@
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
+ 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
+ end