#!/usr/bin/ruby #### Make docs require 'rexml/document' df=Object.methods require 'TagLib' fo=File.open("TagLib_doc.rb","wb") def data_method(fm) if !fm.nil? brief_desc=fm[:brief_desc].gsub(/\s+/im,"").size>0 ? "#{fm[:brief_desc]}\n":"" desc=(" # "+brief_desc+fm[:long_desc]+"\n").gsub("\n","\n # ")+"\n" params=fm[:param].join(",") else desc="" params="" end {:desc=>desc,:params=>params} end def print_methods(klass,functions,indent) out="" methods=klass.singleton_methods-Object.singleton_methods #p functions if(methods.size>0) out << indent+"# Singleton methods\n" methods.each{|m| dm=data_method(functions[m]) out << dm[:desc]+indent+"def self.#{m}(#{dm[:params]})\n"+indent+"end\n" } end methods=klass.instance_methods-Object.instance_methods methods.each{|m| dm=data_method(functions[m]) out << dm[:desc]+indent+"def #{m}(#{dm[:params]})\n"+indent+"end\n" } out end def get_doxygen_description(xml_file) out="" funcs={} if(File.exists? xml_file) #p xml_file xml=REXML::Document.new(File.new(xml_file)) short_desc=xml.root.elements["/doxygen/compounddef/briefdescription"].to_s.gsub(/<.+?>/,"") long_desc=xml.root.elements["/doxygen/compounddef/detaileddescription"].to_s.gsub(/<.+?>/,"") out+=" # "+(""+short_desc+".\n\n"+long_desc).gsub("\n","\n # ") out+="\n # \n" # functions xml.elements.each("/doxygen/compounddef/sectiondef[@kind='public-func']/memberdef[@kind='function']") {|func| name=func.elements["name"].text brief=func.elements["briefdescription"].to_s.gsub(/<.+?>/,"") long=func.elements["detaileddescription"].to_s.gsub(/<.+?>/,"") param=[] func.elements.each("param") {|xpar| type=xpar.elements["type"].to_s.gsub(/<.+?>|const|\*|String|StringList|&/,"").chomp if xpar.elements["defval"] param.push(type+" "+xpar.elements["declname"].text+" = "+xpar.elements["defval"].to_s.gsub(/<.+?>/,"")) else param.push(type+" "+xpar.elements["declname"].text) end } funcs[name]={:param=>param,:brief_desc=>brief,:long_desc=>long} } end {:object=>out,:functions=>funcs} end def print_class(klass,indent) out="" xml_file="xml/xml/class"+klass.to_s.gsub(":","_1")+".xml" dd=get_doxygen_description(xml_file) out+=dd[:object] #p dd[:functions] if klass.superclass != Object out+=indent+"class #{klass} < "+klass.superclass.to_s+"\n" else out+=indent+"class #{klass}\n" end out+=print_methods(klass,dd[:functions],indent+" ") out << indent+"end\n" end def print_module(mod,indent) out="" xml_file="xml/xml/namespace"+mod.to_s.gsub(":","_1")+".xml" dd=get_doxygen_description(xml_file) out+=dd[:object] out+=indent+"module #{mod}\n" out+=indent+print_methods(mod,dd[:functions],indent+" ") submods=[] mod.constants.each {|c| if mod.const_get(c).class==Module submods.push(c) else out << print_constant(mod,c,indent+" ") end } submods.each{|sm| out << print_constant(mod,sm,indent+" ") } out << indent+"end\n" out end def print_constant(obj,con,indent) out="" if(obj.const_get(con).class==Module) out+=print_module(obj.const_get(con),indent+" ") elsif(obj.const_get(con).class==Class) out+=print_class(obj.const_get(con),indent) else out+=indent+"#{con}="+obj.const_get(con).to_s+"\n" end out end out="" out=print_constant(ObjectSpace,"TagLib","") fo.puts out fo.close