Almirah 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/almirah/doc_fabric.rb +21 -2
- data/lib/almirah/doc_items/blockquote.rb +2 -2
- data/lib/almirah/doc_items/code_block.rb +2 -2
- data/lib/almirah/doc_items/controlled_paragraph.rb +100 -79
- data/lib/almirah/doc_items/controlled_table.rb +181 -134
- data/lib/almirah/doc_items/controlled_table_row.rb +3 -3
- data/lib/almirah/doc_items/doc_footer.rb +2 -2
- data/lib/almirah/doc_items/doc_item.rb +1 -1
- data/lib/almirah/doc_items/heading.rb +80 -85
- data/lib/almirah/doc_items/image.rb +2 -2
- data/lib/almirah/doc_items/markdown_list.rb +134 -143
- data/lib/almirah/doc_items/markdown_table.rb +52 -48
- data/lib/almirah/doc_items/paragraph.rb +6 -4
- data/lib/almirah/doc_items/text_line.rb +247 -264
- data/lib/almirah/doc_items/todo_block.rb +2 -2
- data/lib/almirah/doc_parser.rb +56 -60
- data/lib/almirah/doc_types/base_document.rb +1 -0
- data/lib/almirah/doc_types/coverage.rb +4 -1
- data/lib/almirah/doc_types/index.rb +26 -18
- data/lib/almirah/doc_types/specification.rb +56 -93
- data/lib/almirah/doc_types/traceability.rb +6 -2
- data/lib/almirah/dom/doc_section.rb +21 -24
- data/lib/almirah/dom/document.rb +66 -57
- data/lib/almirah/project.rb +257 -275
- data/lib/almirah/search/specifications_db.rb +18 -1
- data/lib/almirah/templates/css/main.css +5 -2
- data/lib/almirah/templates/page.html +4 -2
- data/lib/almirah/templates/scripts/main.js +54 -3
- metadata +2 -2
@@ -1,313 +1,296 @@
|
|
1
1
|
class TextLineToken
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
attr_accessor :value
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@value = ''
|
6
|
+
end
|
6
7
|
end
|
7
8
|
|
8
9
|
class ItalicToken < TextLineToken
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
10
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
11
|
+
@value = '*'
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
15
|
class BoldToken < TextLineToken
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
17
|
+
@value = '**'
|
18
|
+
end
|
20
19
|
end
|
21
20
|
|
22
21
|
class BoldAndItalicToken < TextLineToken
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
22
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
23
|
+
@value = '***'
|
24
|
+
end
|
27
25
|
end
|
28
26
|
|
29
27
|
class ParentheseLeft < TextLineToken
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
28
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
29
|
+
@value = '('
|
30
|
+
end
|
34
31
|
end
|
35
32
|
|
36
33
|
class ParentheseRight < TextLineToken
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
34
|
+
def initialize
|
35
|
+
@value = ')'
|
36
|
+
end
|
41
37
|
end
|
42
38
|
|
43
39
|
class SquareBracketLeft < TextLineToken
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
40
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
41
|
+
@value = '['
|
42
|
+
end
|
48
43
|
end
|
49
44
|
|
50
45
|
class SquareBracketRight < TextLineToken
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
46
|
+
def initialize
|
47
|
+
@value = ']'
|
48
|
+
end
|
55
49
|
end
|
56
50
|
|
57
51
|
class SquareBracketRightAndParentheseLeft < TextLineToken
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
52
|
+
def initialize
|
53
|
+
@value = ']('
|
54
|
+
end
|
62
55
|
end
|
63
56
|
|
64
57
|
class TextLineParser
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
si += 1
|
108
|
-
end
|
109
|
-
end
|
58
|
+
attr_accessor :supported_tokens
|
59
|
+
|
60
|
+
def initialize # rubocop:disable Metrics/AbcSize
|
61
|
+
@supported_tokens = []
|
62
|
+
@supported_tokens.append(BoldAndItalicToken.new)
|
63
|
+
@supported_tokens.append(BoldToken.new)
|
64
|
+
@supported_tokens.append(ItalicToken.new)
|
65
|
+
@supported_tokens.append(SquareBracketRightAndParentheseLeft.new)
|
66
|
+
@supported_tokens.append(ParentheseLeft.new)
|
67
|
+
@supported_tokens.append(ParentheseRight.new)
|
68
|
+
@supported_tokens.append(SquareBracketLeft.new)
|
69
|
+
@supported_tokens.append(SquareBracketRight.new)
|
70
|
+
@supported_tokens.append(TextLineToken.new)
|
71
|
+
end
|
72
|
+
|
73
|
+
def tokenize(str)
|
74
|
+
result = []
|
75
|
+
sl = str.length
|
76
|
+
si = 0
|
77
|
+
while si < sl
|
78
|
+
@supported_tokens.each do |t|
|
79
|
+
tl = t.value.length
|
80
|
+
if tl != 0 # literal is the last supported token in the list
|
81
|
+
projected_end_position = si + tl - 1
|
82
|
+
next if projected_end_position > sl
|
83
|
+
|
84
|
+
buf = str[si..projected_end_position]
|
85
|
+
if buf == t.value
|
86
|
+
result.append(t)
|
87
|
+
si = projected_end_position + 1
|
88
|
+
break
|
89
|
+
end
|
90
|
+
else
|
91
|
+
if result.length.positive? && (result[-1].instance_of? TextLineToken)
|
92
|
+
literal = result[-1]
|
93
|
+
literal.value += str[si]
|
94
|
+
else
|
95
|
+
literal = TextLineToken.new
|
96
|
+
literal.value = str[si]
|
97
|
+
result.append(literal)
|
98
|
+
end
|
99
|
+
si += 1
|
110
100
|
end
|
111
|
-
|
101
|
+
end
|
112
102
|
end
|
103
|
+
result
|
104
|
+
end
|
113
105
|
end
|
114
106
|
|
115
107
|
class TextLineBuilderContext
|
108
|
+
def italic(str)
|
109
|
+
str
|
110
|
+
end
|
116
111
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
def bold(str)
|
122
|
-
return str
|
123
|
-
end
|
112
|
+
def bold(str)
|
113
|
+
str
|
114
|
+
end
|
124
115
|
|
125
|
-
|
126
|
-
|
127
|
-
|
116
|
+
def bold_and_italic(str)
|
117
|
+
str
|
118
|
+
end
|
128
119
|
|
129
|
-
|
130
|
-
|
131
|
-
|
120
|
+
def link(_link_text, link_url)
|
121
|
+
link_url
|
122
|
+
end
|
132
123
|
end
|
133
124
|
|
134
125
|
class TextLineBuilder
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
126
|
+
attr_accessor :builder_context
|
127
|
+
|
128
|
+
def initialize(builder_context)
|
129
|
+
@builder_context = builder_context
|
130
|
+
end
|
131
|
+
|
132
|
+
def restore(token_list)
|
133
|
+
result = ''
|
134
|
+
return '' if token_list.nil?
|
135
|
+
|
136
|
+
sub_list_url_text = nil
|
137
|
+
sub_list_url_address = nil
|
138
|
+
tl = token_list.length
|
139
|
+
ti = 0
|
140
|
+
while ti < tl
|
141
|
+
case token_list[ti].class.name
|
142
|
+
when 'ItalicToken'
|
143
|
+
is_found = false
|
144
|
+
ti_starting_position = ti
|
145
|
+
# try to find closing part
|
146
|
+
tii = ti + 1
|
147
|
+
while tii < tl
|
148
|
+
if token_list[tii].instance_of? ItalicToken
|
149
|
+
sub_list = token_list[(ti + 1)..(tii - 1)]
|
150
|
+
result += @builder_context.italic(restore(sub_list))
|
151
|
+
ti = tii + 1
|
152
|
+
is_found = true
|
153
|
+
break
|
154
|
+
end
|
155
|
+
tii += 1
|
156
|
+
end
|
157
|
+
unless is_found
|
158
|
+
result += '*'
|
159
|
+
ti = ti_starting_position + 1
|
160
|
+
end
|
161
|
+
when 'BoldToken'
|
162
|
+
is_found = false
|
163
|
+
ti_starting_position = ti
|
164
|
+
# try to find closing part
|
165
|
+
tii = ti + 1
|
166
|
+
while tii < tl
|
167
|
+
if token_list[tii].instance_of? BoldToken
|
168
|
+
sub_list = token_list[(ti + 1)..(tii - 1)]
|
169
|
+
result += @builder_context.bold(restore(sub_list))
|
170
|
+
ti = tii + 1
|
171
|
+
is_found = true
|
172
|
+
break
|
173
|
+
end
|
174
|
+
tii += 1
|
175
|
+
end
|
176
|
+
unless is_found
|
177
|
+
result += '**'
|
178
|
+
ti = ti_starting_position + 1
|
179
|
+
end
|
180
|
+
when 'BoldAndItalicToken'
|
181
|
+
is_found = false
|
182
|
+
ti_starting_position = ti
|
183
|
+
# try to find closing part
|
184
|
+
tii = ti + 1
|
185
|
+
while tii < tl
|
186
|
+
if token_list[tii].instance_of? BoldAndItalicToken
|
187
|
+
sub_list = token_list[(ti + 1)..(tii - 1)]
|
188
|
+
result += @builder_context.bold_and_italic(restore(sub_list))
|
189
|
+
ti = tii + 1
|
190
|
+
is_found = true
|
191
|
+
break
|
192
|
+
end
|
193
|
+
tii += 1
|
145
194
|
end
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
end
|
171
|
-
when "BoldToken"
|
172
|
-
is_found = false
|
173
|
-
ti_starting_position = ti
|
174
|
-
# try to find closing part
|
175
|
-
tii = ti + 1
|
176
|
-
while tii < tl
|
177
|
-
if token_list[tii].instance_of? BoldToken
|
178
|
-
sub_list = token_list[(ti+1)..(tii-1)]
|
179
|
-
result += @builder_context.bold(restore(sub_list))
|
180
|
-
ti = tii +1
|
181
|
-
is_found = true
|
182
|
-
break
|
183
|
-
end
|
184
|
-
tii += 1
|
185
|
-
end
|
186
|
-
unless is_found
|
187
|
-
result += "**"
|
188
|
-
ti = ti_starting_position + 1
|
189
|
-
end
|
190
|
-
when "BoldAndItalicToken"
|
191
|
-
is_found = false
|
192
|
-
ti_starting_position = ti
|
193
|
-
# try to find closing part
|
194
|
-
tii = ti + 1
|
195
|
-
while tii < tl
|
196
|
-
if token_list[tii].instance_of? BoldAndItalicToken
|
197
|
-
sub_list = token_list[(ti+1)..(tii-1)]
|
198
|
-
result += @builder_context.bold_and_italic(restore(sub_list))
|
199
|
-
ti = tii +1
|
200
|
-
is_found = true
|
201
|
-
break
|
202
|
-
end
|
203
|
-
tii += 1
|
204
|
-
end
|
205
|
-
unless is_found
|
206
|
-
result += "***"
|
207
|
-
ti = ti_starting_position + 1
|
208
|
-
end
|
209
|
-
when "SquareBracketLeft"
|
210
|
-
# try to find closing part
|
211
|
-
is_found = false
|
212
|
-
tii = ti + 1
|
213
|
-
ti_starting_position = ti
|
214
|
-
while tii < tl
|
215
|
-
case token_list[tii].class.name
|
216
|
-
when "SquareBracketRightAndParentheseLeft"
|
217
|
-
sub_list_url_text = token_list[(ti+1)..(tii-1)]
|
218
|
-
ti = tii +1
|
219
|
-
tiii = ti
|
220
|
-
while tiii < tl
|
221
|
-
case token_list[tiii].class.name
|
222
|
-
when "ParentheseRight"
|
223
|
-
sub_list_url_address = token_list[(tii+1)..(tiii-1)]
|
224
|
-
ti = tiii +1
|
225
|
-
is_found = true
|
226
|
-
break
|
227
|
-
end
|
228
|
-
tiii += 1
|
229
|
-
end
|
230
|
-
break
|
231
|
-
when "SquareBracketRight"
|
232
|
-
break
|
233
|
-
end
|
234
|
-
tii += 1
|
235
|
-
end
|
236
|
-
if is_found
|
237
|
-
result += @builder_context.link(restore(sub_list_url_text), restore(sub_list_url_address))
|
238
|
-
else
|
239
|
-
result += "["
|
240
|
-
ti = ti_starting_position + 1
|
241
|
-
end
|
242
|
-
|
243
|
-
when "TextLineToken", "ParentheseLeft", "ParentheseRight", "SquareBracketLeft", "SquareBracketRight"
|
244
|
-
result += token_list[ti].value
|
245
|
-
ti += 1
|
246
|
-
else
|
247
|
-
ti += 1
|
195
|
+
unless is_found
|
196
|
+
result += '***'
|
197
|
+
ti = ti_starting_position + 1
|
198
|
+
end
|
199
|
+
when 'SquareBracketLeft'
|
200
|
+
# try to find closing part
|
201
|
+
is_found = false
|
202
|
+
tii = ti + 1
|
203
|
+
ti_starting_position = ti
|
204
|
+
while tii < tl
|
205
|
+
case token_list[tii].class.name
|
206
|
+
when 'SquareBracketRightAndParentheseLeft'
|
207
|
+
sub_list_url_text = token_list[(ti + 1)..(tii - 1)]
|
208
|
+
ti = tii + 1
|
209
|
+
tiii = ti
|
210
|
+
while tiii < tl
|
211
|
+
case token_list[tiii].class.name
|
212
|
+
when 'ParentheseRight'
|
213
|
+
sub_list_url_address = token_list[(tii + 1)..(tiii - 1)]
|
214
|
+
ti = tiii + 1
|
215
|
+
is_found = true
|
216
|
+
break
|
217
|
+
end
|
218
|
+
tiii += 1
|
248
219
|
end
|
220
|
+
break
|
221
|
+
when 'SquareBracketRight'
|
222
|
+
break
|
223
|
+
end
|
224
|
+
tii += 1
|
225
|
+
end
|
226
|
+
if is_found
|
227
|
+
result += @builder_context.link(restore(sub_list_url_text), restore(sub_list_url_address))
|
228
|
+
else
|
229
|
+
result += '['
|
230
|
+
ti = ti_starting_position + 1
|
249
231
|
end
|
250
|
-
|
232
|
+
|
233
|
+
when 'TextLineToken', 'ParentheseLeft', 'ParentheseRight', 'SquareBracketRight'
|
234
|
+
result += token_list[ti].value
|
235
|
+
ti += 1
|
236
|
+
else
|
237
|
+
ti += 1
|
238
|
+
end
|
251
239
|
end
|
240
|
+
result
|
241
|
+
end
|
252
242
|
end
|
253
243
|
|
254
244
|
class TextLine < TextLineBuilderContext
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
245
|
+
@@lazy_doc_id_dict = {}
|
246
|
+
|
247
|
+
def self.add_lazy_doc_id(id)
|
248
|
+
doc_id = id.to_s.downcase
|
249
|
+
@@lazy_doc_id_dict[doc_id] = doc_id
|
250
|
+
end
|
251
|
+
|
252
|
+
def format_string(str)
|
253
|
+
tlp = TextLineParser.new
|
254
|
+
tlb = TextLineBuilder.new(self)
|
255
|
+
tlb.restore(tlp.tokenize(str))
|
256
|
+
end
|
257
|
+
|
258
|
+
def italic(str)
|
259
|
+
"<i>#{str}</i>"
|
260
|
+
end
|
261
|
+
|
262
|
+
def bold(str)
|
263
|
+
"<b>#{str}</b>"
|
264
|
+
end
|
265
|
+
|
266
|
+
def bold_and_italic(str)
|
267
|
+
"<b><i>#{str}</i></b>"
|
268
|
+
end
|
269
|
+
|
270
|
+
def link(link_text, link_url)
|
271
|
+
# define default result first
|
272
|
+
result = "<a target=\"_blank\" rel=\"noopener\" href=\"#{link_url}\" class=\"external\">#{link_text}</a>"
|
273
|
+
|
274
|
+
lazy_doc_id = nil
|
275
|
+
anchor = nil
|
276
|
+
|
277
|
+
if res = /(\w+)[.]md$/.match(link_url) # link
|
278
|
+
lazy_doc_id = res[1].to_s.downcase
|
279
|
+
|
280
|
+
elsif res = /(\w*)[.]md(#.*)$/.match(link_url) # link with anchor
|
281
|
+
if res && res.length > 2
|
282
|
+
lazy_doc_id = res[1]
|
283
|
+
anchor = res[2]
|
284
|
+
end
|
284
285
|
end
|
285
286
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
if res = /(\w+)[.]md$/.match(link_url) #link
|
293
|
-
lazy_doc_id = res[1].to_s.downcase
|
294
|
-
|
295
|
-
elsif res = /(\w*)[.]md(#.*)$/.match(link_url) # link with anchor
|
296
|
-
if res && res.length > 2
|
297
|
-
lazy_doc_id = res[1]
|
298
|
-
anchor = res[2]
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
if lazy_doc_id
|
303
|
-
if @@lazy_doc_id_dict.has_key?(lazy_doc_id)
|
304
|
-
if anchor
|
305
|
-
result = "<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html#{anchor}\" class=\"external\">#{link_text}</a>"
|
306
|
-
else
|
307
|
-
result = "<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html\" class=\"external\">#{link_text}</a>"
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|
311
|
-
return result
|
287
|
+
if lazy_doc_id && @@lazy_doc_id_dict.key?(lazy_doc_id)
|
288
|
+
result = if anchor
|
289
|
+
"<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html#{anchor}\" class=\"external\">#{link_text}</a>"
|
290
|
+
else
|
291
|
+
"<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html\" class=\"external\">#{link_text}</a>"
|
292
|
+
end
|
312
293
|
end
|
313
|
-
|
294
|
+
result
|
295
|
+
end
|
296
|
+
end
|
@@ -11,9 +11,9 @@ class TodoBlock < DocItem
|
|
11
11
|
def to_html
|
12
12
|
s = ''
|
13
13
|
f_text = format_string(@text)
|
14
|
-
if @@
|
14
|
+
if @@html_table_render_in_progress
|
15
15
|
s += "</table>\n"
|
16
|
-
@@
|
16
|
+
@@html_table_render_in_progress = false
|
17
17
|
end
|
18
18
|
|
19
19
|
s += "<div class=\"todoblock\"><p>#{f_text}</div>\n"
|