phari_doc_gen 2.1.2 → 3.0.0

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
  SHA1:
3
- metadata.gz: 002bb604bd3cf81fed17ca3cbde3c7c31fef6ece
4
- data.tar.gz: a2ae0188c765f3f41496df7cb5d8e7b0d5b248ff
3
+ metadata.gz: 06152ff667c5bad361dcb49f7b6b231412085756
4
+ data.tar.gz: 87836418be3a511c0b5c2ff51c73bf3f2e5070dd
5
5
  SHA512:
6
- metadata.gz: feb186e59daeb1f237014415117d2122a13b232f22c4bf73c544133ef7c9ea3c179741211e86b44bc4703ac4af727a1ecd645cb133f39ba3179db73fd295e011
7
- data.tar.gz: 2c8c355e1e0bedc1c89c927bbd8c5b60f6bdef3d90173daf855b7cd01951ea265146a219e2832baf8f802a2cdff294d7ced0452af98997812e180ddc7aa150bf
6
+ metadata.gz: 9417a4c37cecc2b2559b28c9eb944288c8cf39932b4f9a928b91375a6d87b4245215bdba0c7a1e187f873c6ca654612caf028a4bc77220d00e1cc46cc7a3c3a4
7
+ data.tar.gz: bc9d64040b03b4c3a45dc10e8136d912b14615890ca5a9603e06b6818d95f0f6b94dfc1151f63ca24b43ff26659619ff2f628893cc1f9bccd04374b1dbe5257a
data/bin/phari_doc_gen CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'phari_doc_gen'
4
- docGen = PhariDocGen.new()
5
- docGen.generate(ARGV[0], ARGV[1])
4
+ PhariDocGen.generate(ARGV[0], ARGV[1])
data/lib/phari_doc_gen.rb CHANGED
@@ -14,7 +14,7 @@ require_relative 'phari_doc_gen/FileHandler.rb'
14
14
 
15
15
  class PhariDocGen
16
16
  # Generate documentation for standard projects
17
- def generate (project, outputPath)
17
+ def self.generate (project, outputPath)
18
18
  generate = FileHandler.new
19
19
  # Ask for project name if nil
20
20
  if project.nil?
@@ -5,8 +5,6 @@
5
5
  # Luiz Philippe.
6
6
  #--------------------------------------------------------------------------------------------
7
7
 
8
- require 'fileutils'
9
- require 'active_support/inflector'
10
8
  require_relative 'Modelo.rb'
11
9
  require_relative 'Rota.rb'
12
10
  require_relative 'Metodo.rb'
@@ -44,8 +42,13 @@ class FileHandler
44
42
  projectDescription = readProjectDescription(readme)
45
43
  readme.close
46
44
  projectDescription
45
+ elsif File.exists?(path + 'readme.md')
46
+ readme = File.new(path + 'readme.md')
47
+ projectDescription = readProjectDescription(readme)
48
+ readme.close
49
+ projectDescription
47
50
  else
48
- puts 'Warning: No README.md file found.'
51
+ puts 'Warning: No readme.md file found.'
49
52
  end
50
53
  end
51
54
 
@@ -232,56 +235,56 @@ class FileHandler
232
235
  tipo = ''
233
236
  nome = ''
234
237
  descricao = ''
235
- inputs = []
236
- outputs = []
238
+ inputs = {}
239
+ outputs = {}
237
240
  methods = []
238
241
  toSent = true
