forked from danbernier/WordCram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docgen.rb
34 lines (26 loc) · 873 Bytes
/
docgen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# use java annotations instead?
# http://download.oracle.com/javase/tutorial/java/javaOO/annotations.html?
# though they'll wind up in the .jar, and probably in the P5 imports...
files = Dir.glob('src/**/*.java')
examples = Hash.new
files.each do |file|
src = File.read(file)
class_name = File.basename(file).gsub(/\..*$/, '')
class_examples = src.scan(/\/\/example (.*)$/).flatten.compact
examples[class_name] = class_examples unless class_examples.empty?
end
#puts examples
#puts '='*80
publics = files.map do |file|
src = File.read(file)
src.scan(/public .*$/)
end
publics = publics.flatten.compact
#puts publics
#puts '='*80
files.each do |file|
src = File.read(file)
docs = src.scan(/\/\*\=(.*)\=\*\//m).flatten.compact
docs.map! { |doc| doc.gsub(/^\s*\*\s*/, '') }
puts docs.join("\n"*3) unless docs.empty?
end