Almirah 0.2.5 → 0.2.7

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/bin/almirah +4 -4
  3. data/lib/almirah/doc_fabric.rb +65 -65
  4. data/lib/almirah/doc_items/blockquote.rb +21 -21
  5. data/lib/almirah/doc_items/code_block.rb +26 -26
  6. data/lib/almirah/doc_items/controlled_paragraph.rb +112 -112
  7. data/lib/almirah/doc_items/controlled_table.rb +224 -224
  8. data/lib/almirah/doc_items/controlled_table_row.rb +22 -22
  9. data/lib/almirah/doc_items/doc_footer.rb +16 -16
  10. data/lib/almirah/doc_items/doc_item.rb +22 -22
  11. data/lib/almirah/doc_items/frontmatter.rb +9 -9
  12. data/lib/almirah/doc_items/heading.rb +93 -93
  13. data/lib/almirah/doc_items/image.rb +27 -27
  14. data/lib/almirah/doc_items/markdown_list.rb +156 -156
  15. data/lib/almirah/doc_items/markdown_table.rb +97 -61
  16. data/lib/almirah/doc_items/paragraph.rb +25 -25
  17. data/lib/almirah/doc_items/text_line.rb +296 -296
  18. data/lib/almirah/doc_items/todo_block.rb +21 -21
  19. data/lib/almirah/doc_parser.rb +379 -378
  20. data/lib/almirah/doc_types/base_document.rb +64 -64
  21. data/lib/almirah/doc_types/coverage.rb +95 -80
  22. data/lib/almirah/doc_types/index.rb +173 -173
  23. data/lib/almirah/doc_types/persistent_document.rb +17 -17
  24. data/lib/almirah/doc_types/protocol.rb +24 -24
  25. data/lib/almirah/doc_types/specification.rb +67 -67
  26. data/lib/almirah/doc_types/traceability.rb +142 -142
  27. data/lib/almirah/dom/doc_section.rb +25 -25
  28. data/lib/almirah/dom/document.rb +78 -78
  29. data/lib/almirah/navigation_pane.rb +16 -16
  30. data/lib/almirah/project.rb +287 -287
  31. data/lib/almirah/project_configuration.rb +41 -41
  32. data/lib/almirah/project_template.rb +298 -298
  33. data/lib/almirah/project_utility.rb +52 -0
  34. data/lib/almirah/search/specifications_db.rb +79 -79
  35. data/lib/almirah/templates/css/main.css +300 -300
  36. data/lib/almirah/templates/css/search.css +40 -40
  37. data/lib/almirah/templates/page.html +42 -42
  38. data/lib/almirah/templates/scripts/main.js +111 -111
  39. data/lib/almirah/templates/scripts/orama_search.js +138 -138
  40. data/lib/almirah.rb +93 -58
  41. metadata +4 -3