239
- begin
240
- arr = IO.readlines(helper)
241
- # Read each line from helper
242
- arr.each do |line|
243
- lineIndex += 1
244
- # Verify if it has a clause
245
- if hasKeyword?(line, lineIndex, helpername)
246
- # If it does, identify which clause it is
247
- arg = decodeArgument(line)
248
- keyword = arg[0]
249
- argument = arg[1]
250
- # Execute clause
251
- case keyword
252
- when 'methods'
253
- if nome != ''
254
- methods << Metodo.new(nome, tipo, inputs, outputs, descricao)
255
- inputs = []
256
- outputs = []
257
- toSent = false
258
- end
259
- tipo = argument
260
- when 'name'
261
- if nome != '' && toSent
262
- methods << Metodo.new(nome, tipo, inputs, outputs, descricao)
263
- inputs = []
264
- outputs = []
265
- else
266
- toSent = true
267
- end
268
- nome = argument
269
- when 'param'
270
- data = dataValue(argument)
271
- inputs << data
272
- when 'return'
273
- data = dataValue(argument)
274
- outputs << data
242
+ arr = IO.readlines(helper)
243
+ # Read each line from helper
244
+ arr.each do |line|
245
+ lineIndex += 1
246
+ begin
247
+ # Verify if it has a clause
248
+ if hasKeyword?(line, lineIndex, helpername)
249
+ # If it does, identify which clause it is
250
+ arg = decodeArgument(line)
251
+ keyword = arg[0]
252
+ argument = arg[1]
253
+ # Execute clause
254
+ case keyword
255
+ when 'methods'
256
+ if nome != ''
257
+ methods << Metodo.new(nome, tipo, inputs, outputs, descricao)
258
+ inputs = {}
259
+ outputs = {}
260
+ toSent = false
261
+ end
262
+ tipo = argument
263
+ when 'name'
264
+ if nome != '' && toSent
265
+ methods << Metodo.new(nome, tipo, inputs, outputs, descricao)
266
+ inputs = {}
267
+ outputs = {}
275
268
  else
276
- # If a possible syntax error is found, a warning is sent informing file and linne
277
- puts "Warning: in #{helpername}:#{lineIndex}: #{keyword} is not a keyword" if keyword != 'namespace'
269
+ toSent = true
278
270
  end
271
+ nome = argument
272
+ when 'param'
273
+ data = dataValue(argument, inputs)
274
+ inputs["#{data.name}"] = data unless data.isChild
275
+ when 'return'
276
+ data = dataValue(argument, outputs)
277
+ outputs["#{data.name}"] = data unless data.isChild
278
+ else
279
+ # If a possible syntax error is found, a warning is sent informing file and linne
280
+ puts "Warning: in #{helpername}:#{lineIndex}: #{keyword} is not a keyword" if keyword != 'namespace'
279
281
  end
280
- descricao = decodeDescription(line) if hasDescription?(line, lineIndex, helpername)
281
282
  end
282
- rescue ArgumentError => e
283
- # If a syntax error is found, it raises an Argument Error informing the file and line
284
- puts "Warning: #{helpername}:#{lineIndex}: in #{nome} " + e.message
283
+ descricao = decodeDescription(line) if hasDescription?(line, lineIndex, helpername)
284
+ rescue ArgumentError => e
285
+ # If a syntax error is found, it raises an Argument Error informing the file and line
286
+ puts "Warning: #{helpername}:#{lineIndex}: in #{nome} " + e.message
287
+ end
285
288
  end
286
289
  methods << Metodo.new(nome, tipo, inputs, outputs, descricao)
287
290
  # Return a methods array
@@ -295,88 +298,88 @@ class FileHandler
295
298
  requisicao = ''
296
299
  dataInput = ''
297
300
  nome = ''
298
- inputs = []
299
- outputs = []
301
+ inputs = {}
302
+ outputs = {}
300
303
  routes = []
301
304
  toSent = true
