def document_ca65_source_as_html(codebase_dir,codebase_title,output_dir) Dir.mkdir(output_dir) unless File.exist?(output_dir) symbol_attributes={} html_filenames={} file_overviews={} puts "generating documentation for #{codebase_title}" documentation_title="#{codebase_title} technical reference" require 'find' files_to_parse=[] Find.find(codebase_dir) do |path| Find.prune if path[0]=='.' files_to_parse <"stylesheet", :href=>"ca65-doc-style.css",:type=>"text/css") end body do h2 "#{symbol_type}s" table do tr do th "#{symbol_type}" th "defined in" end symbol_names.each do |symbol| if symbol_attributes[symbol][:type]==symbol_type then tr do td symbol count=0 td do symbol_attributes[symbol][:defined_in].each do |filename| count+=1 text ", " unless count==1 a(:href=>"#{html_filenames[filename]}##{symbol_type}s", :target=>"docwin"){filename} source_files<"stylesheet", :href=>"ca65-doc-style.css",:type=>"text/css") end body do h1 "#{documentation_title}" h2 "files" table do tr do th "file" th "symbols" end source_files.sort.each do |filename| tr do td {a(:href=>"#{html_filenames[filename]}", :target=>"docwin"){filename}} symbols_in_file=(symbol_names.collect{|symbol| symbol_attributes[symbol][:defined_in].include?(filename) ? symbol:nil}).compact td symbols_in_file.join(", ") end end end end end File.open("#{output_dir}/ref_index.html","w") <"stylesheet", :href=>"ca65-doc-style.css",:type=>"text/css") end body do a(:href=>"ref_index.html") { h1 documentation_title} h1 "File : #{filename}" pre file_overviews[filename] if file_overviews[filename].length>1 if functions_in_file.length>0 then h2(:id=>"functions") {"functions"} table do tr do th{"function"} th{"description"} end functions_in_file.each do |symbol| tr do td(:id=>symbol){symbol} td{pre symbol_attributes[symbol][:comment][filename] unless symbol_attributes[symbol][:comment].nil?} end end end end if variables_in_file.length>0 then h2(:id=>"variables"){"variables"} table do tr do th{"variable"} th{"description"} th{"size (bytes)"} end variables_in_file.each do |symbol| tr do td(:id=>symbol){symbol} td{symbol_attributes[symbol][:comment][filename] unless symbol_attributes[symbol][:comment].nil?} td{symbol_attributes[symbol][:size][filename] unless symbol_attributes[symbol][:size].nil?} end end end end if constants_in_file.length>0 then h2(:id=>"constants") {"constants"} table do tr do th{"constants"} th{"description"} th{"value"} end constants_in_file.each do |symbol| tr do td(:id=>symbol){symbol} td{symbol_attributes[symbol][:comment][filename] unless symbol_attributes[symbol][:comment].nil?} td{symbol_attributes[symbol][:value][filename] unless symbol_attributes[symbol][:value].nil?} end end end end h2{ "implementation"} pre(:id=>:code) {File.open("#{codebase_dir}/#{filename}").read.gsub("\t"," ")} end end File.open("#{output_dir}/#{html_filenames[filename]}","w") < #{documentation_title} EOF end if __FILE__ == $0 then #run from command line codebase_dir=Dir.pwd output_dir="doc" codebase_title=File.basename(codebase_dir) document_ca65_source_as_html(codebase_dir,codebase_title,output_dir) end