@@ -1,93 +1,93 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'paragraph'
4
-
5
- class Heading < Paragraph
6
- attr_accessor :level, :anchor_id, :section_number
7
-
8
- @@global_section_number = ''
9
-
10
- def initialize(doc, text, level)
11
- super(doc, text)
12
- @level = level
13
-
14
- if level != 0 # skip Doc Title
15
- if @@global_section_number == ''
16
- @@global_section_number = '1'
17
- (1..(level - 1)).each do |_n|
18
- @@global_section_number += '.1'
19
- end
20
- else
21
- previous_level = @@global_section_number.split('.').length
22
-
23
- if previous_level == level
24
-
25
- a = @@global_section_number.split('.')
26
- a[-1] = (a[-1].to_i + 1).to_s
27
- @@global_section_number = a.join('.')
28
-
29
- elsif level > previous_level
30
-
31
- a = @@global_section_number.split('.')
32
- a.push('1')
33
- @@global_section_number = a.join('.')
34
-
35
- else # level < previous_level
36
-
37
- a = @@global_section_number.split('.')
38
- delta = previous_level - level
39
- a.pop(delta)
40
- @@global_section_number = a.join('.')
41
- # increment
42
- a = @@global_section_number.split('.')
43
- a[-1] = (a[-1].to_i + 1).to_s
44
- @@global_section_number = a.join('.')
45
- end
46
- end
47
- end
48
- @section_number = @@global_section_number
49
- @anchor_id = get_anchor_text
50
- end
51
-
52
- def get_section_info
53
- if level.zero? # Doc Title
54
- @text
55
- else
56
- "#{@section_number} #{@text}"
57
- end
58
- end
59
-
60
- def get_anchor_text
61
- "#{@section_number}-#{getTextWithoutSpaces}"
62
- end
63
-
64
- def get_markdown_anchor_text
65
- getTextWithoutSpaces
66
- end
67
-
68
- def to_html
69
- s = ''
70
- if @@html_table_render_in_progress
71
- s += "</table>\n"
72
- @@html_table_render_in_progress = false
73
- end
74
- heading_level = level.to_s
75
- heading_text = get_section_info
76
- if level.zero?
77
- heading_level = 1.to_s # Render Doc Title as a regular h1
78
- heading_text = @text # Doc Title does not have a section number
79
- end
80
- s += "<a name=\"#{@anchor_id}\"></a>\n"
81
- s += "<h#{heading_level}> #{heading_text} <a href=\"\##{@anchor_id}\" class=\"heading_anchor\">"
82
- s += "&para;</a></h#{heading_level}>"
83
- s
84
- end
85
-
86
- def get_url
87
- "./specifications/#{parent_doc.id}/#{parent_doc.id}.html\##{@anchor_id}"
88
- end
89
-
90
- def self.reset_global_section_number
91
- @@global_section_number = ''
92
- end
93
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'paragraph'
4
+
5
+ class Heading < Paragraph
6
+ attr_accessor :level, :anchor_id, :section_number
7
+
8
+ @@global_section_number = ''
9
+
10
+ def initialize(doc, text, level)
11
+ super(doc, text)
12
+ @level = level
13
+
14
+ if level != 0 # skip Doc Title
15
+ if @@global_section_number == ''
16
+ @@global_section_number = '1'
17
+ (1..(level - 1)).each do |_n|
18
+ @@global_section_number += '.1'
19
+ end
20
+ else
21
+ previous_level = @@global_section_number.split('.').length
22
+
23
+ if previous_level == level
24
+
25
+ a = @@global_section_number.split('.')
26
+ a[-1] = (a[-1].to_i + 1).to_s
27
+ @@global_section_number = a.join('.')
28
+
29
+ elsif level > previous_level
30
+
31
+ a = @@global_section_number.split('.')
32
+ a.push('1')
33
+ @@global_section_number = a.join('.')
34
+
35
+ else # level < previous_level
36
+
37
+ a = @@global_section_number.split('.')
38
+ delta = previous_level - level
39
+ a.pop(delta)
40
+ @@global_section_number = a.join('.')
41
+ # increment
42
+ a = @@global_section_number.split('.')
43
+ a[-1] = (a[-1].to_i + 1).to_s
44
+ @@global_section_number = a.join('.')
45
+ end
46
+ end
47
+ end
48
+ @section_number = @@global_section_number
49
+ @anchor_id = get_anchor_text
50
+ end
51
+
52
+ def get_section_info
53
+ if level.zero? # Doc Title
54
+ @text
55
+ else
56
+ "#{@section_number} #{@text}"
57
+ end
58
+ end
59
+
60
+ def get_anchor_text
61
+ "#{@section_number}-#{getTextWithoutSpaces}"
62
+ end
63
+
64
+ def get_markdown_anchor_text
65
+ getTextWithoutSpaces
66
+ end
67
+
68
+ def to_html
69
+ s = ''
70
+ if @@html_table_render_in_progress
71
+ s += "</table>\n"
72
+ @@html_table_render_in_progress = false
73
+ end
74
+ heading_level = level.to_s
75
+ heading_text = get_section_info
76
+ if level.zero?
77
+ heading_level = 1.to_s # Render Doc Title as a regular h1
78
+ heading_text = @text # Doc Title does not have a section number
79
+ end
80
+ s += "<a name=\"#{@anchor_id}\"></a>\n"
81
+ s += "<h#{heading_level}> #{heading_text} <a href=\"\##{@anchor_id}\" class=\"heading_anchor\">"
82
+ s += "&para;</a></h#{heading_level}>"
83
+ s
84
+ end
85
+
86
+ def get_url
87
+ "./specifications/#{parent_doc.id}/#{parent_doc.id}.html\##{@anchor_id}"
88
+ end
89
+
90
+ def self.reset_global_section_number
91
+ @@global_section_number = ''
92
+ end
93
+ end
@@ -1,28 +1,28 @@
1
- require_relative "doc_item"
2
-
3
- class Image < DocItem
4
-
5
- attr_accessor :text
6
- attr_accessor :path
7
-
8
- def initialize(text, path)
9
- @text = text
10
- @path = path
11
- end
12
-
13
- def getTextWithoutSpaces
14
- return @text.split.join('-')
15
- end
16
-
17
- def to_html
18
- s = ''
19
- if @@html_table_render_in_progress
20
- s += "</table>\n"
21
- @@html_table_render_in_progress = false
22
- end
23
-
24
- s += "<p style=\"margin-top: 15px;\"><img src=\"#{@path}\" alt=\"#{@text}\" "
25
- s += "href=\"javascript:void(0)\" onclick=\"image_OnClick(this)\">"
26
- return s
27
- end
1
+ require_relative "doc_item"
2
+
3
+ class Image < DocItem
4
+
5
+ attr_accessor :text
6
+ attr_accessor :path
7
+
8
+ def initialize(text, path)
9
+ @text = text
10
+ @path = path
11
+ end
12
+
13
+ def getTextWithoutSpaces
14
+ return @text.split.join('-')
15
+ end
16
+
17
+ def to_html
18
+ s = ''
19
+ if @@html_table_render_in_progress
20
+ s += "</table>\n"
21
+ @@html_table_render_in_progress = false
22
+ end
23
+
24
+ s += "<p style=\"margin-top: 15px;\"><img src=\"#{@path}\" alt=\"#{@text}\" "
25
+ s += "href=\"javascript:void(0)\" onclick=\"image_OnClick(this)\">"
26
+ return s
27
+ end
28
28
  end