302
- begin
303
- arr = IO.readlines(controller)
304
- # Read each line from controller
305
- arr.each do |line|
306
- lineIndex += 1
307
- # Skip to next line if no clause is found
308
- next unless hasKeyword?(line, lineIndex, controllername)
309
- # If it has any clause, identify which one it is
310
- arg = decodeArgument(line)
311
- keyword = arg[0]
312
- argument = arg[1]
313
- case keyword
314
- # Then execute clause
315
- when 'route'
316
- if nome != ''
317
- routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
318
- inputs = []
319
- outputs = []
320
- toSent = false
321
- end
322
- tipo = argument
323
- when 'POST'
324
- if nome != '' && toSent
325
- routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
326
- inputs = []
327
- outputs = []
328
- else
329
- toSent = true
330
- end
331
- requisicao = keyword
332
- dataInput = argument
333
- when 'GET'
334
- if nome != '' && toSent
335
- routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
336
- inputs = []
337
- outputs = []
338
- else
339
- toSent = true
340
- end
341
- requisicao = keyword
342
- dataInput = argument
343
- when 'PUT'
344
- if nome != '' && toSent
345
- routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
346
- inputs = []
347
- outputs = []
348
- else
349
- toSent = true
350
- end
351
- requisicao = keyword
352
- dataInput = argument
353
- when 'DELETE'
354
- if nome != '' && toSent
355
- routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
356
- inputs = []
357
- outputs = []
358
- else
359
- toSent = true
360
- end
361
- requisicao = keyword
362
- dataInput = argument
363
- when 'name'
364
- nome = argument
365
- when 'param'
366
- data = dataValue(argument)
367
- inputs << data
368
- when 'return'
369
- data = dataValue(argument)
370
- outputs << data
371
- else
372
- # If a possible syntax error is found, a warning is sent informing file and linne
373
- # (Here in the namespace comparison, i'm doing a little mcgyver)
374
- puts "Warning: in #{controllername}:#{lineIndex}: #{keyword} is not a keyword" if keyword != 'namespace'
375
- end
305
+ arr = IO.readlines(controller)
306
+ # Read each line from controller
307
+ arr.each do |line|
308
+ begin
309
+ lineIndex += 1
310
+ # Skip to next line if no clause is found
311
+ next unless hasKeyword?(line, lineIndex, controllername)
312
+ # If it has any clause, identify which one it is
313
+ arg = decodeArgument(line)
314
+ keyword = arg[0]
315
+ argument = arg[1]
316
+ case keyword
317
+ # Then execute clause
318
+ when 'route'
319
+ if nome != ''
320
+ routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
321
+ inputs = {}
322
+ outputs = {}
323
+ toSent = false
324
+ end
325
+ tipo = argument
326
+ when 'POST'
327
+ if nome != '' && toSent
328
+ routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
329
+ inputs = {}
330
+ outputs = {}
331
+ else
332
+ toSent = true
333
+ end
334
+ requisicao = keyword
335
+ dataInput = argument
336
+ when 'GET'
337
+ if nome != '' && toSent
338
+ routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
339
+ inputs = {}
340
+ outputs = {}
341
+ else
342
+ toSent = true
343
+ end
344
+ requisicao = keyword
345
+ dataInput = argument
346
+ when 'PUT'
347
+ if nome != '' && toSent
348
+ routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
349
+ inputs = {}
350
+ outputs = {}
351
+ else
352
+ toSent = true
353
+ end
354
+ requisicao = keyword
355
+ dataInput = argument
356
+ when 'DELETE'
357
+ if nome != '' && toSent
358
+ routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
359
+ inputs = {}
360
+ outputs = {}
361
+ else
362
+ toSent = true
363
+ end
364
+ requisicao = keyword
365
+ dataInput = argument
366
+ when 'name'
367
+ nome = argument
368
+ when 'param'
369
+ data = dataValue(argument, inputs)
370
+ inputs["#{data.name}"] = data unless data.isChild
371
+ when 'return'
372
+ data = dataValue(argument, outputs)
373
+ outputs["#{data.name}"] = data unless data.isChild
374
+ else
375
+ # If a possible syntax error is found, a warning is sent informing file and linne
376
+ # (Here in the namespace comparison, i'm doing a little mcgyver)
377
+ puts "Warning: in #{controllername}:#{lineIndex}: #{keyword} is not a keyword" if keyword != 'namespace'
378
+ end
379
+ rescue ArgumentError => e
380
+ # If a syntax error is found, it raises an Argument Error informing the file and line
381
+ puts "Warning: #{controllername}:#{lineIndex}: in #{nome} " + e.message
376
382
  end
377
- rescue ArgumentError => e
378
- # If a syntax error is found, it raises an Argument Error informing the file and line
379
- puts "Warning: #{controllername}:#{lineIndex}: in #{nome} " + e.message
380
383
  end
381
384
  routes << Rota.new(nome, tipo, requisicao, dataInput, inputs, outputs)
382
385
  # Return a routes array
@@ -401,7 +404,7 @@ class FileHandler
401
404
  return false
