#!/usr/bin/ruby -w require "rexml/document" files = File.new(ARGV[0]).readlines().map{|i| i.chop} title = ARGV[1] files.each_with_index {|file, idx| puts "Processing: #{file}" xml = REXML::Document.new(File.new(file).read()) if idx+1 < files.length next_file = files[idx+1] else next_file = nil end if idx - 1 > 0 then prev_file = files[idx-1] else prev_file = nil end xml.elements.each("/html/head") {|head| if prev_file then prev_link = REXML::Element.new("link") prev_link.attributes["rel"] = "prev" prev_link.attributes["href"] = prev_file head << prev_link end if next_file then next_link = REXML::Element.new("link") next_link.attributes["rel"] = "next" next_link.attributes["href"] = next_file head << next_link end up_link = REXML::Element.new("link") up_link.attributes["rel"] = "up" up_link.attributes["href"] = "toc.html" head << up_link; } xml.elements.each("/html/body") {|body| body << REXML::Element.new("hr") el = REXML::Element.new("small") el.text = file body << el } f = File.new("out/#{file}", "w") f.write(xml.to_s) f.close() } puts "Writing out/toc.html" f = File.new("out/toc.html", "w") f.puts("") f.puts("") if title then f.puts("#{title}") end f.puts "" f.puts("") f.puts("") if title then f.puts("

#{title}

") end f.puts("") f.puts("") f.puts("") f.close() # EOF #