docrb 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +31 -41
- data/Gemfile +5 -1
- data/Gemfile.lock +28 -13
- data/docrb.gemspec +3 -5
- data/exe/docrb +39 -57
- data/lib/docrb/doc_compiler.rb +7 -47
- data/lib/docrb/version.rb +1 -1
- data/lib/docrb.rb +15 -54
- metadata +8 -55
- data/lib/docrb/comment_parser/code_example_block.rb +0 -36
- data/lib/docrb/comment_parser/code_example_parser.rb +0 -29
- data/lib/docrb/comment_parser/field_block.rb +0 -18
- data/lib/docrb/comment_parser/field_list_parser.rb +0 -90
- data/lib/docrb/comment_parser/text_block.rb +0 -43
- data/lib/docrb/comment_parser.rb +0 -272
- data/lib/docrb/doc_compiler/base_container/computations.rb +0 -178
- data/lib/docrb/doc_compiler/base_container.rb +0 -123
- data/lib/docrb/doc_compiler/doc_attribute.rb +0 -58
- data/lib/docrb/doc_compiler/doc_blocks.rb +0 -111
- data/lib/docrb/doc_compiler/doc_class.rb +0 -43
- data/lib/docrb/doc_compiler/doc_method.rb +0 -66
- data/lib/docrb/doc_compiler/doc_module.rb +0 -9
- data/lib/docrb/doc_compiler/file_ref.rb +0 -41
- data/lib/docrb/doc_compiler/object_container.rb +0 -68
- data/lib/docrb/markdown.rb +0 -62
- data/lib/docrb/module_extensions.rb +0 -13
- data/lib/docrb/resolvable.rb +0 -178
- data/lib/docrb/ruby_parser.rb +0 -630
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0802ce2c22dc5e953086dc6a7ceb943f2698123aa218b84ffe0c12979cf6d8
|
4
|
+
data.tar.gz: e6ffe294b8f3ca2aea65b8a29295c69597241a7369356e48a655dcc4267da2ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5186508c23d6da130f52ca66e704f049c9545ac486faf0da9f93bd72620d5139a4e9835955e419062cbd4a2eeb29c417523253c27e74927a7a29408b151588f
|
7
|
+
data.tar.gz: 8d8c70b0bcacfedea85f401abd53901c3b1835ceadcfc9f8f089a1fef74ec6f1dcb83cc5fb83983f76fc9e9db6c9d8087472717e096099c5f85c2ecb93e677e0
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 3.2
|
3
|
+
SuggestExtensions: false
|
3
4
|
NewCops: enable
|
4
|
-
Exclude:
|
5
|
-
- spec/**/*
|
6
5
|
|
7
6
|
Style/StringLiterals:
|
8
7
|
Enabled: true
|
@@ -12,59 +11,50 @@ Style/StringLiteralsInInterpolation:
|
|
12
11
|
Enabled: true
|
13
12
|
EnforcedStyle: double_quotes
|
14
13
|
|
15
|
-
Style/Documentation:
|
16
|
-
Exclude:
|
17
|
-
- lib/docrb/module_extensions.rb
|
18
|
-
|
19
14
|
Layout/LineLength:
|
20
15
|
Max: 120
|
21
|
-
Exclude:
|
22
|
-
- exe/*
|
23
|
-
- lib/docrb/comment_parser.rb
|
24
|
-
- lib/docrb/ruby_parser.rb
|
25
16
|
|
26
|
-
|
27
|
-
|
17
|
+
Layout/FirstHashElementIndentation:
|
18
|
+
EnforcedStyle: consistent
|
28
19
|
|
29
|
-
|
20
|
+
Layout/EndAlignment:
|
21
|
+
EnforcedStyleAlignWith: start_of_line
|
22
|
+
|
23
|
+
Layout/MultilineMethodCallIndentation:
|
24
|
+
EnforcedStyle: indented
|
25
|
+
|
26
|
+
Style/Documentation:
|
30
27
|
Enabled: false
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
Layout/CaseIndentation:
|
30
|
+
EnforcedStyle: end
|
31
|
+
|
32
|
+
Layout/FirstArgumentIndentation:
|
33
|
+
EnforcedStyle: consistent_relative_to_receiver
|
34
|
+
|
35
|
+
Layout/ArgumentAlignment:
|
36
|
+
EnforcedStyle: with_fixed_indentation
|
37
|
+
|
38
|
+
Style/EmptyCaseCondition:
|
39
|
+
Enabled: false
|
35
40
|
|
36
41
|
Metrics/BlockLength:
|
37
|
-
|
38
|
-
- exe/*
|
39
|
-
- lib/docrb/ruby_parser.rb
|
42
|
+
Enabled: false
|
40
43
|
|
41
|
-
Metrics/
|
42
|
-
|
43
|
-
- exe/*
|
44
|
-
- lib/docrb/doc_compiler/base_container.rb
|
45
|
-
- lib/docrb/doc_compiler/base_container/computations.rb
|
46
|
-
- lib/docrb/doc_compiler/object_container.rb
|
47
|
-
- lib/docrb/resolvable.rb
|
48
|
-
- lib/docrb/ruby_parser.rb
|
44
|
+
Metrics/ClassLength:
|
45
|
+
Enabled: false
|
49
46
|
|
50
|
-
Metrics/
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
- lib/docrb/doc_compiler/object_container.rb
|
56
|
-
- lib/docrb/resolvable.rb
|
57
|
-
- lib/docrb/ruby_parser.rb
|
58
|
-
|
59
|
-
Lint/ShadowingOuterLocalVariable:
|
60
|
-
Exclude:
|
61
|
-
- exe/*
|
47
|
+
Metrics/ModuleLength:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/MethodLength:
|
51
|
+
Enabled: false
|
62
52
|
|
63
53
|
Metrics/AbcSize:
|
64
54
|
Enabled: false
|
65
55
|
|
66
|
-
Metrics/
|
56
|
+
Metrics/CyclomaticComplexity:
|
67
57
|
Enabled: false
|
68
58
|
|
69
|
-
|
59
|
+
Metrics/PerceivedComplexity:
|
70
60
|
Enabled: false
|
data/Gemfile
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
+
gem "docrb-html", path: "../docrb-html"
|
6
|
+
|
7
|
+
gem "docrb-parser", path: "../docrb-parser"
|
8
|
+
|
5
9
|
# Specify your gem's dependencies in docrb.gemspec
|
6
10
|
gemspec
|
7
11
|
|
@@ -10,7 +14,7 @@ group :development do
|
|
10
14
|
|
11
15
|
gem "rspec", "~> 3.0"
|
12
16
|
|
13
|
-
gem "rubocop", "~> 1.
|
17
|
+
gem "rubocop", "~> 1.21"
|
14
18
|
|
15
19
|
gem "byebug"
|
16
20
|
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,24 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ../docrb-html
|
3
3
|
specs:
|
4
|
-
docrb (0.
|
5
|
-
|
6
|
-
parser (~> 3.2)
|
4
|
+
docrb-html (0.3.0)
|
5
|
+
nokogiri (~> 1.14)
|
7
6
|
redcarpet (~> 3.6)
|
8
7
|
rouge (~> 4.1)
|
8
|
+
sassc (~> 2.4)
|
9
|
+
|
10
|
+
PATH
|
11
|
+
remote: ../docrb-parser
|
12
|
+
specs:
|
13
|
+
docrb-parser (0.1.0)
|
14
|
+
prism (~> 0.13)
|
15
|
+
|
16
|
+
PATH
|
17
|
+
remote: .
|
18
|
+
specs:
|
19
|
+
docrb (0.3.0)
|
20
|
+
docrb-html (~> 0.3)
|
21
|
+
docrb-parser (~> 0.1)
|
9
22
|
|
10
23
|
GEM
|
11
24
|
remote: https://rubygems.org/
|
@@ -14,25 +27,23 @@ GEM
|
|
14
27
|
awesome_print (1.9.2)
|
15
28
|
byebug (11.1.3)
|
16
29
|
diff-lcs (1.5.0)
|
17
|
-
|
18
|
-
nokogiri (~> 1.14)
|
19
|
-
sassc (~> 2.4)
|
20
|
-
ffi (1.15.5)
|
30
|
+
ffi (1.16.3)
|
21
31
|
json (2.6.3)
|
22
|
-
nokogiri (1.
|
32
|
+
nokogiri (1.15.4-arm64-darwin)
|
23
33
|
racc (~> 1.4)
|
24
|
-
nokogiri (1.
|
34
|
+
nokogiri (1.15.4-x86_64-darwin)
|
25
35
|
racc (~> 1.4)
|
26
36
|
parallel (1.22.1)
|
27
37
|
parser (3.2.1.0)
|
28
38
|
ast (~> 2.4.1)
|
29
|
-
|
39
|
+
prism (0.14.0)
|
40
|
+
racc (1.7.1)
|
30
41
|
rainbow (3.1.1)
|
31
42
|
rake (13.0.6)
|
32
43
|
redcarpet (3.6.0)
|
33
44
|
regexp_parser (2.7.0)
|
34
45
|
rexml (3.2.5)
|
35
|
-
rouge (4.
|
46
|
+
rouge (4.2.0)
|
36
47
|
rspec (3.12.0)
|
37
48
|
rspec-core (~> 3.12.0)
|
38
49
|
rspec-expectations (~> 3.12.0)
|
@@ -65,15 +76,19 @@ GEM
|
|
65
76
|
|
66
77
|
PLATFORMS
|
67
78
|
arm64-darwin-22
|
79
|
+
arm64-darwin-23
|
68
80
|
x86_64-darwin-20
|
81
|
+
x86_64-darwin-22
|
69
82
|
|
70
83
|
DEPENDENCIES
|
71
84
|
awesome_print
|
72
85
|
byebug
|
73
86
|
docrb!
|
87
|
+
docrb-html!
|
88
|
+
docrb-parser!
|
74
89
|
rake (~> 13.0)
|
75
90
|
rspec (~> 3.0)
|
76
|
-
rubocop (~> 1.
|
91
|
+
rubocop (~> 1.21)
|
77
92
|
|
78
93
|
BUNDLED WITH
|
79
94
|
2.2.22
|
data/docrb.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = "#{spec.homepage}/tree/trunk/lib/docrb"
|
19
19
|
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
20
21
|
|
21
22
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
23
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
@@ -25,9 +26,6 @@ Gem::Specification.new do |spec|
|
|
25
26
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
27
|
spec.require_paths = ["lib"]
|
27
28
|
|
28
|
-
spec.add_dependency "docrb-html", "~> 0.
|
29
|
-
spec.add_dependency "parser", "~>
|
30
|
-
spec.add_dependency "redcarpet", "~> 3.6"
|
31
|
-
spec.add_dependency "rouge", "~> 4.1"
|
32
|
-
spec.metadata["rubygems_mfa_required"] = "true"
|
29
|
+
spec.add_dependency "docrb-html", "~> 0.3"
|
30
|
+
spec.add_dependency "docrb-parser", "~> 0.1"
|
33
31
|
end
|
data/exe/docrb
CHANGED
@@ -7,12 +7,11 @@ require "fileutils"
|
|
7
7
|
require "optparse"
|
8
8
|
require "open3"
|
9
9
|
require "tmpdir"
|
10
|
-
require "renderer"
|
11
10
|
|
12
11
|
require "docrb"
|
13
12
|
|
14
|
-
def exec(cmd,
|
15
|
-
_, stdout_and_err, wait_thread = Open3.popen2e(cmd,
|
13
|
+
def exec(cmd, *, **)
|
14
|
+
_, stdout_and_err, wait_thread = Open3.popen2e(cmd, *, **)
|
16
15
|
status = wait_thread.value
|
17
16
|
{
|
18
17
|
code: status.exitstatus,
|
@@ -20,57 +19,55 @@ def exec(cmd, *args, **kwargs)
|
|
20
19
|
}
|
21
20
|
end
|
22
21
|
|
23
|
-
def git(
|
24
|
-
exec("git", *args, **kwargs)
|
25
|
-
end
|
26
|
-
|
27
|
-
def render_html(*args, **kwargs)
|
28
|
-
exec("docrb-html", *args, **kwargs)
|
29
|
-
end
|
22
|
+
def git(*, **) = exec("git", *, **)
|
30
23
|
|
31
24
|
def run
|
32
25
|
options = {}
|
33
|
-
opts = OptionParser.new do |
|
34
|
-
|
35
|
-
gemspec_info = "When omitted, Docrb attempts to extract information from
|
26
|
+
opts = OptionParser.new do |opt|
|
27
|
+
opt.banner = "Usage: bin/docrb [options] [input directory] [output directory]"
|
28
|
+
gemspec_info = "When omitted, Docrb attempts to extract information from " \
|
29
|
+
"a .gemspec file in the provided input directory."
|
36
30
|
|
37
|
-
|
38
|
-
puts
|
31
|
+
opt.on("--help", "Prints this help") do
|
32
|
+
puts opt
|
39
33
|
exit
|
40
34
|
end
|
41
35
|
|
42
|
-
|
43
|
-
|
36
|
+
opt.on("-bPATH", "--base=PATH",
|
37
|
+
"Base directory to search for source files. Defaults to the provided input directory.") do |b|
|
44
38
|
options[:base] = b
|
45
39
|
end
|
46
40
|
|
47
|
-
|
48
|
-
|
41
|
+
opt.on("-rPATH", "--readme=PATH",
|
42
|
+
"Path for README.md file. When omitted, Docrb searches for a README.md " \
|
43
|
+
"file in the provided input directory.") do |r|
|
49
44
|
options[:readme] = r
|
50
45
|
end
|
51
46
|
|
52
|
-
|
47
|
+
opt.on("-nNAME", "--name=NAME", "Name of the project being documented. #{gemspec_info}") do |n|
|
53
48
|
options[:name] = n
|
54
49
|
end
|
55
50
|
|
56
|
-
|
51
|
+
opt.on("-sSUMMARY", "--summary=SUMMARY", "Short summary of the project being documented. #{gemspec_info}") do |d|
|
57
52
|
options[:summary] = d
|
58
53
|
end
|
59
54
|
|
60
|
-
|
55
|
+
opt.on("-hURL", "--host=URL", "URL for the gem's hosted URL. #{gemspec_info}") do |u|
|
61
56
|
options[:host_url] = u
|
62
57
|
end
|
63
58
|
|
64
|
-
|
65
|
-
|
59
|
+
opt.on("-gURL", "--git-repo=URL",
|
60
|
+
"URL for the repository containing the documented project. When " \
|
61
|
+
"omitted, Docrb attempts to extract this information from the " \
|
62
|
+
".git directory present in the provided input directory, if any.") do |u|
|
66
63
|
options[:git_url] = u
|
67
64
|
end
|
68
65
|
|
69
|
-
|
66
|
+
opt.on("--authors a,b,c", "List of name of project authors. #{gemspec_info}") do |list|
|
70
67
|
options[:authors] = list
|
71
68
|
end
|
72
69
|
|
73
|
-
|
70
|
+
opt.on("-lLICENSE", "--license=LICENSE", "The project's license. #{gemspec_info}") do |license|
|
74
71
|
options[:license] = license
|
75
72
|
end
|
76
73
|
end
|
@@ -104,10 +101,6 @@ def run
|
|
104
101
|
end
|
105
102
|
end
|
106
103
|
|
107
|
-
tmp_output = Dir.mktmpdir
|
108
|
-
data_path = File.join(tmp_output, "data.json")
|
109
|
-
markdown_path = File.join(tmp_output, "readme.html")
|
110
|
-
metadata_path = File.join(tmp_output, "metadata.json")
|
111
104
|
readme_path = File.join(input, "README.md")
|
112
105
|
base_path = input
|
113
106
|
|
@@ -119,7 +112,16 @@ def run
|
|
119
112
|
end
|
120
113
|
end
|
121
114
|
|
122
|
-
|
115
|
+
if options[:base]
|
116
|
+
path = File.join(input, options[:base])
|
117
|
+
unless File.exist? path
|
118
|
+
puts "--base was provided, but #{path} does not exist."
|
119
|
+
exit(1)
|
120
|
+
end
|
121
|
+
base_path = path
|
122
|
+
end
|
123
|
+
|
124
|
+
source, spec = Docrb.parse_folder(base_path, input)
|
123
125
|
|
124
126
|
%i[name summary host_url git_url authors license].each do |k|
|
125
127
|
spec[k] = options[k] if options.key? k
|
@@ -131,25 +133,17 @@ def run
|
|
131
133
|
end
|
132
134
|
|
133
135
|
if spec[:summary] == "" || spec[:summary].nil?
|
134
|
-
puts "Docrb could not detect the project's summary. Please check your
|
136
|
+
puts "Docrb could not detect the project's summary. Please check your " \
|
137
|
+
".gemspec, or provide one manually using --summary."
|
135
138
|
exit(1)
|
136
139
|
end
|
137
140
|
|
138
|
-
if options[:base]
|
139
|
-
path = File.join(input, options[:base])
|
140
|
-
unless File.exist? path
|
141
|
-
puts "--base was provided, but #{path} does not exist."
|
142
|
-
exit(1)
|
143
|
-
end
|
144
|
-
base_path = path
|
145
|
-
end
|
146
|
-
|
147
141
|
git_tip = nil
|
148
142
|
git_root = nil
|
149
143
|
git_status = git("status", "--porcelain", chdir: input)
|
150
144
|
if (git_status[:code]).zero?
|
151
145
|
if git_status[:output].length.positive?
|
152
|
-
puts "WARNING: Your local git copy seems to be dirty. Consider
|
146
|
+
puts "WARNING: Your local git copy seems to be dirty. Consider committing your changes before generating docs."
|
153
147
|
end
|
154
148
|
tip_data = git("rev-parse", "HEAD", chdir: input)
|
155
149
|
if tip_data[:code] != 0
|
@@ -179,27 +173,15 @@ def run
|
|
179
173
|
spec[:timestamp] = Time.now.utc.strftime("%A, %d %b %Y %l:%M %p GMT")
|
180
174
|
spec[:version] = Docrb::VERSION
|
181
175
|
|
182
|
-
data = Docrb.parse_folder(base_path)
|
183
|
-
compiler = Docrb::DocCompiler.new
|
184
|
-
data.each { |f| compiler.append(f) }
|
185
|
-
|
186
|
-
File.write(data_path, compiler.to_h.to_json)
|
187
|
-
puts "Created: #{data_path}"
|
188
|
-
|
189
176
|
if File.exist? readme_path
|
190
|
-
puts "Found #{readme_path}"
|
191
177
|
md = File.read(readme_path).to_s
|
192
|
-
|
193
|
-
File.write(markdown_path, result)
|
194
|
-
puts "Created #{markdown_path}"
|
178
|
+
spec[:readme] = md
|
195
179
|
else
|
196
180
|
puts "#{readme_path} does not exist. Skipping..."
|
197
181
|
end
|
198
|
-
File.write(metadata_path, spec.to_json)
|
199
|
-
puts "Created #{metadata_path}"
|
200
182
|
|
201
|
-
|
202
|
-
|
183
|
+
compiler = Docrb::DocCompiler.new(source, spec, output)
|
184
|
+
compiler.run!
|
203
185
|
end
|
204
186
|
|
205
187
|
run
|
data/lib/docrb/doc_compiler.rb
CHANGED
@@ -1,55 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Docrb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
autoload :DocClass, "docrb/doc_compiler/doc_class"
|
10
|
-
autoload :DocModule, "docrb/doc_compiler/doc_module"
|
11
|
-
autoload :DocMethod, "docrb/doc_compiler/doc_method"
|
12
|
-
autoload :DocAttribute, "docrb/doc_compiler/doc_attribute"
|
13
|
-
autoload :ObjectContainer, "docrb/doc_compiler/object_container"
|
14
|
-
autoload :DocBlocks, "docrb/doc_compiler/doc_blocks"
|
15
|
-
|
16
|
-
attr_reader :classes, :modules, :methods, :parent
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
super
|
20
|
-
@classes = ObjectContainer.new(self, DocClass)
|
21
|
-
@modules = ObjectContainer.new(self, DocModule)
|
22
|
-
@methods = ObjectContainer.new(self, DocMethod)
|
23
|
-
@parent = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
# Appends a given object to the compiler collection. Raises ArgumentError in
|
27
|
-
# case the object cannot be appended to the current container.
|
28
|
-
#
|
29
|
-
# obj - Object to be appended
|
30
|
-
def append(obj)
|
31
|
-
filename = obj[:filename]
|
32
|
-
target = case obj[:type]
|
33
|
-
when :module
|
34
|
-
@modules
|
35
|
-
when :class
|
36
|
-
@classes
|
37
|
-
when :def, :defs
|
38
|
-
@methods
|
39
|
-
end
|
40
|
-
|
41
|
-
raise ArgumentError, "cannot append obj of type #{obj[:type]}" if target.nil?
|
42
|
-
|
43
|
-
target.push(filename, obj)
|
4
|
+
class DocCompiler
|
5
|
+
def initialize(source, spec, output)
|
6
|
+
@source = source
|
7
|
+
@spec = spec
|
8
|
+
@output = output
|
44
9
|
end
|
45
10
|
|
46
|
-
|
47
|
-
|
48
|
-
{
|
49
|
-
modules: @modules.map(&:to_h),
|
50
|
-
classes: @classes.map(&:to_h),
|
51
|
-
methods: @methods.map(&:to_h)
|
52
|
-
}
|
11
|
+
def run!
|
12
|
+
Renderer.new(@source, @spec, @output).render
|
53
13
|
end
|
54
14
|
end
|
55
15
|
end
|
data/lib/docrb/version.rb
CHANGED
data/lib/docrb.rb
CHANGED
@@ -1,71 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "parser/current"
|
4
|
-
require "forwardable"
|
5
3
|
require "json"
|
6
|
-
require "redcarpet"
|
7
|
-
require "rouge"
|
8
|
-
require "rouge/plugins/redcarpet"
|
9
4
|
require "rubygems"
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
Parser::Builders::Default.emit_encoding = true
|
14
|
-
Parser::Builders::Default.emit_index = true
|
15
|
-
Parser::Builders::Default.emit_arg_inside_procarg0 = true
|
16
|
-
Parser::Builders::Default.emit_forward_arg = true
|
17
|
-
Parser::Builders::Default.emit_kwargs = true
|
18
|
-
Parser::Builders::Default.emit_match_pattern = true
|
6
|
+
require "docrb-html"
|
7
|
+
require "docrb-parser"
|
19
8
|
|
20
|
-
require_relative "docrb/
|
21
|
-
require_relative "docrb/
|
22
|
-
require_relative "docrb/module_extensions"
|
9
|
+
require_relative "docrb/spec"
|
10
|
+
require_relative "docrb/doc_compiler"
|
23
11
|
|
24
12
|
# Docrb implements a source and documentation parser for Ruby projects
|
25
13
|
module Docrb
|
26
14
|
# Error class from which all other Docrb errors derive from
|
27
15
|
class Error < StandardError; end
|
28
16
|
|
29
|
-
|
30
|
-
autoload :DocCompiler, "docrb/doc_compiler"
|
31
|
-
autoload :Resolvable, "docrb/resolvable"
|
32
|
-
autoload :Markdown, "docrb/markdown"
|
33
|
-
autoload :Spec, "docrb/spec"
|
34
|
-
|
35
|
-
# Public: Parses a single file under a provided path
|
36
|
-
#
|
37
|
-
# path - Path to the file to be parsed
|
38
|
-
#
|
39
|
-
# Returns an object representing the parsed source and documentation
|
40
|
-
def self.parse(path)
|
41
|
-
inst = RubyParser.new(path)
|
42
|
-
inst.parse
|
43
|
-
inst
|
44
|
-
end
|
45
|
-
|
46
|
-
# Public: Parses a given input folder recursivelly and returns all sources
|
17
|
+
# Public: Parses a given input folder recursively and returns all sources
|
47
18
|
# and documentations
|
48
19
|
#
|
49
|
-
# inp - Folder to be parsed. Finds all .rb files
|
20
|
+
# inp - Folder to be parsed. Finds all .rb files recursively from this path.
|
50
21
|
#
|
51
|
-
# Returns
|
52
|
-
def self.parse_folder(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
inst.modules.each do |c|
|
61
|
-
c[:filename] = f
|
62
|
-
output << c
|
63
|
-
end
|
64
|
-
inst.methods.each do |c|
|
65
|
-
c[:filename] = f
|
66
|
-
output << c
|
67
|
-
end
|
68
|
-
end
|
69
|
-
output
|
22
|
+
# Returns a NodeArray with parsed nodes.
|
23
|
+
def self.parse_folder(base, input)
|
24
|
+
source = Docrb::Parser
|
25
|
+
.new
|
26
|
+
.tap { |parser| Dir["#{base}/**/*.rb"].each { parser.parse(_1) } }
|
27
|
+
.tap(&:finalize)
|
28
|
+
spec = Spec.parse_folder(input)
|
29
|
+
|
30
|
+
[source, spec]
|
70
31
|
end
|
71
32
|
end
|