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.
@@ -1,194 +0,0 @@
1
- require_relative "doc_items/doc_item"
2
- require_relative "doc_items/heading"
3
- require_relative "doc_items/paragraph"
4
- require_relative "doc_items/blockquote"
5
- require_relative "doc_items/controlled_paragraph"
6
- require_relative "doc_items/markdown_table"
7
- require_relative "doc_items/image"
8
- require_relative "doc_items/markdown_list"
9
-
10
- class Specification
11
-
12
- attr_accessor :path
13
- attr_accessor :docItems
14
- attr_accessor :headings
15
- attr_accessor :title
16
- attr_accessor :key
17
- attr_accessor :up_link_key
18
- attr_accessor :dictionary
19
- attr_accessor :controlledParagraphs
20
- attr_accessor :tempMdTable
21
- attr_accessor :tempMdList
22
-
23
- def initialize(fele_path)
24
-
25
- @path = fele_path
26
- @title = ""
27
- @docItems = Array.new
28
- @headings = Array.new
29
- @controlledParagraphs = Array.new
30
- @dictionary = Hash.new
31
- @tempMdTable = nil
32
- @tempMdList = nil
33
-
34
- @key = File.basename(fele_path, File.extname(fele_path)).upcase
35
- @up_link_key = ""
36
-
37
- self.parse()
38
- end
39
-
40
- def parse()
41
-
42
- file = File.open( self.path )
43
- file_lines = file.readlines
44
- file.close
45
-
46
- file_lines.each do |s|
47
- if s.lstrip != ""
48
- if res = /^([#]{1,})\s(.*)/.match(s) # Heading
49
-
50
- if @tempMdTable
51
- self.docItems.append(@tempMdTable)
52
- @tempMdTable = nil
53
- end
54
- if @tempMdList
55
- self.docItems.append(@tempMdList)
56
- @tempMdList = nil
57
- end
58
-
59
- level = res[1].length
60
- value = res[2]
61
- item = Heading.new(value, level)
62
- self.docItems.append(item)
63
- self.headings.append(item)
64
-
65
- if level == 1 && self.title == ""
66
- self.title = value
67
- end
68
-
69
- elsif res = /^\[(\S*)\]\s+(.*)/.match(s) # Controlled Paragraph
70
-
71
- if @tempMdTable
72
- self.docItems.append(@tempMdTable)
73
- @tempMdTable = nil
74
- end
75
- if @tempMdList
76
- self.docItems.append(@tempMdList)
77
- @tempMdList = nil
78
- end
79
-
80
- id = res[1]
81
- text = res[2]
82
-
83
- #check if it contains the uplink
84
- if tmp = /(.*)\s+>\[(\S*)\]$/.match(text)
85
-
86
- text = tmp[1]
87
- up_link = tmp[2]
88
-
89
- if tmp = /^([a-zA-Z]+)[-]\d+/.match(up_link)
90
- self.up_link_key = tmp[1]
91
- end
92
- end
93
-
94
- item = ControlledParagraph.new( text, id )
95
- item.up_link = up_link
96
-
97
- self.docItems.append(item)
98
- self.dictionary[ id.to_s ] = item #for fast search
99
- self.controlledParagraphs.append(item) #for fast search
100
-
101
- elsif res = /^[!]\[(.*)\]\((.*)\)/.match(s) # Image
102
-
103
- if @tempMdTable
104
- self.docItems.append(@tempMdTable)
105
- @tempMdTable = nil
106
- end
107
- if @tempMdList
108
- self.docItems.append(@tempMdList)
109
- @tempMdList = nil
110
- end
111
-
112
- img_text = res[1]
113
- img_path = res[2]
114
-
115
- item = Image.new( img_text, img_path )
116
-
117
- self.docItems.append(item)
118
-
119
- elsif res = /^(\*\s?)+(.*)/.match(s) #check if bullet list
120
-
121
- if @tempMdTable
122
- self.docItems.append(@tempMdTable)
123
- @tempMdTable = nil
124
- end
125
-
126
- row = res[2]
127
-
128
- if @tempMdList
129
- @tempMdList.addRow(row)
130
- else
131
- item = MarkdownList.new(row)
132
- @tempMdList = item
133
- end
134
-
135
- elsif s[0] == '|' #check if table
136
-
137
- if @tempMdList
138
- self.docItems.append(@tempMdList)
139
- @tempMdList = nil
140
- end
141
-
142
- if res = /^[|](-{3,})[|]/.match(s) #check if it is a separator first
143
-
144
- if @tempMdTable
145
- #separator is found after heading - just skip it
146
- else
147
- #separator out of table scope consider it just as a regular paragraph
148
- item = Paragraph.new(s)
149
- self.docItems.append(item)
150
- end
151
-
152
- elsif res = /^[|](.*[|])/.match(s) #check if it looks as a table
153
-
154
- row = res[1]
155
-
156
- if @tempMdTable
157
- @tempMdTable.addRow(row)
158
- else
159
- #start table from heading
160
- @tempMdTable = MarkdownTable.new(row)
161
- end
162
- end
163
-
164
- elsif res = /^[>](.*)/.match(s) #check if blockquote
165
-
166
- if @tempMdTable
167
- self.docItems.append(@tempMdTable)
168
- @tempMdTable = nil
169
- end
170
- if @tempMdList
171
- self.docItems.append(@tempMdList)
172
- @tempMdList = nil
173
- end
174
-
175
- item = Blockquote.new(res[1])
176
- self.docItems.append(item)
177
-
178
- else # Reqular Paragraph
179
- if @tempMdTable
180
- self.docItems.append(@tempMdTable)
181
- @tempMdTable = nil
182
- end
183
- if @tempMdList
184
- self.docItems.append(@tempMdList)
185
- @tempMdList = nil
186
- end
187
-
188
- item = Paragraph.new(s)
189
- self.docItems.append(item)
190
- end
191
- end
192
- end
193
- end
194
- end