402
405
  end
403
406
  end
404
- # Return true if it do
407
+ # Return true if it does
405
408
  true
406
409
  else
407
410
  # And false if it don't
@@ -462,18 +465,45 @@ class FileHandler
462
465
  end
463
466
 
464
467
  # If the clause is a param or return value, decode the name and datatype
465
- def dataValue(argument)
468
+ def dataValue(argument, objects)
466
469
  if argument.include? "\s"
470
+ notNull = true
471
+ isObject = false
472
+ isCollection = false
473
+ isChild = false
467
474
  name = argument.slice(0, argument.index("\s"))
475
+ if name.end_with?('?')
476
+ notNull = false
477
+ name = name.slice(0, name.index('?'))
478
+ end
468
479
  type = argument.slice(argument.index("\s") + 1, argument.size - 2)
469
- data = MethodParam.new(name, type)
480
+ if type.include? "\s"
481
+ example = type.slice(type.index("\s")+1, type.size-1-type.index("\s"))
482
+ type = type.slice(0, type.index("\s"))
483
+ end
484
+ type = type.slice(0, type.size-1) if type.end_with?("\s") || type.end_with?("\n")
485
+ isObject = true if type.downcase == "object"
486
+ if name.include?(">")
487
+ isChild = true
488
+ path = []
489
+ while name.include?(">")
490
+ prefix = name.slice(0, name.index(">"))
491
+ name = name.slice(name.index(">")+1, name.size-(name.index(">")+1))
492
+ path << prefix
493
+ end
494
+ fatherObject = nil
495
+ path.each do |object|
496
+ raise ArgumentError, "Object #{object} does not exists!" unless objects.has_key?(object) && objects["#{object}"].isObject
497
+ fatherObject = objects["#{object}"]
498
+ objects = fatherObject.childAttributes
499
+ end
500
+ end
501
+ data = MethodParam.new(name, type, notNull, isObject, isChild, example)
502
+ fatherObject.addField data unless fatherObject.nil?
470
503
  # Return the data
471
504
  return data
472
505
  elsif argument.include? "nil"
473
- data = MethodParam.new('', 'nil')
474
- return data
475
- elsif argument.include? "boolean"
476
- data = MethodParam.new('', 'boolen')
506
+ data = MethodParam.new('', 'nil', nil, nil, nil, nil)
477
507
  return data
478
508
  end
479
509
  argumentText = argument.slice(0, argument.index("\n"))
@@ -669,25 +699,21 @@ class FileHandler
669
699
  inputs = method.inputs
670
700
  outputs = method.outputs
671
701
  description = method.description
