phari_doc_gen 1.2.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/{generate → phari_doc_gen} +0 -0
- data/lib/phari_doc_gen/FileHandler.rb +118 -62
- data/lib/phari_doc_gen/MethodParam.rb +7 -0
- data/lib/phari_doc_gen/Metodo.rb +7 -0
- data/lib/phari_doc_gen/Modelo.rb +7 -0
- data/lib/phari_doc_gen/Rota.rb +7 -0
- data/lib/phari_doc_gen.rb +28 -19
- metadata +29 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e53d9f6e1da49020951dcd28ef795366414da7
|
4
|
+
data.tar.gz: 98e589057107d1e726ce6c275175d94a28a35b7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfa16be8876a0d45963dff63dabe84acf83643f3cbf2e3a46c2357b8655088cea729ccd3f68abe73b7ad91545e89ff9fac2b74704a47ee3fbdae07b4305b8dd6
|
7
|
+
data.tar.gz: 875ba1fcd148ee471d210652c320af69f5b56dfb28d8a3af8881d212d09adacd888be3fdf6bf004347f8caaf362a4baa09219ed92b53ac77e648d4186d95c12e
|
File without changes
|
@@ -1,3 +1,10 @@
|
|
1
|
+
#--------------------------------------------------------------------------------------------
|
2
|
+
# THE BEER-WARE LICENSE" (Revision 42): <luiz@phari.solutions> wrote this file.
|
3
|
+
# As long as you retain this notice you can do whatever you want with this stuff.
|
4
|
+
# If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
|
5
|
+
# Luiz Philippe.
|
6
|
+
#--------------------------------------------------------------------------------------------
|
7
|
+
|
1
8
|
require 'fileutils'
|
2
9
|
require_relative 'Modelo.rb'
|
3
10
|
require_relative 'Rota.rb'
|
@@ -5,43 +12,52 @@ require_relative 'Metodo.rb'
|
|
5
12
|
require_relative 'MethodParam.rb'
|
6
13
|
|
7
14
|
class FileHandler
|
8
|
-
#
|
15
|
+
# Reading files
|
16
|
+
# Find a folder with the project name
|
9
17
|
def packageExistis?(packageName)
|
10
18
|
found = false
|
11
19
|
package = ''
|
20
|
+
puts'Finding project'
|
21
|
+
puts'It may take some time...'
|
12
22
|
Dir.glob('/**/' + packageName + '/') do |folder|
|
13
23
|
package = folder unless found
|
14
24
|
found = true
|
15
|
-
# puts 'done'
|
16
25
|
end
|
17
26
|
packagePath = package.to_s
|
18
|
-
# puts packagePath
|
19
27
|
if found
|
28
|
+
# Return the folder path if found
|
20
29
|
return packagePath
|
21
30
|
else
|
31
|
+
# Exit if not found
|
22
32
|
puts 'Aborting: package not found'
|
23
33
|
exit
|
24
34
|
end
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
|
-
|
37
|
+
# Read the 'README.md' file and generate descriprion
|
38
|
+
def readProject(path)
|
29
39
|
projectDescription = ''
|
30
|
-
|
31
|
-
|
32
|
-
|
40
|
+
if File.exists?(path + 'README.md')
|
41
|
+
readme = File.new(path + 'README.md')
|
42
|
+
projectDescription = readProjectDescription(readme)
|
43
|
+
projectDescription
|
44
|
+
else
|
45
|
+
puts 'Warning: No README.md file found.'
|
46
|
+
end
|
33
47
|
end
|
34
48
|
|
35
|
-
|
49
|
+
# Read models, helpers and controllers
|
50
|
+
def readFiles(path)
|
36
51
|
models = []
|
37
|
-
|
38
|
-
Dir.glob(path + '
|
52
|
+
# Find each model, helper and controller
|
53
|
+
Dir.glob(path + 'api/models/*.rb') do |file|
|
39
54
|
filename = file.to_s
|
40
55
|
inputFile = File.new(filename)
|
41
56
|
modelname = File.basename(inputFile, '.rb')
|
42
|
-
helpername = path + '
|
43
|
-
controllername = path + '
|
57
|
+
helpername = path + 'api/app/helpers/' + modelname + '_helper.rb'
|
58
|
+
controllername = path + 'api/app/controllers/' + modelname + '.rb'
|
44
59
|
if File.exist?(helpername) && File.exist?(controllername)
|
60
|
+
# Call the necessary methods for each helper and controller
|
45
61
|
modelHelper = File.new(helpername, 'r')
|
46
62
|
modelController = File.new(controllername, 'r')
|
47
63
|
methods = readMethods(modelHelper, helpername)
|
@@ -50,37 +66,26 @@ class FileHandler
|
|
50
66
|
models << currentModel
|
51
67
|
end
|
52
68
|
end
|
69
|
+
# Return models
|
53
70
|
models
|
54
71
|
end
|
55
72
|
|
56
|
-
#
|
73
|
+
# Auxiliary methods of reading
|
74
|
+
|
75
|
+
#Generate project descriprion based on 'README.md'
|
57
76
|
def readProjectDescription(readme)
|
58
77
|
isCode = false
|
59
78
|
@projectDescription = ''
|
60
79
|
arr = IO.readlines(readme)
|
80
|
+
# Read each line from the README
|
61
81
|
arr.each do |line|
|
62
|
-
|
63
|
-
if line.start_with?('
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
line = '<h4>' + line.slice(4, line.length - 4) + '</h4>'
|
70
|
-
# puts line
|
71
|
-
end
|
72
|
-
if line.start_with?('##### ')
|
73
|
-
line = '<h5>' + line.slice(6, line.length - 6) + '</h5>'
|
74
|
-
# puts line
|
75
|
-
end
|
76
|
-
if line.start_with?('* ')
|
77
|
-
line = '<li>' + line.slice(2, line.length - 2) + '</li>'
|
78
|
-
# puts line
|
79
|
-
end
|
80
|
-
while hasBetween?(line, '**', '**')
|
81
|
-
line = higlightText(line)
|
82
|
-
# puts line
|
83
|
-
end
|
82
|
+
# Read markdown syntax and trasform into HTML tags
|
83
|
+
next if line.start_with?('# ') || line.start_with?('#!shell')
|
84
|
+
line = '<h3>' + line.slice(3, line.length - 3) + '</h3>'if line.start_with?('## ')
|
85
|
+
line = '<h4>' + line.slice(4, line.length - 4) + '</h4>' if line.start_with?('### ')
|
86
|
+
line = '<h5>' + line.slice(6, line.length - 6) + '</h5>' if line.start_with?('##### ')
|
87
|
+
line = '<li>' + line.slice(2, line.length - 2) + '</li>' if line.start_with?('* ')
|
88
|
+
line = higlightText(line) while hasBetween?(line, '**', '**')
|
84
89
|
line = italicText(line) while hasBetween?(line, '*', '*')
|
85
90
|
if line.include?('```')
|
86
91
|
if isCode
|
@@ -96,9 +101,11 @@ class FileHandler
|
|
96
101
|
end
|
97
102
|
@projectDescription += line
|
98
103
|
end
|
104
|
+
# Return the HTML formated lines
|
99
105
|
@projectDescription
|
100
106
|
end
|
101
107
|
|
108
|
+
# Verify if line contains markdown syntax like **bold**
|
102
109
|
def hasBetween?(line, stringA, stringB)
|
103
110
|
if line.include?(stringA)
|
104
111
|
initial = line.index(stringA)
|
@@ -109,6 +116,7 @@ class FileHandler
|
|
109
116
|
false
|
110
117
|
end
|
111
118
|
|
119
|
+
# Convert **bold** markdown to <b>bold</b> HTML
|
112
120
|
def higlightText(line)
|
113
121
|
initialIndex = line.index('**') + 2
|
114
122
|
finalIndex = line.index('**', initialIndex)
|
@@ -116,10 +124,10 @@ class FileHandler
|
|
116
124
|
higlightedString = line.slice(initialIndex, finalIndex - initialIndex)
|
117
125
|
finalString = line.slice(finalIndex + 2, line.length - finalIndex + 2)
|
118
126
|
line = initialString + '<b>' + higlightedString + '</b>' + finalString
|
119
|
-
# puts line
|
120
127
|
line
|
121
128
|
end
|
122
129
|
|
130
|
+
# Convert *italic* markdown to <i>italic</i> HTML
|
123
131
|
def italicText(line)
|
124
132
|
initialIndex = line.index('*') + 1
|
125
133
|
finalIndex = line.index('*', initialIndex)
|
@@ -127,10 +135,10 @@ class FileHandler
|
|
127
135
|
higlightedString = line.slice(initialIndex, finalIndex - initialIndex)
|
128
136
|
finalString = line.slice(finalIndex + 1, line.length - finalIndex + 1)
|
129
137
|
line = initialString + '<i>' + higlightedString + '</i>' + finalString
|
130
|
-
# puts line
|
131
138
|
line
|
132
139
|
end
|
133
140
|
|
141
|
+
# Convert [www.someaddress.com](text) markdown to <a href="www.someaddress.com">text</a> HTML
|
134
142
|
def linkText(line)
|
135
143
|
if line.include?(' [') && line.include?('](')
|
136
144
|
initialContentIndex = line.index('[') + 1
|
@@ -146,6 +154,7 @@ class FileHandler
|
|
146
154
|
line
|
147
155
|
end
|
148
156
|
|
157
|
+
# Read all methods from a helper file; helper = file, helpername = file path
|
149
158
|
def readMethods(helper, helpername)
|
150
159
|
lineIndex = 0
|
151
160
|
tipo = ''
|
@@ -157,12 +166,16 @@ class FileHandler
|
|
157
166
|
toSent = true
|
158
167
|
begin
|
159
168
|
arr = IO.readlines(helper)
|
169
|
+
# Read each line from helper
|
160
170
|
arr.each do |line|
|
161
171
|
lineIndex += 1
|
172
|
+
# Verify if it has a clause
|
162
173
|
if hasKeyword?(line, lineIndex, helpername)
|
174
|
+
# If it does, identify which clause it is
|
163
175
|
arg = decodeArgument(line)
|
164
176
|
keyword = arg[0]
|
165
177
|
argument = arg[1]
|
178
|
+
# Execute clause
|
166
179
|
case keyword
|
167
180
|
when 'methods'
|
168
181
|
if nome != ''
|
@@ -181,8 +194,6 @@ class FileHandler
|
|
181
194
|
toSent = true
|
182
195
|
end
|
183
196
|
nome = argument
|
184
|
-
# methods.last.printName
|
185
|
-
# puts "#{methods.size}"
|
186
197
|
when 'param'
|
187
198
|
data = dataValue(argument)
|
188
199
|
inputs << data
|
@@ -190,19 +201,23 @@ class FileHandler
|
|
190
201
|
data = dataValue(argument)
|
191
202
|
outputs << data
|
192
203
|
else
|
204
|
+
# If a possible syntax error is found, a warning is sent informing file and linne
|
193
205
|
puts "Warning: in #{helpername}:#{lineIndex}: #{keyword} is not a keyword" if keyword != 'namespace'
|
194
206
|
end
|
195
207
|
end
|
196
208
|
descricao = decodeDescription(line) if hasDescription?(line, lineIndex, helpername)
|
197
209
|
end
|
198
210
|
rescue ArgumentError => e
|
211
|
+
# If a syntax error is found, it rais an Argument Error informing the file and line
|
199
212
|
puts "ERROR: #{helpername}:#{lineIndex}: in #{nome}"
|
200
213
|
puts e.message
|
201
214
|
end
|
202
215
|
methods << Metodo.new(nome, tipo, inputs, outputs, descricao)
|
216
|
+
# Return a methods array
|
203
217
|
methods
|
204
218
|
end
|
205
219
|
|
220
|
+
# Read all routes from a controller file; controller = file, controllername = file path
|
206
221
|
def readRoutes(controller, controllername)
|
207
222
|
lineIndex = 0
|
208
223
|
tipo = ''
|
@@ -215,13 +230,17 @@ class FileHandler
|
|
215
230
|
toSent = true
|
216
231
|
begin
|
217
232
|
arr = IO.readlines(controller)
|
233
|
+
# Read each line from controller
|
218
234
|
arr.each do |line|
|
219
235
|
lineIndex += 1
|
236
|
+
# Skip to next line if no clause is found
|
220
237
|
next unless hasKeyword?(line, lineIndex, controllername)
|
238
|
+
# If it has any clause, identify which one it is
|
221
239
|
arg = decodeArgument(line)
|
222
240
|
keyword = arg[0]
|
223
241
|
argument = arg[1]
|
224
242
|
case keyword
|
243
|
+
# Then execute clause
|
225
244
|
when 'route'
|
226
245
|
if nome != ''
|
227
246
|
routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
|
@@ -279,18 +298,24 @@ class FileHandler
|
|
279
298
|
data = dataValue(argument)
|
280
299
|
outputs << data
|
281
300
|
else
|
301
|
+
# If a possible syntax error is found, a warning is sent informing file and linne
|
302
|
+
# (Here in the namespace comparison, i'm doing a little mcgyver)
|
282
303
|
puts "Warning: in #{controllername}:#{lineIndex}: #{keyword} is not a keyword" if keyword != 'namespace'
|
283
304
|
end
|
284
305
|
end
|
285
306
|
rescue ArgumentError => e
|
307
|
+
# If a syntax error is found, it raise an Argument Error informing the file and line
|
286
308
|
puts "ERROR: #{controllername}:#{lineIndex}: in #{nome}"
|
287
309
|
puts e.message
|
288
310
|
end
|
289
311
|
routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
|
312
|
+
# Return a routes array
|
290
313
|
routes
|
291
314
|
end
|
292
315
|
|
293
|
-
#
|
316
|
+
# Decoding clauses methods
|
317
|
+
|
318
|
+
# Verify if a given line has any clause
|
294
319
|
def hasKeyword?(line, lineIndex, fileName)
|
295
320
|
if (line.include? '#') && (line.include? '@')
|
296
321
|
for i in 0..line.index('#')-1
|
@@ -301,16 +326,20 @@ class FileHandler
|
|
301
326
|
for i in line.index('#')+1..line.index('@')-1
|
302
327
|
if line[i].match(/^[[:alpha:]]$/)
|
303
328
|
lineText = line.slice(line.index('#'), line.index("\n") - line.index('#'))
|
329
|
+
# A warning informing file and line is sent if a possible error is found
|
304
330
|
puts "Warning: in #{fileName}:#{lineIndex}: #{lineText} is not a keyword"
|
305
331
|
return false
|
306
332
|
end
|
307
333
|
end
|
334
|
+
# Return true if it do
|
308
335
|
true
|
309
336
|
else
|
337
|
+
# And false if it don't
|
310
338
|
false
|
311
339
|
end
|
312
340
|
end
|
313
341
|
|
342
|
+
# The ** description clause has his own method seen that it has different syntax
|
314
343
|
def hasDescription?(line, lineIndex, fileName)
|
315
344
|
if (line.include? '#') && (line.include? '**')
|
316
345
|
for i in 0..line.index('#')-1
|
@@ -321,22 +350,27 @@ class FileHandler
|
|
321
350
|
for i in line.index('#')+1..line.index('**')-1
|
322
351
|
if line[i].match(/^[[:alpha:]]$/)
|
323
352
|
lineText = line.slice(line.index('#'), line.index("\n") - line.index('#'))
|
353
|
+
# A warning informing file and line is sent if a possible error is found
|
324
354
|
puts "Warning: in #{fileName}:#{lineIndex}: #{lineText} is not a description"
|
325
355
|
return false
|
326
356
|
end
|
327
357
|
end
|
358
|
+
# Return true if it has description clause
|
328
359
|
true
|
329
360
|
else
|
361
|
+
# And false if it don't
|
330
362
|
false
|
331
363
|
end
|
332
364
|
end
|
333
365
|
|
366
|
+
# Decode which clause is on a given line, and which arguments
|
334
367
|
def decodeArgument(line)
|
335
368
|
args = []
|
336
369
|
initialIndex = line.index('@') + 1
|
337
370
|
finalIndex = line.index("\s", line.index('@'))
|
338
371
|
if finalIndex == nil || initialIndex == nil
|
339
372
|
if line.index('@')+1 == /^[[:alpha:]]$/
|
373
|
+
# Raises an Argument Error if some error is found
|
340
374
|
raise ArgumentError.new("Sytanx error: expected 2 arguments (one given)")
|
341
375
|
else raise ArgumentError.new("Sytanx error: expected 2 arguments (none given)")
|
342
376
|
end
|
@@ -346,15 +380,17 @@ class FileHandler
|
|
346
380
|
argument = line.slice(finalIndex + 1, line.size - finalIndex)
|
347
381
|
args << keyword
|
348
382
|
args << argument
|
383
|
+
# Return array with clause and arguments
|
349
384
|
args
|
350
385
|
end
|
351
386
|
|
387
|
+
# If the clause is a param or return value, decode the name and datatype
|
352
388
|
def dataValue(argument)
|
353
389
|
if argument.include? "\s"
|
354
390
|
name = argument.slice(0, argument.index("\s"))
|
355
|
-
type = argument.slice(argument.index("\s") + 1, argument.size -
|
391
|
+
type = argument.slice(argument.index("\s") + 1, argument.size - 2)
|
356
392
|
data = MethodParam.new(name, type)
|
357
|
-
# data
|
393
|
+
# Return the data
|
358
394
|
return data
|
359
395
|
elsif argument.include? "nil"
|
360
396
|
data = MethodParam.new('', 'nil')
|
@@ -364,46 +400,62 @@ class FileHandler
|
|
364
400
|
return data
|
365
401
|
end
|
366
402
|
argumentText = argument.slice(0, argument.index("\n"))
|
403
|
+
# If any information is missing or incorrect, raises an Argument Error
|
367
404
|
raise ArgumentError.new("Sytanx error: #{argumentText} is no data")
|
368
405
|
end
|
369
406
|
|
407
|
+
# Decode the text from a description clause
|
370
408
|
def decodeDescription(line)
|
371
409
|
initialIndex = line.index('*') + 3
|
372
410
|
lenght = line.size - initialIndex
|
373
411
|
description = line.slice(initialIndex, lenght)
|
374
|
-
#
|
412
|
+
# Return the description text
|
375
413
|
description
|
376
414
|
end
|
377
415
|
|
378
|
-
#
|
379
|
-
def writeFiles(models,
|
380
|
-
|
381
|
-
|
416
|
+
# File writing
|
417
|
+
def writeFiles(models, projectName, projectDescription, path)
|
418
|
+
outputFolder = path + "#{projectName}_PhariDoc/"
|
419
|
+
FileUtils.mkdir_p(outputFolder)
|
420
|
+
# Create the css/master.css file, which is default for any project
|
421
|
+
FileUtils.mkdir_p(outputFolder + 'css/')
|
422
|
+
css = File.open(outputFolder + 'css/master.css', 'w')
|
382
423
|
writeCSS(css)
|
383
424
|
css.close
|
384
|
-
|
425
|
+
# Write the project main page
|
426
|
+
projectHTML = File.open(outputFolder + 'project.html', 'w')
|
385
427
|
writeHeader(projectHTML)
|
386
|
-
writeProjectPage(
|
428
|
+
writeProjectPage(projectName, projectHTML, models, projectDescription)
|
387
429
|
projectHTML.close
|
388
|
-
|
430
|
+
# Write each model's page
|
431
|
+
FileUtils.mkdir_p(outputFolder + 'models/')
|
389
432
|
models.each do |model|
|
390
433
|
name = model.name.downcase
|
391
|
-
modelHTML = File.open(
|
434
|
+
modelHTML = File.open(outputFolder + "models/#{name}.html", 'w')
|
392
435
|
writeHeaderInDir(modelHTML)
|
393
|
-
writeModelPage(modelHTML, model)
|
436
|
+
writeModelPage(modelHTML, model, projectName)
|
437
|
+
modelHTML.close
|
394
438
|
end
|
395
439
|
end
|
396
440
|
|
441
|
+
# Write the css content
|
397
442
|
def writeCSS(file)
|
398
443
|
file.write("body{
|
399
|
-
background-color: #
|
444
|
+
background-color: #2CA896;
|
400
445
|
}
|
401
446
|
a{
|
447
|
+
color: #2CA896;
|
448
|
+
}
|
449
|
+
a:hover{
|
402
450
|
color: #333;
|
403
451
|
}
|
404
452
|
li{
|
405
453
|
padding-left: 3%;
|
406
454
|
}
|
455
|
+
code{
|
456
|
+
background-color: #DDD;
|
457
|
+
color: black;
|
458
|
+
}
|
407
459
|
.logo{
|
408
460
|
margin: 5%;
|
409
461
|
}
|
@@ -418,6 +470,7 @@ class FileHandler
|
|
418
470
|
}")
|
419
471
|
end
|
420
472
|
|
473
|
+
# Write the HTML header
|
421
474
|
def writeHeader(file)
|
422
475
|
file.write("<!DOCTYPE html>
|
423
476
|
|
@@ -441,6 +494,7 @@ class FileHandler
|
|
441
494
|
<br><br><br>")
|
442
495
|
end
|
443
496
|
|
497
|
+
# Write the HTML header with relative paths
|
444
498
|
def writeHeaderInDir(file)
|
445
499
|
file.write("<!DOCTYPE html>
|
446
500
|
|
@@ -464,6 +518,7 @@ class FileHandler
|
|
464
518
|
<br><br><br>")
|
465
519
|
end
|
466
520
|
|
521
|
+
#Write the main project HTML content
|
467
522
|
def writeProjectPage(project, file, models, description)
|
468
523
|
file.write("<div class='container panel panel-default'>
|
469
524
|
<div class='row'>
|
@@ -496,13 +551,14 @@ class FileHandler
|
|
496
551
|
</body>")
|
497
552
|
end
|
498
553
|
|
499
|
-
|
554
|
+
# Write a model HTML page content
|
555
|
+
def writeModelPage(file, model, project)
|
500
556
|
name = model.name.capitalize
|
501
557
|
file.write("<div class='container panel panel-default'>
|
502
558
|
<div class='row'>
|
503
559
|
<div class='panel panel-default'>
|
504
560
|
<div class='panel-heading'>
|
505
|
-
<h1
|
561
|
+
<h1>#{project}</h1>
|
506
562
|
</div>
|
507
563
|
<div class='panel-body'>
|
508
564
|
<h2>#{name} Model</h2>
|
@@ -525,15 +581,15 @@ class FileHandler
|
|
525
581
|
outputs = method.outputs
|
526
582
|
description = method.description
|
527
583
|
file.write(" <div class='list-group-item'>
|
528
|
-
<h4 class='list-group-item-heading'
|
529
|
-
<p><br>
|
584
|
+
<h4 class='list-group-item-heading'>CRUD: #{type}<br>Name: #{name}</h4>
|
585
|
+
<p><br>Inputs:<br>
|
530
586
|
<ul>")
|
531
587
|
inputs.each do |input|
|
532
588
|
type = input.type
|
533
589
|
name = input.name
|
534
590
|
file.write("<li>#{type}: #{name}</li>")
|
535
591
|
end
|
536
|
-
file.write("</ul><br>
|
592
|
+
file.write("</ul><br>Outputs:<br>
|
537
593
|
<ul>")
|
538
594
|
outputs.each do |output|
|
539
595
|
if output != 'nil'
|
@@ -565,17 +621,17 @@ class FileHandler
|
|
565
621
|
inputs = route.inputs
|
566
622
|
outputs = route.outputs
|
567
623
|
file.write(" <div class='list-group-item'>
|
568
|
-
<h4 class='list-group-item-heading'>
|
624
|
+
<h4 class='list-group-item-heading'>CRUD: #{type}<br>Name: #{name}</h4>
|
569
625
|
<p><br>Request: #{request}<br>
|
570
626
|
<br>Notation type: #{dataInput}<br>
|
571
|
-
<br>
|
627
|
+
<br>Inputs:<br>
|
572
628
|
<ul>")
|
573
629
|
inputs.each do |input|
|
574
630
|
type = input.type
|
575
631
|
name = input.name
|
576
632
|
file.write("<li>#{type}: #{name}</li>")
|
577
633
|
end
|
578
|
-
file.write("</ul><br>
|
634
|
+
file.write("</ul><br>Outputs:<br>
|
579
635
|
<ul>")
|
580
636
|
outputs.each do |output|
|
581
637
|
if output != 'nil'
|
@@ -1,3 +1,10 @@
|
|
1
|
+
#--------------------------------------------------------------------------------------------
|
2
|
+
# THE BEER-WARE LICENSE" (Revision 42): <luiz@phari.solutions> wrote this file.
|
3
|
+
# As long as you retain this notice you can do whatever you want with this stuff.
|
4
|
+
# If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
|
5
|
+
# Luiz Philippe.
|
6
|
+
#--------------------------------------------------------------------------------------------
|
7
|
+
|
1
8
|
class MethodParam
|
2
9
|
@name = ''
|
3
10
|
@type = ''
|
data/lib/phari_doc_gen/Metodo.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#--------------------------------------------------------------------------------------------
|
2
|
+
# THE BEER-WARE LICENSE" (Revision 42): <luiz@phari.solutions> wrote this file.
|
3
|
+
# As long as you retain this notice you can do whatever you want with this stuff.
|
4
|
+
# If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
|
5
|
+
# Luiz Philippe.
|
6
|
+
#--------------------------------------------------------------------------------------------
|
7
|
+
|
1
8
|
require_relative 'MethodParam.rb'
|
2
9
|
|
3
10
|
class Metodo
|
data/lib/phari_doc_gen/Modelo.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#--------------------------------------------------------------------------------------------
|
2
|
+
# THE BEER-WARE LICENSE" (Revision 42): <luiz@phari.solutions> wrote this file.
|
3
|
+
# As long as you retain this notice you can do whatever you want with this stuff.
|
4
|
+
# If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
|
5
|
+
# Luiz Philippe.
|
6
|
+
#--------------------------------------------------------------------------------------------
|
7
|
+
|
1
8
|
class Modelo
|
2
9
|
@methods = []
|
3
10
|
@routes = []
|
data/lib/phari_doc_gen/Rota.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#--------------------------------------------------------------------------------------------
|
2
|
+
# THE BEER-WARE LICENSE" (Revision 42): <luiz@phari.solutions> wrote this file.
|
3
|
+
# As long as you retain this notice you can do whatever you want with this stuff.
|
4
|
+
# If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
|
5
|
+
# Luiz Philippe.
|
6
|
+
#--------------------------------------------------------------------------------------------
|
7
|
+
|
1
8
|
class Rota
|
2
9
|
@type = ''
|
3
10
|
@name = ''
|
data/lib/phari_doc_gen.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#--------------------------------------------------------------------------------------------
|
2
|
+
# THE BEER-WARE LICENSE" (Revision 42): <luiz@phari.solutions> wrote this file.
|
3
|
+
# As long as you retain this notice you can do whatever you want with this stuff.
|
4
|
+
# If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
|
5
|
+
# Luiz Philippe.
|
6
|
+
#--------------------------------------------------------------------------------------------
|
7
|
+
|
1
8
|
require 'fileutils'
|
2
9
|
require_relative 'phari_doc_gen/Modelo.rb'
|
3
10
|
require_relative 'phari_doc_gen/Rota.rb'
|
@@ -6,29 +13,31 @@ require_relative 'phari_doc_gen/MethodParam.rb'
|
|
6
13
|
require_relative 'phari_doc_gen/FileHandler.rb'
|
7
14
|
|
8
15
|
class PhariDocGen
|
9
|
-
|
10
|
-
|
16
|
+
# Generate documentation for standard projects
|
17
|
+
def generate (project, outputPath)
|
18
|
+
generate = FileHandler.new
|
19
|
+
# Ask for project name if nil
|
20
|
+
if project.nil?
|
11
21
|
puts "Insert project which generate documentation"
|
12
22
|
project = gets.chomp
|
23
|
+
while project == ''
|
24
|
+
project = gets.chomp
|
25
|
+
end
|
13
26
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
path += '/' unless path.end_with?('/')
|
26
|
-
path = '/'+path unless path.start_with?('/')
|
27
|
-
if path == ''
|
28
|
-
puts 'Aborting generation due to empty path'
|
29
|
-
exit
|
27
|
+
# Verify the existence of the project
|
28
|
+
projectPath = generate.packageExistis?(project)
|
29
|
+
# Get description from README.md
|
30
|
+
projectDescription = generate.readProject(projectPath)
|
31
|
+
# Get models with their methods and routes
|
32
|
+
models = generate.readFiles(projectPath)
|
33
|
+
# Specify the output path
|
34
|
+
if outputPath.nil?
|
35
|
+
outputPath = ''
|
36
|
+
else
|
37
|
+
outputPath += '/' unless outputPath.end_with?('/')
|
30
38
|
end
|
31
|
-
|
39
|
+
# Write documentation
|
40
|
+
generate.writeFiles(models, project, projectDescription, outputPath)
|
32
41
|
puts 'Done!'
|
33
42
|
end
|
34
43
|
end
|
metadata
CHANGED
@@ -1,24 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phari_doc_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Phari
|
7
|
+
- Phari Solutions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
13
|
+
description: |2-
|
14
|
+
Hi there buddy! I've heard you've been looking for a simple
|
15
|
+
and functional documentation generator for this Ruby web app
|
16
|
+
of yours. So here goes a brief tutorial on how to use this
|
17
|
+
little gem developed by Phari Solutions. First things first.
|
18
|
+
To use this gem, you will need to be following the sinatra/padrino
|
19
|
+
patterns. If you're using those frameworks probably you already
|
20
|
+
matched the requisites, otherwise, organize your folders properly.
|
21
|
+
Your project tree has to be organized in a main directory called
|
22
|
+
'api' that must contain another folder 'app' with three other
|
23
|
+
directories 'models', 'helpers' and 'controllers' within. The files will
|
24
|
+
also have to be especifically named. But we'll look further into it
|
25
|
+
later. Now, requisites aside, Phari Doc Generator will provide you
|
26
|
+
an easy way to generate documentation for your projects. The result
|
27
|
+
will be a project page with a description that can be written using a simplified
|
28
|
+
markdown syntax that is going to be explained ahead. Also, each ruby
|
29
|
+
Class will have it's own page especifying it's helper methods and controllers
|
30
|
+
routes including their inputs, outputs and descriptions. The gem includes
|
31
|
+
an executable file and the classes that can be used individually,
|
32
|
+
providing the possibility to use the generator for any project
|
33
|
+
structure. See full documentation in:
|
34
|
+
email: contact@phari.solutions
|
16
35
|
executables:
|
17
|
-
-
|
36
|
+
- phari_doc_gen
|
18
37
|
extensions: []
|
19
38
|
extra_rdoc_files: []
|
20
39
|
files:
|
21
|
-
- bin/
|
40
|
+
- bin/phari_doc_gen
|
22
41
|
- lib/phari_doc_gen.rb
|
23
42
|
- lib/phari_doc_gen/FileHandler.rb
|
24
43
|
- lib/phari_doc_gen/MethodParam.rb
|
@@ -27,7 +46,7 @@ files:
|
|
27
46
|
- lib/phari_doc_gen/Rota.rb
|
28
47
|
homepage: ''
|
29
48
|
licenses:
|
30
|
-
-
|
49
|
+
- Beerware
|
31
50
|
metadata: {}
|
32
51
|
post_install_message:
|
33
52
|
rdoc_options: []
|
@@ -48,5 +67,5 @@ rubyforge_project:
|
|
48
67
|
rubygems_version: 2.5.1
|
49
68
|
signing_key:
|
50
69
|
specification_version: 4
|
51
|
-
summary: 'Main classes: PhariDocGen &&
|
70
|
+
summary: 'Main classes: PhariDocGen && FileHandler'
|
52
71
|
test_files: []
|