documentize 0.0.2 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f0ac87e2115d413689eb60d6aca2eaad42e1efe
4
- data.tar.gz: 458eac724e6f5de5806ff591154e8ee2f290b417
3
+ metadata.gz: 57965ec4586ab232786be61504d5fd0df5a7e535
4
+ data.tar.gz: b370f41a42b553ff961b96b1f572e01c8b51b75d
5
5
  SHA512:
6
- metadata.gz: 8372c263379106c63a2739a1e0532841cb6ef19e75e4290f30c4a4c112c32f7d638407251e8fda00cbcfebdd1fa59d06994e2078f73f500f6369a63142f868c5
7
- data.tar.gz: 4978c512666b8ffeb0be77e72096a99331d11bc14056d96f7026d3e790ce5c6d21ab29df0f42746108416b7b7f2d581606990ed2d0b24467af34d554ab19ecab
6
+ metadata.gz: e5df7647a8775c153dc7380d759135907524cd1fef87873688b7274c81c2c4dc2d664e70b164b9750a98845399dc59a63e089bd4a7bbb8d4cfd9d6fd4ee59190
7
+ data.tar.gz: a9b4995a2a0b259f7ffcf4ddf08e3053782ab72916dd87c6782ee944fd6fb962d8ec05f5ae4566c705c60a1d4f76f6635e6a848b0c3d7658a857fce6909f27ad
data/exe/documentize ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'documentize'
4
+
5
+
6
+ doc = Documentize::Documentize.new(ARGV[0])
7
+ ARGV.clear
8
+
9
+ doc.run
data/lib/documentize.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require "documentize/version"
2
+ require "documentize/printer"
3
+ require "documentize/builder"
2
4
  require "documentize/collector"
3
- require "documentize/generator"
5
+ require "documentize/informator"
6
+
4
7
 
5
8
 
6
9
  module Documentize
@@ -10,12 +13,12 @@ module Documentize
10
13
  shbang: /^#!.*?ruby$/
11
14
  }
12
15
 
13
- attr_reader :collector, :file, :header, :tree
16
+ attr_reader :collector, :file, :informator, :header, :tree
14
17
 
15
18
  def initialize(file_name)
16
19
  @file = load_file(file_name)
17
20
  @collector = Collector.new
18
- @generator = Generator.new
21
+ @informator = Informator.new
19
22
  end
20
23
 
21
24
  def load_file(file_name)
@@ -26,7 +29,9 @@ module Documentize
26
29
 
27
30
  def run
28
31
  @tree, @header = collector.run(@file)
29
- # generator.gen_docs(tree)
32
+ informator.gen_info(tree)
33
+ informator.clear_screen
34
+ Printer.print_with_docs(tree)
30
35
  end
31
36
 
32
37
  private
@@ -0,0 +1,64 @@
1
+ module Documentize
2
+ class Builder
3
+
4
+ REGEX = {
5
+ bad_do_block: /\sdo.*?end/,
6
+ do_block: /\sdo[\s\|.*]/
7
+ }
8
+
9
+ def self.build_docs(branch)
10
+ doc_str = ""
11
+ doc_str << "# Public: #{branch[:desc]}\n#\n"
12
+ if branch[:args]
13
+ branch[:args].each do |arg|
14
+ doc_str << "# #{arg[:name]} - #{arg[:type]}: #{arg[:desc]}\n"
15
+ end
16
+ doc_str << "# \n"
17
+ end
18
+ doc_str
19
+ end
20
+
21
+
22
+ def self.build_args(args)
23
+ str = ""
24
+ str << "("
25
+ args.each do |arg|
26
+ str << "#{arg[:name]}"
27
+ str << " = #{arg[:default]}" if arg[:default]
28
+ str << ", " unless arg == args[-1]
29
+ end
30
+ str << ")"
31
+ end
32
+
33
+ def self.build_code(code, indent = 0)
34
+ str = ""
35
+ str << build_docs(code) if code[:doc]
36
+ str << " "*indent
37
+ str << "#{code[:type]} #{code[:name]}"
38
+ str << build_args(code[:args]) if code[:args]
39
+ str << "\n\n"
40
+
41
+ code[:content].each do |item|
42
+ if item.is_a?(Hash)
43
+
44
+ str << build_code(item, indent+1)
45
+
46
+ else
47
+
48
+ indent -= 1 if item =~ /end/ && item !~ REGEX[:bad]
49
+
50
+ str << " "*(indent+1) + "#{item} \n"
51
+ str << "\n" if item =~ /end/ && item !~ REGEX[:bad]
52
+
53
+ indent += 1 if item =~ REGEX[:do_block] && item !~ REGEX[:bad]
54
+
55
+ end
56
+ end
57
+
58
+ str << " "*indent
59
+ str << "end\n"
60
+ indent -= 1
61
+ str << "\n"
62
+ end
63
+ end
64
+ end
@@ -68,7 +68,9 @@ module Documentize
68
68
  items = arg.split("=").map{ |item| item.strip }
