phari_doc_gen 2.1.0 → 2.1.1
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/lib/phari_doc_gen/FileHandler.rb +152 -109
- metadata +5 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ad8f025c300abb25064da2bf9ac3ddcabf231ed
|
4
|
+
data.tar.gz: 49927b12a5443efbb62cde2b7828493c8f7f0210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09c3af0a867d263c21fe8d1ff4f3f3991046773ce043a848c7f95386cd858f3da5d1d0b59444ef8f3e877191b79ea9549918ed6b3e285ee63851550f47a14b7
|
7
|
+
data.tar.gz: 37f6ac303ca59dc6cf544c5fe9d5b3367b3a6316c9105d59da118286b1f47f80eedb73ee7055dd9020af9f7f5b2675d28e865c953ea77159f7dfbc463a95716b
|
@@ -6,6 +6,7 @@
|
|
6
6
|
#--------------------------------------------------------------------------------------------
|
7
7
|
|
8
8
|
require 'fileutils'
|
9
|
+
require 'active_support/inflector'
|
9
10
|
require_relative 'Modelo.rb'
|
10
11
|
require_relative 'Rota.rb'
|
11
12
|
require_relative 'Metodo.rb'
|
@@ -55,29 +56,44 @@ class FileHandler
|
|
55
56
|
Dir.glob(path + 'api/models/*.rb') do |file|
|
56
57
|
filename = file.to_s
|
57
58
|
inputFile = File.new(filename)
|
59
|
+
modelFile = File.new(filename, 'r')
|
58
60
|
modelname = File.basename(inputFile, '.rb')
|
59
|
-
modelPath = path + 'api/models/' + modelname + '.rb'
|
60
61
|
helpername = path + 'api/app/helpers/' + modelname + '_helper.rb'
|
61
62
|
controllername = path + 'api/app/controllers/' + modelname + '.rb'
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
modelname = nameFormat(modelname)
|
64
|
+
# Call the necessary methods for each helper, model and controller
|
65
|
+
relations = readRelations(modelFile, modelname, filename)
|
66
|
+
modelFile.close
|
67
|
+
if File.exist?(helpername)
|
65
68
|
modelHelper = File.new(helpername, 'r')
|
66
|
-
modelController = File.new(controllername, 'r')
|
67
|
-
relations = readRelations(modelFile, modelname, modelPath)
|
68
69
|
methods = readMethods(modelHelper, helpername)
|
69
|
-
routes = readRoutes(modelController, controllername)
|
70
|
-
currentModel = Modelo.new(modelname, methods, routes, relations)
|
71
|
-
models << currentModel
|
72
|
-
modelFile.close
|
73
70
|
modelHelper.close
|
71
|
+
end
|
72
|
+
if File.exist?(controllername)
|
73
|
+
modelController = File.new(controllername, 'r')
|
74
|
+
routes = readRoutes(modelController, controllername)
|
74
75
|
modelController.close
|
75
76
|
end
|
77
|
+
currentModel = Modelo.new(modelname, methods, routes, relations)
|
78
|
+
models << currentModel
|
79
|
+
methods = nil
|
80
|
+
routes = nil
|
81
|
+
relations = nil
|
76
82
|
end
|
77
83
|
# Return models
|
78
84
|
models
|
79
85
|
end
|
80
86
|
|
87
|
+
def nameFormat(name)
|
88
|
+
name = name.capitalize
|
89
|
+
if name.include?("_")
|
90
|
+
prefix = name.slice(0, name.index("_"))
|
91
|
+
sulfix = name.slice(name.index("_")+1, name.length - name.index("_"))
|
92
|
+
name = "#{prefix.capitalize} #{sulfix.capitalize}"
|
93
|
+
end
|
94
|
+
name
|
95
|
+
end
|
96
|
+
|
81
97
|
# Auxiliary methods of reading
|
82
98
|
|
83
99
|
# Generate project descriprion based on 'README.md'
|
@@ -166,31 +182,37 @@ class FileHandler
|
|
166
182
|
def readRelations(modelFile, modelname, modelPath)
|
167
183
|
lineIndex = 0
|
168
184
|
relations = []
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
#
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
185
|
+
begin
|
186
|
+
arr = IO.readlines(modelFile)
|
187
|
+
# Read each line from model
|
188
|
+
arr.each do |line|
|
189
|
+
lineIndex += 1
|
190
|
+
# Verify presence of any clause
|
191
|
+
if hasKeyword?(line, lineIndex, modelname)
|
192
|
+
# If it does, identify which clause it is
|
193
|
+
arg = decodeArgument(line)
|
194
|
+
keyword = arg[0]
|
195
|
+
argument = arg[1]
|
196
|
+
# Execute clause
|
197
|
+
case keyword
|
198
|
+
when 'belongs_to'
|
199
|
+
relation = modelname + ' belongs to ' + argument
|
200
|
+
relations << relation
|
201
|
+
when 'has_one'
|
202
|
+
relation = modelname + ' has one ' + argument
|
203
|
+
relations << relation
|
204
|
+
when 'has_many'
|
205
|
+
relation = modelname + ' has many ' + argument.pluralize
|
206
|
+
relations << relation
|
207
|
+
when 'has_and_belongs_to_many'
|
208
|
+
relation = modelname + ' has and belongs to many ' + argument.pluralize
|
209
|
+
relations << relation
|
210
|
+
end
|
192
211
|
end
|
193
212
|
end
|
213
|
+
rescue ArgumentError => e
|
214
|
+
# If a syntax error is found, it raises an Argument Error informing the file and line
|
215
|
+
puts "Warning: #{modelPath}:#{lineIndex} " + e.message
|
194
216
|
end
|
195
217
|
relations
|
196
218
|
end
|
@@ -249,9 +271,8 @@ class FileHandler
|
|
249
271
|
descricao = decodeDescription(line) if hasDescription?(line, lineIndex, helpername)
|
250
272
|
end
|
251
273
|
rescue ArgumentError => e
|
252
|
-
# If a syntax error is found, it
|
253
|
-
puts "
|
254
|
-
puts e.message
|
274
|
+
# If a syntax error is found, it raises an Argument Error informing the file and line
|
275
|
+
puts "Warning: #{helpername}:#{lineIndex}: in #{nome} " + e.message
|
255
276
|
end
|
256
277
|
methods << Metodo.new(nome, tipo, inputs, outputs, descricao)
|
257
278
|
# Return a methods array
|
@@ -345,9 +366,8 @@ class FileHandler
|
|
345
366
|
end
|
346
367
|
end
|
347
368
|
rescue ArgumentError => e
|
348
|
-
# If a syntax error is found, it
|
349
|
-
puts "
|
350
|
-
puts e.message
|
369
|
+
# If a syntax error is found, it raises an Argument Error informing the file and line
|
370
|
+
puts "Warning: #{controllername}:#{lineIndex}: in #{nome} " + e.message
|
351
371
|
end
|
352
372
|
routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
|
353
373
|
# Return a routes array
|
@@ -408,23 +428,30 @@ class FileHandler
|
|
408
428
|
def decodeArgument(line)
|
409
429
|
args = []
|
410
430
|
initialIndex = line.index('@') + 1
|
431
|
+
sentence = line.slice(initialIndex, line.length - initialIndex)
|
432
|
+
# Raises an Argument Error if some error is found
|
433
|
+
raise ArgumentError.new("Sytanx error: expected 2 arguments (none given)") unless hasSomething?(sentence)
|
434
|
+
raise ArgumentError.new("Sytanx error: expected 2 arguments (one given)") unless sentence.include?("\s")
|
411
435
|
finalIndex = line.index("\s", line.index('@'))
|
412
|
-
if finalIndex == nil || initialIndex == nil
|
413
|
-
if line.index('@')+1 == /^[[:alpha:]]$/
|
414
|
-
# Raises an Argument Error if some error is found
|
415
|
-
raise ArgumentError.new("Sytanx error: expected 2 arguments (one given)")
|
416
|
-
else raise ArgumentError.new("Sytanx error: expected 2 arguments (none given)")
|
417
|
-
end
|
418
|
-
end
|
419
436
|
lenght = finalIndex - initialIndex
|
420
437
|
keyword = line.slice(initialIndex, lenght)
|
421
438
|
argument = line.slice(finalIndex + 1, line.size - finalIndex)
|
439
|
+
raise ArgumentError.new("Sytanx error: expected 2 arguments (one given)") unless hasSomething?(argument)
|
422
440
|
args << keyword
|
423
441
|
args << argument
|
424
442
|
# Return array with clause and arguments
|
425
443
|
args
|
426
444
|
end
|
427
445
|
|
446
|
+
def hasSomething?(line)
|
447
|
+
for i in 0..line.length-1
|
448
|
+
if line[i].match(/^[[:alpha:]]$/)
|
449
|
+
return true
|
450
|
+
end
|
451
|
+
end
|
452
|
+
false
|
453
|
+
end
|
454
|
+
|
428
455
|
# If the clause is a param or return value, decode the name and datatype
|
429
456
|
def dataValue(argument)
|
430
457
|
if argument.include? "\s"
|
@@ -576,11 +603,13 @@ class FileHandler
|
|
576
603
|
<div class='row'>
|
577
604
|
<div class='col-md-4'>
|
578
605
|
<ul class='list-group'>")
|
579
|
-
models.
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
606
|
+
unless models.nil?
|
607
|
+
models.each do |model|
|
608
|
+
link = model.name.downcase
|
609
|
+
name = model.name
|
610
|
+
file.write("\t\t<a href='models/#{link}.html' class='list-indexes list-group-item'>#{name}</a>
|
611
|
+
")
|
612
|
+
end
|
584
613
|
end
|
585
614
|
file.write("\t</ul>
|
586
615
|
</div>
|
@@ -594,8 +623,10 @@ class FileHandler
|
|
594
623
|
|
595
624
|
# Write a model HTML page content
|
596
625
|
def writeModelPage(file, model, project)
|
597
|
-
name = model.name
|
626
|
+
name = model.name
|
598
627
|
relations = model.relations
|
628
|
+
methods = model.methods
|
629
|
+
routes = model.routes
|
599
630
|
file.write("<div class='container panel panel-default'>
|
600
631
|
<div class='row'>
|
601
632
|
<div class='panel panel-default'>
|
@@ -605,8 +636,10 @@ class FileHandler
|
|
605
636
|
<div class='panel-body'>
|
606
637
|
<h2>#{name} Model</h2>
|
607
638
|
<h4>")
|
608
|
-
relations.
|
609
|
-
|
639
|
+
unless relations.nil?
|
640
|
+
relations.each do |relation|
|
641
|
+
file.write('<br>'+relation)
|
642
|
+
end
|
610
643
|
end
|
611
644
|
file.write("</h4>
|
612
645
|
</div>
|
@@ -620,35 +653,40 @@ class FileHandler
|
|
620
653
|
</div>
|
621
654
|
</div>
|
622
655
|
<ul class='list-group'>")
|
623
|
-
methods
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
<ul>")
|
634
|
-
inputs.each do |input|
|
635
|
-
type = input.type
|
636
|
-
name = input.name
|
637
|
-
file.write("<li>#{type}: #{name}</li>")
|
638
|
-
end
|
639
|
-
file.write("</ul><br>Outputs:<br>
|
656
|
+
unless methods.nil?
|
657
|
+
methods.each do |method|
|
658
|
+
type = method.type
|
659
|
+
name = method.name
|
660
|
+
inputs = method.inputs
|
661
|
+
outputs = method.outputs
|
662
|
+
description = method.description
|
663
|
+
file.write(" <div class='list-group-item'>
|
664
|
+
<h4 class='list-group-item-heading'>CRUD: #{type}<br>Name: #{name}</h4>
|
665
|
+
<p><br>Inputs:<br>
|
640
666
|
<ul>")
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
file.write('<li>Null</li>')
|
667
|
+
unless inputs.nil?
|
668
|
+
inputs.each do |input|
|
669
|
+
type = input.type
|
670
|
+
name = input.name
|
671
|
+
file.write("<li>#{type}: #{name}</li>")
|
672
|
+
end
|
648
673
|
end
|
674
|
+
file.write("</ul><br>Outputs:<br>
|
675
|
+
<ul>")
|
676
|
+
unless outputs.nil?
|
677
|
+
outputs.each do |output|
|
678
|
+
if output != 'nil'
|
679
|
+
type = output.type
|
680
|
+
name = output.name
|
681
|
+
file.write("<li>#{type}: #{name}</li>")
|
682
|
+
else
|
683
|
+
file.write('<li>Null</li>')
|
684
|
+
end
|
685
|
+
end
|
686
|
+
end
|
687
|
+
file.write("</ul><br>Description: #{description}</p>
|
688
|
+
</div>")
|
649
689
|
end
|
650
|
-
file.write("</ul><br>Description: #{description}</p>
|
651
|
-
</div>")
|
652
690
|
end
|
653
691
|
file.write("</ul>
|
654
692
|
</div>
|
@@ -659,38 +697,43 @@ class FileHandler
|
|
659
697
|
</div>
|
660
698
|
</div>
|
661
699
|
<ul class='list-group'>")
|
662
|
-
routes
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
<ul>")
|
676
|
-
inputs.each do |input|
|
677
|
-
type = input.type
|
678
|
-
name = input.name
|
679
|
-
file.write("<li>#{type}: #{name}</li>")
|
680
|
-
end
|
681
|
-
file.write("</ul><br>Outputs:<br>
|
700
|
+
unless routes.nil?
|
701
|
+
routes.each do |route|
|
702
|
+
type = route.type
|
703
|
+
name = route.name
|
704
|
+
request = route.request
|
705
|
+
dataInput = route.dataInput
|
706
|
+
inputs = route.inputs
|
707
|
+
outputs = route.outputs
|
708
|
+
file.write(" <div class='list-group-item'>
|
709
|
+
<h4 class='list-group-item-heading'>CRUD: #{type}<br>Name: #{name}</h4>
|
710
|
+
<p><br>Request: #{request}<br>
|
711
|
+
<br>Notation type: #{dataInput}<br>
|
712
|
+
<br>Inputs:<br>
|
682
713
|
<ul>")
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
714
|
+
unless inputs.nil?
|
715
|
+
inputs.each do |input|
|
716
|
+
type = input.type
|
717
|
+
name = input.name
|
718
|
+
file.write("<li>#{type}: #{name}</li>")
|
719
|
+
end
|
720
|
+
end
|
721
|
+
file.write("</ul><br>Outputs:<br>
|
722
|
+
<ul>")
|
723
|
+
unless outputs.nil?
|
724
|
+
outputs.each do |output|
|
725
|
+
if output != 'nil'
|
726
|
+
type = output.type
|
727
|
+
name = output.name
|
728
|
+
file.write("<li>#{type}: #{name}</li>")
|
729
|
+
else
|
730
|
+
file.write('<li>Null</li>')
|
731
|
+
end
|
732
|
+
end
|
690
733
|
end
|
734
|
+
file.write("</ul></p>
|
735
|
+
</div>")
|
691
736
|
end
|
692
|
-
file.write("</ul></p>
|
693
|
-
</div>")
|
694
737
|
end
|
695
738
|
file.write("</ul>
|
696
739
|
</div>
|
metadata
CHANGED
@@ -1,32 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phari_doc_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phari Solutions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2-
|
14
14
|
Hi there buddy! I've heard you've been looking for a simple
|
15
15
|
and functional documentation generator for this Ruby web app
|
16
|
-
of yours.
|
17
|
-
|
18
|
-
To use this gem, you will need to be following the sinatra/padrino
|
19
|
-
patterns. If you're using these 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
|
16
|
+
of yours. Phari Doc Generator will provide you an easy way
|
17
|
+
to generate documentation for your projects. The result
|
27
18
|
will be a project page with a description that can be written using a simplified
|
28
19
|
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 controller
|
20
|
+
Class will have it's own page especifying it's relatios helper methods and controller
|
30
21
|
routes including their inputs, outputs and descriptions. The gem includes
|
31
22
|
an executable file and the classes that can be used individually,
|
32
23
|
providing the possibility to use the generator for any project
|