/
doc.thor
38 lines (31 loc) · 1.2 KB
/
doc.thor
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
35
36
37
38
require 'rubygems'
gem 'rdoc'
require 'rdoc/rdoc'
require 'fileutils'
require 'erb'
require File.join(File.dirname(__FILE__), 'rdoc', 'generators', 'merb_generator')
$: << File.join(File.join(File.dirname(__FILE__), "rdoc"))
class Doc < Thor
desc "generate PATH", "generate doc for the path passed as an argument"
def generate(path)
path = File.expand_path(path)
readme = File.join(path, "README") || File.join(path, "README.markdown")
# destination => ./generated_doc/project_name
destination = File.join(Dir.pwd, 'generated_doc', File.basename(path))
# cleaning up the folder before generating the doc
FileUtils.rm_rf(destination)
# get all the files to process
files = Dir.glob("#{path}/**/lib/**/*.rb")
files = files.select{|f| f unless f.match(/(generators\/templates|\/spec\d*\/)/) }
# without forgetting the readme file
files += ["#{path}/README"] if File.exists?("#{path}/README")
# rdoc args
arguments = [
"-m", readme,
"--fmt", "merb",
"--op", destination
]
puts "Generating doc for #{File.basename(path)} (#{files.size} files) doc generated to: #{destination}"
RDoc::RDoc.new.document(arguments + files)
end
end