69
69
  {
70
70
  name: items[0],
71
- default: items[1]
71
+ default: items[1],
72
+ type: nil,
73
+ test: nil
72
74
  }
73
75
  end
74
76
  end
@@ -83,12 +85,13 @@ module Documentize
83
85
  cmd = breakup[1]
84
86
  end
85
87
  {
86
- type: type,
87
- name: cmd,
88
- args: args,
89
- content: [],
90
- doc: nil
91
- }
88
+ type: type,
89
+ name: cmd,
90
+ desc: nil,
91
+ doc: nil,
92
+ args: args,
93
+ content: [],
94
+ }
92
95
  end
93
96
 
94
97
  def remove_headers(file)
@@ -0,0 +1,93 @@
1
+ module Documentize
2
+ class Informator
3
+
4
+
5
+
6
+ def clear_screen
7
+ system("cls") || system("tput reset") || system("clear") || puts("\e[H\e[2J")
8
+ end
9
+
10
+ def branch_info(branch, parent = nil)
11
+
12
+ display_branch(branch, parent)
13
+
14
+ branch[:desc] = get_desc(branch[:type])
15
+
16
+ get_args(branch) if branch[:args]
17
+
18
+ branch[:content].each do |item|
19
+ branch_info(item, [branch[:name], branch[:type]]) if item.is_a?(Hash)
20
+ end
21
+
22
+ end
23
+
24
+ def display_branch(branch, parent = nil)
25
+ clear_screen unless parent
26
+
27
+ puts line_break
28
+
29
+ print "Describing: #{branch[:name]} #{branch[:type]}"
30
+ print " of #{parent[0]} #{parent[1]}" if parent
31
+ puts
32
+
33
+ puts line_break
34
+
35
+ puts Builder.build_code(branch)
36
+ end
37
+
38
+ def gen_doc(branch)
39
+ branch[:content].each do |item|
40
+ gen_doc(item) if item.is_a?(Hash)
41
+ end
42
+ branch[:doc] = Builder.build_docs(branch)
43
+ end
44
+
45
+ def gen_info(tree)
46
+
47
+ tree.each do |branch|
48
+ branch_info(branch)
49
+ gen_doc(branch)
50
+ end
51
+
52
+ end
53
+
54
+ def get_args(branch)
55
+
56
+ print "#{branch[:type]} #{branch[:name]}"
57
+ print Builder.build_args(branch[:args])
58
+ puts
59
+
60
+ branch[:args].each do |arg|
61
+
62
+ puts "Please enter a brief description of argument: #{arg[:name]}"
63
+ arg[:desc] = gets.strip
64
+
65
+ puts "What input Type should be entered for agument: #{arg[:name]}"
66
+ arg[:type] = gets.strip
67
+
68
+ if arg[:default] == nil
69
+ puts "Please enter a default 'testing' value for Rspec:"
70
+ arg[:test] = gets.strip
71
+ end
72
+
73
+ end
74
+
75
+ branch[:args]
76
+ end
77
+
78
+ def get_desc(type)
79
+
80
+ puts "please enter a description of the above #{type}\n\n"
81
+ gets.strip
82
+
83
+ end
84
+
85
+
86
+
87
+ def line_break
88
+ puts
89
+ puts "--------------------------------------------------"
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,9 @@
1
+ module Documentize
2
+ class Printer
3
+ def self.print_with_docs(tree)
4
+ tree.each do |branch|
5
+ puts Builder.build_code(branch)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Documentize
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: documentize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2016-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,7 +70,8 @@ description: Pass in a cluttered, or just undocumented ruby file and get back a
70
70
  file with a TomDoc Skeleton for easy doc writing
71
71
  email:
72
72
  - sampsonsprojects@gmail.com
73
- executables: []
73
+ executables:
74
+ - documentize
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
@@ -85,9 +86,12 @@ files:
85
86
  - bin/console
86
87
  - bin/setup
87
88
  - documentize.gemspec
89
+ - exe/documentize
88
90
  - lib/documentize.rb
91
+ - lib/documentize/builder.rb
89
92
  - lib/documentize/collector.rb
90
- - lib/documentize/generator.rb
93
+ - lib/documentize/informator.rb
94
+ - lib/documentize/printer.rb
91
95
  - lib/documentize/version.rb
92
96
  - tasks/rspec.rake
93
97
  homepage: https://github.com/SampsonCrowley/documentize
@@ -1,4 +0,0 @@
1
- module Documentize
2
- class Generator
3
- end
4
- end