Almirah 0.0.1 → 0.0.3
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/bin/almirah +5 -0
- data/lib/almirah/doc_items/blockquote.rb +21 -0
- data/lib/almirah/doc_items/controlled_paragraph.rb +52 -0
- data/lib/almirah/doc_items/doc_item.rb +8 -0
- data/lib/almirah/doc_items/heading.rb +25 -0
- data/lib/almirah/doc_items/markdown_table.rb +47 -0
- data/lib/almirah/doc_items/paragraph.rb +25 -0
- data/lib/almirah/html_render.rb +53 -0
- data/lib/almirah/linker.rb +42 -0
- data/lib/almirah/specification.rb +131 -0
- data/lib/almirah/templates/page.html +9 -0
- data/lib/almirah.rb +44 -3
- metadata +15 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fb9468eb0f2bd41ef114392ac41e3954da577bcbf008b0e1302d0436cd1222c
|
4
|
+
data.tar.gz: fe5652461a3f368c77df81bbffafa4c127168bd3eb3af4c2f0c181c50e23a59e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b8ecdb79e738a58f1a8992735adbb7fe07f883f587f2d4b8314083bfdc2d750b31217738886c8c4abbba02b672e819d01257dd0fb6c70febe0bfe15e6912760
|
7
|
+
data.tar.gz: bca5f63cab9daa24e21dbaaf1af7e3f9fa0297b60a9ea1a31bf5ebc38f5306290810ade574df8bd3979cc4df21d32bdfe1a4478813f3a016e7d4a51995f4e827
|
data/bin/almirah
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "doc_item"
|
2
|
+
|
3
|
+
class Blockquote < DocItem
|
4
|
+
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
def initialize(text)
|
8
|
+
@text = text
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_html
|
12
|
+
s = ''
|
13
|
+
if @@htmlTableRenderInProgress
|
14
|
+
s += "</table>"
|
15
|
+
@@htmlTableRenderInProgress = false
|
16
|
+
end
|
17
|
+
|
18
|
+
s += "<p>Note: #{@text}\n\r"
|
19
|
+
return s
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative "paragraph"
|
2
|
+
|
3
|
+
class ControlledParagraph < Paragraph
|
4
|
+
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :up_link
|
7
|
+
attr_accessor :down_links
|
8
|
+
|
9
|
+
def initialize(text, id)
|
10
|
+
@text = text
|
11
|
+
@id = id
|
12
|
+
@up_link = nil
|
13
|
+
@down_links = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_html
|
17
|
+
s = ''
|
18
|
+
unless @@htmlTableRenderInProgress
|
19
|
+
s += "<table>\n\r"
|
20
|
+
s += "\t<thead> <th>#</th> <th>Text</th> <th>UL</th> <th>DL</th> <th>COV</th> </thead>\n\r"
|
21
|
+
@@htmlTableRenderInProgress = true
|
22
|
+
end
|
23
|
+
s += "\t<tr>\n\r"
|
24
|
+
s += "\t\t<td> <a name=\"#{@id}\"></a>#{@id} </td>\n\r"
|
25
|
+
s += "\t\t<td>#{@text}</td>\n\r"
|
26
|
+
|
27
|
+
if @up_link
|
28
|
+
if tmp = /^([a-zA-Z]+)[-]\d+/.match(@up_link)
|
29
|
+
up_link_doc_name = tmp[1].downcase
|
30
|
+
end
|
31
|
+
s += "\t\t<td><a href=\"./../#{up_link_doc_name}/#{up_link_doc_name}.html\" class=\"external\">#{@up_link}</a></td>\n\r"
|
32
|
+
else
|
33
|
+
s += "\t\t<td></td>\n\r"
|
34
|
+
end
|
35
|
+
|
36
|
+
if @down_links
|
37
|
+
if tmp = /^([a-zA-Z]+)[-]\d+/.match(@down_links[0].id) # guessing that all the links refer to one document
|
38
|
+
down_link_doc_name = tmp[1].downcase
|
39
|
+
end
|
40
|
+
s += "\t\t<td><a href=\"./../#{down_link_doc_name}/#{down_link_doc_name}.html\" class=\"external\">#{@down_links.length}</a></td>\n\r"
|
41
|
+
else
|
42
|
+
s += "\t\t<td></td>\n\r"
|
43
|
+
end
|
44
|
+
|
45
|
+
#s += "\t\t<td></td>\n\r" # UL
|
46
|
+
#s += "\t\t<td></td>\n\r" # DL
|
47
|
+
s += "\t\t<td></td>\n\r" # COV
|
48
|
+
s += "\t</tr>\n\r"
|
49
|
+
return s
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "paragraph"
|
2
|
+
|
3
|
+
class Heading < Paragraph
|
4
|
+
|
5
|
+
attr_accessor :level
|
6
|
+
|
7
|
+
def initialize(text, level)
|
8
|
+
@text = text
|
9
|
+
@level = level
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_html
|
13
|
+
s = ''
|
14
|
+
if @@htmlTableRenderInProgress
|
15
|
+
s += "</table>"
|
16
|
+
@@htmlTableRenderInProgress = false
|
17
|
+
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}\">"
|
22
|
+
s += "¶</a></h#{headingLevel}>"
|
23
|
+
return s
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative "doc_item"
|
2
|
+
|
3
|
+
class MarkdownTable < DocItem
|
4
|
+
|
5
|
+
attr_accessor :column_names
|
6
|
+
attr_accessor :rows
|
7
|
+
|
8
|
+
def initialize(heading_row)
|
9
|
+
@column_names = heading_row.split('|')
|
10
|
+
@rows = Array.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def addRow(row)
|
14
|
+
columns = row.split('|')
|
15
|
+
@rows.append(columns)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_html
|
19
|
+
s = ''
|
20
|
+
if @@htmlTableRenderInProgress
|
21
|
+
s += "</table>"
|
22
|
+
@@htmlTableRenderInProgress = false
|
23
|
+
end
|
24
|
+
|
25
|
+
s += "<table>\n\r"
|
26
|
+
s += "\t<thead>"
|
27
|
+
|
28
|
+
@column_names.each do |h|
|
29
|
+
s += " <th>#{h}</th>"
|
30
|
+
end
|
31
|
+
|
32
|
+
s += " </thead>\n\r"
|
33
|
+
|
34
|
+
@rows.each do |row|
|
35
|
+
s += "\t<tr>\n\r"
|
36
|
+
row.each do |col|
|
37
|
+
s += "\t\t<td>#{col}</td>\n\r"
|
38
|
+
end
|
39
|
+
s += "\t</tr>\n\r"
|
40
|
+
end
|
41
|
+
|
42
|
+
s += "</table>\n\r"
|
43
|
+
|
44
|
+
return s
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "doc_item"
|
2
|
+
|
3
|
+
class Paragraph < DocItem
|
4
|
+
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
def initialize(text)
|
8
|
+
@text = text
|
9
|
+
end
|
10
|
+
|
11
|
+
def getTextWithoutSpaces
|
12
|
+
return @text.split.join('-')
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_html
|
16
|
+
s = ''
|
17
|
+
if @@htmlTableRenderInProgress
|
18
|
+
s += "</table>"
|
19
|
+
@@htmlTableRenderInProgress = false
|
20
|
+
end
|
21
|
+
|
22
|
+
s += "<p>#{@text}"
|
23
|
+
return s
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative "specification"
|
2
|
+
require_relative "doc_items/doc_item"
|
3
|
+
require_relative "doc_items/heading"
|
4
|
+
require_relative "doc_items/paragraph"
|
5
|
+
require_relative "doc_items/controlled_paragraph"
|
6
|
+
|
7
|
+
class HtmlRender
|
8
|
+
|
9
|
+
attr_accessor :template
|
10
|
+
attr_accessor :htmlRows
|
11
|
+
attr_accessor :outputFile
|
12
|
+
attr_accessor :document
|
13
|
+
|
14
|
+
def initialize(document, template, outputFile)
|
15
|
+
|
16
|
+
@template = template
|
17
|
+
@outputFile = outputFile
|
18
|
+
@htmlRows = Array.new
|
19
|
+
@document = document
|
20
|
+
|
21
|
+
self.render()
|
22
|
+
self.saveRenderToFile()
|
23
|
+
end
|
24
|
+
|
25
|
+
def render()
|
26
|
+
self.htmlRows.append('')
|
27
|
+
|
28
|
+
self.document.docItems.each do |item|
|
29
|
+
a = item.to_html
|
30
|
+
self.htmlRows.append a
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def saveRenderToFile()
|
35
|
+
|
36
|
+
file = File.open( self.template )
|
37
|
+
file_data = file.readlines
|
38
|
+
file.close
|
39
|
+
|
40
|
+
file = File.open( self.outputFile, "w" )
|
41
|
+
file_data.each do |s|
|
42
|
+
if s.include?('{{CONTENT}}')
|
43
|
+
self.htmlRows.each do |r|
|
44
|
+
file.puts r
|
45
|
+
end
|
46
|
+
else
|
47
|
+
file.puts s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
file.close
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative "doc_items/doc_item"
|
2
|
+
require_relative "specification"
|
3
|
+
|
4
|
+
class Linker
|
5
|
+
|
6
|
+
attr_accessor :field
|
7
|
+
|
8
|
+
def initialize()
|
9
|
+
@field = "field"
|
10
|
+
end
|
11
|
+
|
12
|
+
def link(doc_A, doc_B)
|
13
|
+
|
14
|
+
if doc_A.key == doc_B.up_link_key
|
15
|
+
top_document = doc_A
|
16
|
+
bottom_document = doc_B
|
17
|
+
elsif doc_B.key == doc_A.up_link_key
|
18
|
+
top_document = doc_B
|
19
|
+
bottom_document = doc_A
|
20
|
+
else
|
21
|
+
puts "No Links"
|
22
|
+
return # no links
|
23
|
+
end
|
24
|
+
|
25
|
+
bottom_document.controlledParagraphs.each do |item|
|
26
|
+
|
27
|
+
if top_document.dictionary.has_key?(item.up_link.to_s)
|
28
|
+
|
29
|
+
topItem = top_document.dictionary[item.up_link.to_s]
|
30
|
+
|
31
|
+
unless topItem.down_links
|
32
|
+
topItem.down_links = Array.new
|
33
|
+
end
|
34
|
+
topItem.down_links.append(item)
|
35
|
+
|
36
|
+
#if tmp = /^([a-zA-Z]+)[-]\d+/.match(item.id)
|
37
|
+
# top_document.downlinkKey = tmp[1].upcase
|
38
|
+
#end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,131 @@
|
|
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
|
+
|
8
|
+
class Specification
|
9
|
+
|
10
|
+
attr_accessor :path
|
11
|
+
attr_accessor :docItems
|
12
|
+
attr_accessor :title
|
13
|
+
attr_accessor :key
|
14
|
+
attr_accessor :up_link_key
|
15
|
+
attr_accessor :dictionary
|
16
|
+
attr_accessor :controlledParagraphs
|
17
|
+
attr_accessor :tempMdTable
|
18
|
+
|
19
|
+
def initialize(fele_path)
|
20
|
+
|
21
|
+
@path = fele_path
|
22
|
+
@title = ""
|
23
|
+
@docItems = Array.new
|
24
|
+
@controlledParagraphs = Array.new
|
25
|
+
@dictionary = Hash.new
|
26
|
+
@tempMdTable = nil
|
27
|
+
|
28
|
+
@key = File.basename(fele_path, File.extname(fele_path)).upcase
|
29
|
+
@up_link_key = ""
|
30
|
+
|
31
|
+
self.parse()
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse()
|
35
|
+
|
36
|
+
file = File.open( self.path )
|
37
|
+
file_lines = file.readlines
|
38
|
+
file.close
|
39
|
+
|
40
|
+
file_lines.each do |s|
|
41
|
+
if s.lstrip != ""
|
42
|
+
if res = /^([#]{1,})\s(.*)/.match(s) # Heading
|
43
|
+
|
44
|
+
if @tempMdTable
|
45
|
+
self.docItems.append(@tempMdTable)
|
46
|
+
@tempMdTable = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
level = res[1].length
|
50
|
+
value = res[2]
|
51
|
+
item = Heading.new(value, level)
|
52
|
+
self.docItems.append(item)
|
53
|
+
|
54
|
+
if level == 1
|
55
|
+
self.title = value
|
56
|
+
end
|
57
|
+
|
58
|
+
elsif res = /^\[(\S*)\]\s+(.*)/.match(s) # Controlled Paragraph
|
59
|
+
|
60
|
+
if @tempMdTable
|
61
|
+
self.docItems.append(@tempMdTable)
|
62
|
+
@tempMdTable = nil
|
63
|
+
end
|
64
|
+
|
65
|
+
id = res[1]
|
66
|
+
text = res[2]
|
67
|
+
item = ControlledParagraph.new( text, id )
|
68
|
+
|
69
|
+
#check if it contains the uplink
|
70
|
+
if tmp = /(.*)\s+>\[(\S*)\]$/.match(text)
|
71
|
+
|
72
|
+
text = tmp[1]
|
73
|
+
up_link = tmp[2]
|
74
|
+
|
75
|
+
item.up_link = up_link
|
76
|
+
|
77
|
+
if tmp = /^([a-zA-Z]+)[-]\d+/.match(up_link)
|
78
|
+
self.up_link_key = tmp[1]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
self.docItems.append(item)
|
83
|
+
self.dictionary[ id.to_s ] = item #for fast search
|
84
|
+
self.controlledParagraphs.append(item) #for fast search
|
85
|
+
|
86
|
+
elsif s[0] == '|' #check if table
|
87
|
+
|
88
|
+
if res = /^[|](-{3,})[|]/.match(s) #check if it is a separator first
|
89
|
+
|
90
|
+
if @tempMdTable
|
91
|
+
#separator is found after heading - just skip it
|
92
|
+
else
|
93
|
+
#separator out of table scope consider it just as a regular paragraph
|
94
|
+
item = Paragraph.new(s)
|
95
|
+
self.docItems.append(item)
|
96
|
+
end
|
97
|
+
|
98
|
+
elsif res = /^[|](.*[|])/.match(s) #check if it looks as a table
|
99
|
+
|
100
|
+
row = res[1]
|
101
|
+
|
102
|
+
if @tempMdTable
|
103
|
+
@tempMdTable.addRow(row)
|
104
|
+
else
|
105
|
+
#start table from heading
|
106
|
+
@tempMdTable = MarkdownTable.new(row)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
elsif res = /^[>](.*)/.match(s) #check if blockquote
|
111
|
+
|
112
|
+
if @tempMdTable
|
113
|
+
self.docItems.append(@tempMdTable)
|
114
|
+
@tempMdTable = nil
|
115
|
+
end
|
116
|
+
|
117
|
+
item = Blockquote.new(res[1])
|
118
|
+
self.docItems.append(item)
|
119
|
+
|
120
|
+
else # Reqular Paragraph
|
121
|
+
if @tempMdTable
|
122
|
+
self.docItems.append(@tempMdTable)
|
123
|
+
@tempMdTable = nil
|
124
|
+
end
|
125
|
+
item = Paragraph.new(s)
|
126
|
+
self.docItems.append(item)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/lib/almirah.rb
CHANGED
@@ -1,5 +1,46 @@
|
|
1
|
+
require "thor"
|
2
|
+
require_relative "almirah/specification"
|
3
|
+
require_relative "almirah/linker"
|
4
|
+
require_relative "almirah/html_render"
|
5
|
+
|
6
|
+
class CLI < Thor
|
7
|
+
desc "please <pass>", "say <pass>"
|
8
|
+
def please(pass)
|
9
|
+
Almirah.new().start(pass)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
1
13
|
class Almirah
|
2
|
-
|
3
|
-
|
14
|
+
|
15
|
+
def getGemRoot
|
16
|
+
File.expand_path './..', File.dirname(__FILE__)
|
4
17
|
end
|
5
|
-
|
18
|
+
|
19
|
+
def start(pass)
|
20
|
+
# Documents
|
21
|
+
documentList = Array.new
|
22
|
+
|
23
|
+
# Parse
|
24
|
+
Dir.glob( "#{pass}/**/*.md" ).each do |f|
|
25
|
+
puts f
|
26
|
+
spec = Specification.new(f)
|
27
|
+
documentList.append(spec)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Link
|
31
|
+
linker = Linker.new
|
32
|
+
linker.link(documentList[0], documentList[1])
|
33
|
+
|
34
|
+
# Render
|
35
|
+
FileUtils.remove_dir(pass + "/build", true)
|
36
|
+
FileUtils.mkdir_p(pass + "/build/specifications")
|
37
|
+
|
38
|
+
documentList.each do |spec|
|
39
|
+
FileUtils.mkdir_p(pass + "/build/specifications/" + spec.key.downcase)
|
40
|
+
HtmlRender.new( spec,
|
41
|
+
getGemRoot() + "/lib/almirah/templates/page.html",
|
42
|
+
"#{pass}/build/specifications/#{spec.key.downcase}/#{spec.key.downcase}.html" )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
metadata
CHANGED
@@ -1,22 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Almirah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksandr Ivanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The software part of the Almirah system
|
14
14
|
email: oleksandr.ivanov.development@gmail.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- almirah
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- bin/almirah
|
19
21
|
- lib/almirah.rb
|
22
|
+
- lib/almirah/doc_items/blockquote.rb
|
23
|
+
- lib/almirah/doc_items/controlled_paragraph.rb
|
24
|
+
- lib/almirah/doc_items/doc_item.rb
|
25
|
+
- lib/almirah/doc_items/heading.rb
|
26
|
+
- lib/almirah/doc_items/markdown_table.rb
|
27
|
+
- lib/almirah/doc_items/paragraph.rb
|
28
|
+
- lib/almirah/html_render.rb
|
29
|
+
- lib/almirah/linker.rb
|
30
|
+
- lib/almirah/specification.rb
|
31
|
+
- lib/almirah/templates/page.html
|
20
32
|
homepage: https://rubygems.org/gems/almirah
|
21
33
|
licenses:
|
22
34
|
- MIT
|