Almirah 0.0.1 → 0.0.4

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: a29ec9ab722212c37c713f3c6bc21466d4e5c346fac874df35668e6870b8fea6
4
- data.tar.gz: 9b77c2ef7c49daa90bb4eb9b0113e9f5058f0bdf02c36d91a1c80ec68555d57e
3
+ metadata.gz: 0cec091b4437bbdeb9ea83b3a55638fafef7b0d629ba9eb1f069594ec420651c
4
+ data.tar.gz: 6de241968325f0d89227f25b854332aa697a8af659e49d91fe5130112fcb31ea
5
5
  SHA512:
6
- metadata.gz: 6470130f1031b6bbaba1b1fda333172242c63638cbafcd98f628072d100d2ed135dba1c638abac86da92f7869e004eaf9bf6a42fec56893223f75846e631efc5
7
- data.tar.gz: 8d37951766677fabb80f64840816539c48b38da9fe5fadc778da5f1e5cf64a0ddc06b5ef636231b01446facd8cbb4b2326adec0505558d21ad3062691cd7a681
6
+ metadata.gz: 5196218711f21202659e7cf84b5e1f8329ace42a00831d80acc275357e4b2b38cecb1af6842cc3b9b439f8a1d8c78610761756af5b9e565ce77b3f0aa64d24fd
7
+ data.tar.gz: a23964002a9c745e7529182b6e2ae684b4ca6a9fd7c963a7eae553c370ac64565edd6be4412dfa27c8ed4517f9273562e14ab4adfebe818cf13bce6102b72736
data/bin/almirah ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "almirah"
4
+
5
+ CLI.start(ARGV)
@@ -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>\n\r"
15
+ @@htmlTableRenderInProgress = false
16
+ end
17
+
18
+ s += "<div class=\"blockquote\"><p>#{@text}</div>\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 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
+ @@htmlTableRenderInProgress = true
22
+ 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"
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 class=\"item_id\"><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 class=\"item_id\"></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 class=\"item_id\"><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 class=\"item_id\"></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 class=\"item_id\"></td>\n\r" # COV
48
+ s += "\t</tr>\n\r"
49
+ return s
50
+ end
51
+
52
+ end
@@ -0,0 +1,8 @@
1
+ class DocItem
2
+ @@htmlTableRenderInProgress = false
3
+ end
4
+
5
+
6
+
7
+
8
+
@@ -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}\" class=\"heading_anchor\">"
22
+ s += "&para;</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 class=\"markdown_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
+
68
+ #check if it contains the uplink
69
+ if tmp = /(.*)\s+>\[(\S*)\]$/.match(text)
70
+
71
+ text = tmp[1]
72
+ up_link = tmp[2]
73
+
74
+ if tmp = /^([a-zA-Z]+)[-]\d+/.match(up_link)
75
+ self.up_link_key = tmp[1]
76
+ end
77
+ end
78
+
79
+ item = ControlledParagraph.new( text, id )
80
+ item.up_link = up_link
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
@@ -0,0 +1,147 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <!-- CSS -->
6
+ <style>
7
+ body {
8
+ font-family: Verdana, sans-serif;
9
+ font-size: 12px;
10
+ color: #333;
11
+ margin: 0;
12
+ padding: 0;
13
+ min-width: 900px;
14
+ }
15
+ #main {
16
+ flex-grow: 2;
17
+ display: flex;
18
+ flex-direction: row-reverse;
19
+ }
20
+ #content {
21
+ flex-grow: 1;
22
+ background-color: #fff;
23
+ margin: 0px;
24
+ padding: 10px 16px 10px 16px;
25
+ overflow-x: auto;
26
+ }
27
+ #content h1, h2, h3, h4, h5, h6 {
28
+ color: #555;
29
+ font-family: "Trebuchet MS", Verdana, sans-serif;
30
+ padding: 2px 10px 1px 0px;
31
+ margin: 0 0 10px 0;
32
+ }
33
+ h1 {
34
+ font-size: 2em;
35
+ }
36
+ h2 {
37
+ font-size: 1.8em;
38
+ }
39
+ h3 {
40
+ font-size: 1.5em;
41
+ }
42
+ h4 {
43
+ font-size: 1.2em;
44
+ border: none;
45
+ font-weight: bold;
46
+ }
47
+ h5 {
48
+ font-size: 1em;
49
+ }
50
+ h6 {
51
+ font-size: 1em; color: #8e8e8e;
52
+ }
53
+ a.heading_anchor {
54
+ display: none;
55
+ margin-left: 6px;
56
+ text-decoration: none;
57
+ }
58
+ table.markdown_table{
59
+ border: 1px solid #bbb;
60
+ border-collapse: collapse;
61
+ padding: 4px;
62
+ margin-bottom: 4px;
63
+ overflow: hidden;
64
+ }
65
+ table.markdown_table th{
66
+ border: 1px solid #bbb;
67
+ padding: 4px;
68
+ display: table-cell;
69
+ vertical-align: inherit;
70
+ background-color:#EEEEEE;
71
+ }
72
+ table.markdown_table td{
73
+ border: 1px solid #bbb;
74
+ padding: 4px;
75
+ display: table-cell;
76
+ vertical-align: inherit;
77
+ }
78
+ table.controlled{
79
+ border: 1px solid #e4e4e4;
80
+ border-collapse: collapse;
81
+ width: 100%;
82
+ margin-bottom: 4px;
83
+ border-spacing: 0px;
84
+ border-radius: 3px;
85
+ overflow: hidden;
86
+ }
87
+ table.controlled th {
88
+ background-color:#e1f1fa;
89
+ padding: 4px;
90
+ white-space:nowrap;
91
+ font-weight:bold;
92
+ border: 1px solid #bbb;
93
+ }
94
+ table.controlled td {
95
+ text-align:center;
96
+ vertical-align:middle;
97
+ padding-right:10px;
98
+ border: 1px solid #bbb;
99
+ }
100
+ table.controlled tr:first-child th {
101
+ border-top: 0;
102
+ }
103
+ table.controlled tr:last-child td {
104
+ border-bottom: 0;
105
+ }
106
+ table.controlled tr td:first-child,
107
+ table.controlled tr th:first-child {
108
+ border-left: 0;
109
+ }
110
+ table.controlled tr td:last-child,
111
+ table.controlled tr th:last-child {
112
+ border-right: 0;
113
+ }
114
+ table.controlled td.item_id {
115
+ width: 3%;
116
+ text-align: center;
117
+ }
118
+ table.controlled td.item_text{
119
+ text-align: left;
120
+ }
121
+ table.controlled:not(.odd-even) tbody tr:nth-child(odd) { background-color:#f6f7f8; }
122
+ table.controlled:not(.odd-even) tbody tr:nth-child(even) { background-color: #fff; }
123
+ table.controlled:not(.odd-even) tbody tr:nth-child(odd):hover,
124
+ table.controlled:not(.odd-even) tbody tr:nth-child(even):hover { background-color:#ffffdd; }
125
+ a, a:link, a:visited {
126
+ color: #169;
127
+ text-decoration: none;
128
+ }
129
+ div.blockquote {
130
+ display: block;
131
+ background:#f9f9fb;
132
+ border-left: 3px double #bbb;
133
+ font-style: italic;
134
+ padding: 4px 1em 4px 4px;
135
+ margin-top: 4px;
136
+ margin-bottom: 4px;
137
+ }
138
+ </style>
139
+ </head>
140
+ <body>
141
+ <div id="main">
142
+ <div id="content">
143
+ {{CONTENT}}
144
+ </div>
145
+ </div>
146
+ </body>
147
+
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
- def self.hi
3
- puts "Hi, this is Almirah gem. My development is in-progress."
14
+
15
+ def getGemRoot
16
+ File.expand_path './..', File.dirname(__FILE__)
4
17
  end
5
- end
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.1
4
+ version: 0.0.4
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-16 00:00:00.000000000 Z
11
+ date: 2024-01-27 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