@@ -1,156 +1,156 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'doc_item'
4
-
5
- class MarkdownList < DocItem
6
- attr_accessor :rows, :text, :is_ordered, :indent_position, :current_nesting_level
7
-
8
- @@lists_stack = []
9
-
10
- def initialize(doc, is_ordered)
11
- super(doc)
12
-
13
- @rows = []
14
- @is_ordered = is_ordered
15
- @current_nesting_level = 0
16
- @indent_position = 0
17
- @text = ''
18
-
19
- @@lists_stack.push(self)
20
- end
21
-
22
- def add_row(raw_text)
23
- pos = calculate_text_position(raw_text)
24
- row = raw_text[pos..-1]
25
-
26
- pos = calculate_indent_position(raw_text)
27
-
28
- if pos > @@lists_stack[-1].indent_position
29
-
30
- prev_lists_stack_item = @@lists_stack[-1]
31
- # the following line pushes new list to the lists_stack in the constructor!
32
- nested_list = MarkdownList.new(@parent_doc, MarkdownList.ordered_list_item?(raw_text))
33
- nested_list.current_nesting_level = @current_nesting_level + 1
34
- nested_list.indent_position = pos
35
-
36
- prev_row = prev_lists_stack_item.rows[-1]
37
- if prev_row.is_a?(MarkdownList)
38
- # cannot be there
39
- else
40
- nested_list.text = prev_row
41
- # puts "Length: " + prev_lists_stack_item.rows.length.to_s
42
- prev_lists_stack_item.rows[-1] = nested_list
43
- end
44
-
45
- nested_list.add_row(raw_text)
46
-
47
- elsif pos < @@lists_stack[-1].indent_position
48
-
49
- @@lists_stack.pop while pos < @@lists_stack[-1].indent_position
50
- @@lists_stack[-1].rows.append(row)
51
-
52
- else
53
- @@lists_stack[-1].rows.append(row)
54
-
55
- end
56
- end
57
-
58
- def calculate_indent_position(s)
59
- s.downcase
60
- pos = 0
61
- s.each_char do |c|
62
- break if c != ' ' && c != '\t'
63
-
64
- pos += 1
65
- end
66
- pos
67
- end
68
-
69
- def calculate_text_position(s)
70
- s.downcase
71
- pos = 0
72
- state = 'looking_for_list_item_marker'
73
- s.each_char do |c|
74
- case state
75
- when 'looking_for_list_item_marker'
76
- if c == '*'
77
- state = 'looking_for_space'
78
- elsif numeric?(c)
79
- state = 'looking_for_dot'
80
- end
81
- when 'looking_for_dot'
82
- state = 'looking_for_space' if c == '.'
83
- when 'looking_for_space'
84
- state = 'looking_for_non_space' if [' ', '\t'].include?(c)
85
- when 'looking_for_non_space'
86
- if c != ' ' || c != '\t'
87
- state = 'list_item_text_pos_found'
88
- break
89
- end
90
- end
91
- pos += 1
92
- end
93
- pos
94
- end
95
-
96
- def letter?(c)
97
- c.match?(/[[:alpha:]]/)
98
- end
99
-
100
- def numeric?(c)
101
- c.match?(/[[:digit:]]/)
102
- end
103
-
104
- def non_blank?(c)
105
- c.match?(/[[:graph:]]/)
106
- end
107
-
108
- def self.unordered_list_item?(raw_text)
109
- res = /(\*\s?)(.*)/.match(raw_text)
110
- return true if res
111
-
112
- false
113
- end
114
-
115
- def self.ordered_list_item?(raw_text)
116
- res = /\d[.]\s(.*)/.match(raw_text)
117
- return true if res
118
-
119
- false
120
- end
121
-
122
- def to_html
123
- s = ''
124
- if @@html_table_render_in_progress
125
- s += "</table>\n"
126
- @@html_table_render_in_progress = false
127
- end
128
-
129
- s += if @is_ordered
130
- "<ol>\n"
131
- else
132
- "<ul>\n"
133
- end
134
-
135
- @rows.each do |r|
136
- if r.is_a?(MarkdownList)
137
- f_text = format_string(r.text)
138
- s += "\t<li>#{f_text}\n"
139
- s += r.to_html
140
- s += "</li>\n"
141
- else
142
- f_text = format_string(r)
143
- # puts f_text
144
- s += "\t<li>#{f_text}</li>\n"
145
- end
146
- end
147
-
148
- s += if @is_ordered
149
- "</ol>\n"
150
- else
151
- "</ul>\n"
152
- end
153
-
154
- s
155
- end
156
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'doc_item'
4
+
5
+ class MarkdownList < DocItem
6
+ attr_accessor :rows, :text, :is_ordered, :indent_position, :current_nesting_level
7
+
8
+ @@lists_stack = []
9
+
10
+ def initialize(doc, is_ordered)
11
+ super(doc)
12
+
13
+ @rows = []
14
+ @is_ordered = is_ordered
15
+ @current_nesting_level = 0
16
+ @indent_position = 0
17
+ @text = ''
18
+
19
+ @@lists_stack.push(self)
20
+ end
21
+
22
+ def add_row(raw_text)
23
+ pos = calculate_text_position(raw_text)
24
+ row = raw_text[pos..-1]
25
+
26
+ pos = calculate_indent_position(raw_text)
27
+
28
+ if pos > @@lists_stack[-1].indent_position
29
+
30
+ prev_lists_stack_item = @@lists_stack[-1]
31
+ # the following line pushes new list to the lists_stack in the constructor!
32
+ nested_list = MarkdownList.new(@parent_doc, MarkdownList.ordered_list_item?(raw_text))
33
+ nested_list.current_nesting_level = @current_nesting_level + 1
34
+ nested_list.indent_position = pos
35
+
36
+ prev_row = prev_lists_stack_item.rows[-1]
37
+ if prev_row.is_a?(MarkdownList)
38
+ # cannot be there
39
+ else
40
+ nested_list.text = prev_row
41
+ # puts "Length: " + prev_lists_stack_item.rows.length.to_s
42
+ prev_lists_stack_item.rows[-1] = nested_list
43
+ end
44
+
45
+ nested_list.add_row(raw_text)
46
+
47
+ elsif pos < @@lists_stack[-1].indent_position
48
+
49
+ @@lists_stack.pop while pos < @@lists_stack[-1].indent_position
50
+ @@lists_stack[-1].rows.append(row)
51
+
52
+ else
53
+ @@lists_stack[-1].rows.append(row)
54
+
55
+ end
56
+ end
57
+
58
+ def calculate_indent_position(s)
59
+ s.downcase
60
+ pos = 0
61
+ s.each_char do |c|
62
+ break if c != ' ' && c != '\t'
63
+
64
+ pos += 1
65
+ end
66
+ pos
67
+ end
68
+
69
+ def calculate_text_position(s)
70
+ s.downcase
71
+ pos = 0
72
+ state = 'looking_for_list_item_marker'
73
+ s.each_char do |c|
74
+ case state
75
+ when 'looking_for_list_item_marker'
76
+ if c == '*'
77
+ state = 'looking_for_space'
78
+ elsif numeric?(c)
79
+ state = 'looking_for_dot'
80
+ end
81
+ when 'looking_for_dot'
82
+ state = 'looking_for_space' if c == '.'
83
+ when 'looking_for_space'
84
+ state = 'looking_for_non_space' if [' ', '\t'].include?(c)
85
+ when 'looking_for_non_space'
86
+ if c != ' ' || c != '\t'
87
+ state = 'list_item_text_pos_found'
88
+ break
89
+ end
90
+ end
91
+ pos += 1
92
+ end
93
+ pos
94
+ end
95
+
96
+ def letter?(c)
97
+ c.match?(/[[:alpha:]]/)
98
+ end
99
+
100
+ def numeric?(c)
101
+ c.match?(/[[:digit:]]/)
102
+ end
103
+
104
+ def non_blank?(c)
105
+ c.match?(/[[:graph:]]/)
106
+ end
107
+
108
+ def self.unordered_list_item?(raw_text)
109
+ res = /(\*\s?)(.*)/.match(raw_text)
110
+ return true if res
111
+
112
+ false
113
+ end
114
+
115
+ def self.ordered_list_item?(raw_text)
116
+ res = /\d[.]\s(.*)/.match(raw_text)
117
+ return true if res
118
+
119
+ false
120
+ end
121
+
122
+ def to_html
123
+ s = ''
124
+ if @@html_table_render_in_progress
125
+ s += "</table>\n"
126
+ @@html_table_render_in_progress = false
127
+ end
128
+
129
+ s += if @is_ordered
130
+ "<ol>\n"
131
+ else
132
+ "<ul>\n"
133
+ end
134
+
135
+ @rows.each do |r|
136
+ if r.is_a?(MarkdownList)
137
+ f_text = format_string(r.text)
138
+ s += "\t<li>#{f_text}\n"
139
+ s += r.to_html
140
+ s += "</li>\n"
141
+ else
142
+ f_text = format_string(r)
143
+ # puts f_text
144
+ s += "\t<li>#{f_text}</li>\n"
145
+ end
146
+ end
147
+
148
+ s += if @is_ordered
149
+ "</ol>\n"
150
+ else
151
+ "</ul>\n"
152
+ end
153
+
154
+ s
155
+ end
156
+ end