From: gotoken@... (GOTO Kentaro) Date: 2000-02-16T05:16:31+09:00 Subject: [ruby-talk:01397] Re: Ruby Language Reference Manual--Glossary In message "[ruby-talk:01373] Ruby Language Reference Manual--Glossary" on 00/02/15, "Conrad Schneiker" writes: >Also, does anyone have a ruby program that will cleanly combine multiple >html file documents into one file to facilitate printing and (browser) >searching? (Humm, that would be a good item to add to the Ruby Cookbook >FAQ.) I've enjoyed hacking up it :) -- gotoken #! /usr/bin/env ruby # # combman.rb - combines ruby-man files into one html file # # Usage: # ls -1 SOMEWHERE/ruby-man-1.4/*.html > ~/index.txt # (Edit ~/index.txt to arrange. However, index.html is always put at # the top.) # ruby combman.rb `cat ~/index.txt` > ~/ruby-man-1.4.html # # Or simply: # ruby combman.rb SOMEWHERE/ruby-man-1.4/*.html > ~/ruby-man-1.4.html def main index_html = ARGV.grep(/index\.html/)[0] ARGV.delete(index_html) gets_title(*ARGV) puts_header puts "" puts_index(index_html) puts_filetable(*ARGV) puts_sections(*ARGV) puts %Q{

generated by combman.rb
#{Time.now}

} puts "" end def gets_title(*argv) $title = {} argv.each do |fn| $title[fn] = open(fn).read.scan(%r{([^<]*)}i)[0][0].delete("\n") end end def puts_header puts < Ruby reference manual (combined version) EOS end def puts_index(index) puts_file(index) end def puts_filetable(*argv) puts "

Table of files

\n" end def puts_sections(*argv) argv.each do |fn| puts_file(fn) end end def puts_file(fn) f = File.basename(fn) puts "" text = open(fn).read # delete head elements text.gsub!(%r{.*}ip, '') # delete outside of the body element text.gsub!(%r{(]*>\s*}ip, '') # delete navigation anchors text.gsub!(%r{\s*\s*index\s*\s*}ip, "\\& - \\&") text.gsub!(%r{[^<]+(\s+-\s+[^<]+)+}ip, '') text.gsub!(%r{
(\s*
)*}ip, '
') # delete mailto text.gsub!(%r{]*>\s*]*matz@[^>]*>matz@[^<]+\s*

\s*}ip, '') # fix anchors text.gsub!(%r{(]*href\s*=\s*"#)([^"]+"[^>]*>)}ip, "\\1#{f}_\\2") text.gsub!(%r{(]*href\s*=\s*")([^"]+\.html"[^>]*>)}ip, "\\1#\\2") text.gsub!(%r{(]*href\s*=\s*")([^"]+\.html)#([^"]+"[^>]*>)}ip, "\\1#\\2_\\3") text.gsub!(%r{(]*name\s*=\s*")([^"]+"[^>]*>)}ip, "\\1#{f}_\\2") puts text end main