#!/usr/bin/env ruby # Generate rdocs. # # Geneate documentation. This uses the rdoc config entry, # but only documents one designated target at a time. # # NOTE: THIS IS WRITTEN SPECIALLY FOR FACETS!!! RDOC_SETTINGS = YAML.load %{ - title : Facets main : README chdir : lib/core output : doc/rdoc/core - title : Facets chdir : lib/more output : doc/rdoc groups : - [ facets/annotations.rb, facets/settings.rb ] - [ facets/aop.rb, facets/cut.rb ] - [ facets/buildable.rb, facets/buildingblock.rb, facets/hashbuilder.rb ] - [ facets/command.rb, facets/arguments.rb, facets/ansicode.rb ] # facets/bbcode.rb - [ facets/dictionary.rb, facets/orderedhash.rb ] - [ facets/fileable.rb, facets/filelist.rb, facets/pathlist.rb, facets/fileshell.rb ] - [ facets/heap.rb, facets/pqueue.rb ] - [ facets/openobject.rb, facets/opencascade.rb, facets/opencollection.rb, facets/ostruct.rb ] - [ facets/syncarray.rb, facets/synchash.rb ] } RDOC_ADFILE = 'doc/rdoc_ad.html' # Generate rdocs. def rdoc configs = RDOC_SETTINGS configs = [configs] unless Array===configs configs.each do |config| if config['groups'] rdoc_groups(config) else rdoc_target(config) end end puts "RDoc complete." end # Docuement groups of targets. def rdoc_groups(config) site = config.delete('output') || config.delete('op') || 'doc/rdoc' tdir = config['chdir'] groups = config.delete('groups') groups = TrueClass===groups ? [] : groups # the rest rest = [] chdir(tdir){rest=glob('**/*').select{|f| File.file?(f)}} rest = rest - groups.flatten groups.concat(rest.collect{ |r| [r] }) title = config['title'].to_s # rdoc each group groups.each do |group| gf1st = File.basename(group.first) gname = gf1st.chomp(File.extname(gf1st)) gsite = File.join(site,gname) gtitle = "#{title} #{gname.capitalize}".strip gconfig = config.merge('title' => gtitle, 'op' => gsite, 'files' => group) rdoc_target(gconfig) end end # Document target. def rdoc_target(config) config = { 'template' => 'html', 'merge' => true, 'inline-source' => true, }.merge(config) site = config['output'] || 'doc/rdoc' tgdir = config['chdir'] || '.' files = config['files'] || '**/*' main = config['main'] template = config['template'] merge = config['merge'] inline = config['inline'] output = File.expand_path(site) main = File.expand_path(main) if main files = [files].flatten # Remove all old rdocs. fu.rm_r(site) if File.directory?(site) #and safe?(site) otps = [] opts << "--output #{output}" opts << "--main #{main}" if main opts << "--template #{template}" if template opts << "--merge" if merge opts << "--inline-source" if inline cmd = "rdoc #{opts.join(' ')} #{files.join(' ')}" # Create Documentation. Dir.chdir(tgdir) do if dryrun? puts cmd else system cmd end end insert_ads(site) end # Insert ads. def insert_ads(site) adfile = RDOC_ADFILE return unless adfile && File.file?(adfile) adtext = File.read(adfile) #puts dirs = Dir.glob(File.join(site,'*/')) dirs.each do |dir| files = Dir.glob(File.join(dir, '**/*.html')) files.each do |file| html = file_read(file) bodi = html.index('') html[bodi + 7] = "\n" + adtext #print "Augmenting #{file}..." file_write(file, html) unless dryrun? #puts "[done]" end end end # def fu DRYRUN ? FileUtils::Dryrun : FileUtils end # def dryrun? @dryrun ||= ARGV.include?('--dryrun') end # Go! if $0 == __FILE__ rdoc end __END__ # Build RDoc's for each target, # task :rdoc_targets do # # #targets.each do |name, files| # # targets[name] = files.split(/\s+/) if String===files # #end # # # # single = ARGV[0] # # # # Just do the one requested. # # if targets.keys.include?(single) # # targets = { single => targets[single] } # # single_site = File.join(site, single) # # # Remove just the one doc directory. # # rm_r(single_site) if dir?(single_site) and safe?(single_site) # # else # # # Remove all old rdocs. # # rm_r(site) if dir?(site) and safe?(site) # # end # # # Document each target. # targets.each do |name, options| # tgdir = options.delete('chdir') # files = options.delete('files') # # #files.collect!{|f| "lib/more/facets/#{f}" } # # outdir = File.expand_path(File.join(site, name.gsub(' ',''))) # title = "Facets #{name.capitalize}" # # config = config.merge( # 'op' => outdir, # 'title' => title # ) # # # Prepare command arguments. # vector = [files, config] #.flatten.compact # # # Create Documentation. # cd(tgdir) do # rdoc(vector.to_params) # end # end # # end