672
- file.write(" <div class='list-group-item'>
702
+ file.write(" <div class='list-group-item'>
673
703
  <h4 class='list-group-item-heading'>CRUD: #{type}<br>Name: #{name}</h4>
674
- <p><br>Inputs:<br>
675
- <ul>")
704
+ <p><br>Inputs:<br><ul>")
676
705
  unless inputs.nil?
677
706
  inputs.each do |input|
678
- type = input.type
679
- name = input.name
680
- file.write("<li>#{type}: #{name}</li>")
707
+ input = input[1]
708
+ file.write("<li>#{input.serialize}</li>")
681
709
  end
682
710
  end
683
- file.write("</ul><br>Outputs:<br>
684
- <ul>")
711
+ file.write("</ul><br>Outputs:<br><ul>")
685
712
  unless outputs.nil?
686
713
  outputs.each do |output|
714
+ output = output[1]
687
715
  if output != 'nil'
688
- type = output.type
689
- name = output.name
690
- file.write("<li>#{type}: #{name}</li>")
716
+ file.write("<li>#{output.serialize}</li>")
691
717
  else
692
718
  file.write('<li>Null</li>')
693
719
  end
@@ -718,23 +744,19 @@ class FileHandler
718
744
  <h4 class='list-group-item-heading'>CRUD: #{type}<br>Name: #{name}</h4>
719
745
  <p><br>Request: #{request}<br>
720
746
  <br>Notation type: #{dataInput}<br>
721
- <br>Inputs:<br>
722
- <ul>")
747
+ <br>Inputs:<br><ul>")
723
748
  unless inputs.nil?
724
749
  inputs.each do |input|
725
- type = input.type
726
- name = input.name
727
- file.write("<li>#{type}: #{name}</li>")
750
+ input = input[1]
751
+ file.write("<li>#{input.serialize}</li>")
728
752
  end
729
753
  end
730
- file.write("</ul><br>Outputs:<br>
731
- <ul>")
754
+ file.write("</ul><br>Outputs:<br><ul>")
732
755
  unless outputs.nil?
733
756
  outputs.each do |output|
757
+ output = output[1]
734
758
  if output != 'nil'
735
- type = output.type
736
- name = output.name
737
- file.write("<li>#{type}: #{name}</li>")
759
+ file.write("<li>#{output.serialize}</li>")
738
760
  else
739
761
  file.write('<li>Null</li>')
740
762
  end
@@ -6,23 +6,44 @@
6
6
  #--------------------------------------------------------------------------------------------
7
7
 
8
8
  class MethodParam
9
- @name = ''
10
- @type = ''
9
+ attr_accessor :name, :type, :notNull, :isObject, :isChild, :example, :childAttributes, :serial
11
10
 
12
- def initialize(givenName, givenType)
13
- @name = givenName
14
- @type = givenType
11
+ def initialize(name = "", type = "", notNull = true, isObject = false, isChild = false, example = nil)
12
+ @name = name
13
+ @type = type
14
+ @notNull = notNull
15
+ @isObject = isObject
16
+ @isChild = isChild
17
+ @example = example
18
+ @childAttributes = {} if @isObject
19
+ @serial = self.serialize
15
20
  end
16
21
 
17
- def type
18
- @type
22
+ def addField attribute
23
+ @childAttributes["#{attribute.name}"] = attribute
24
+ @serial = self.serialize
19
25
  end
20
26
 
21
- def name
22
- @name
27
+ def serialize
28
+ if @type == 'nil'
29
+ serialized = "Null"
30
+ elsif @isObject
31
+ serialized = "#{@name}: {<br><ul>"
32
+ @childAttributes.each do |attribute|
33
+ serialized = serialized + "<li>#{attribute[1].serial}</li>"
34
+ end
35
+ serialized = serialized + "</ul>}"
36
+ else
37
+ unless @example.nil?
38
+ serialized = "#{@name}: #{@example}"
39
+ else
40
+ serialized = "#{@name}: #{@type}"
41
+ end
42
+ end
43
+ serialized
23
44
  end
24
45
 
25
46
  def printSelf
26
- puts"Nome: #{@name}\t\tTipo: #{@type}"
47
+ puts self.serialize
27
48
  end
28
49
  end
metadata CHANGED
@@ -1,28 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phari_doc_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 3.0.0
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-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.1.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.1.4
13
33
  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. Phari Doc Generator will provide you an easy way
34
+ Hi there, friend! PhariDoc Generator is a simple
35
+ and functional documentation generator for Ruby web aps.
36
+ PhariDoc Generator will provide you an easy way
17
37
  to generate documentation for your projects. The result
18
38
  will be a project page with a description that can be written using a simplified
19
- markdown syntax that is going to be explained ahead. Also, each ruby
39
+ markdown syntax. Also, each ruby
20
40
  Class will have it's own page especifying it's relatios helper methods and controller
21
41
  routes including their inputs, outputs and descriptions. The gem includes
22
42
  an executable file and the classes that can be used individually,
23
43
  providing the possibility to use the generator for any project
24
44
  structure.
25
- email: contact@phari.solutions
45
+ email: luiz@phari.solutions
26
46
  executables:
27
47
  - phari_doc_gen
28
48
  extensions: []
@@ -35,7 +55,7 @@ files:
35
55
  - lib/phari_doc_gen/Metodo.rb
36
56
  - lib/phari_doc_gen/Modelo.rb
37
57
  - lib/phari_doc_gen/Rota.rb
38
- homepage: ''
58
+ homepage: https://gitlab.com/LuizPPA/PhariDocGen
39
59
  licenses:
40
60
  - Beerware
41
61
  metadata: {}