PageRenderTime 62ms CodeModel.GetById 51ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/rdoc/generators/chm_generator.rb

http://github.com/agross/netopenspace
Ruby | 112 lines | 104 code | 7 blank | 1 comment | 1 complexity | 0f16d888e7b24d6daf7f90e5f4c3b330 MD5 | raw file
  1require 'rdoc/generators/html_generator'
  2
  3module Generators
  4
  5  class CHMGenerator < HTMLGenerator
  6
  7    HHC_PATH = "c:/Program Files/HTML Help Workshop/hhc.exe"
  8
  9    # Standard generator factory
 10    def CHMGenerator.for(options)
 11      CHMGenerator.new(options)
 12    end
 13
 14    
 15    def initialize(*args)
 16      super
 17      @op_name = @options.op_name || "rdoc"
 18      check_for_html_help_workshop
 19    end
 20
 21    def check_for_html_help_workshop
 22      stat = File.stat(HHC_PATH)
 23    rescue
 24      $stderr <<
 25	"\n.chm output generation requires that Microsoft's Html Help\n" <<
 26	"Workshop is installed. RDoc looks for it in:\n\n    " <<
 27	HHC_PATH <<
 28	"\n\nYou can download a copy for free from:\n\n" <<
 29	"    http://msdn.microsoft.com/library/default.asp?" <<
 30	"url=/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp\n\n"
 31      
 32      exit 99
 33    end
 34
 35    # Generate the html as normal, then wrap it
 36    # in a help project
 37    def generate(info)
 38      super
 39      @project_name = @op_name + ".hhp"
 40      create_help_project
 41    end
 42
 43    # The project contains the project file, a table of contents
 44    # and an index
 45    def create_help_project
 46      create_project_file
 47      create_contents_and_index
 48      compile_project
 49    end
 50
 51    # The project file links together all the various
 52    # files that go to make up the help.
 53
 54    def create_project_file
 55      template = TemplatePage.new(RDoc::Page::HPP_FILE)
 56      values = { "title" => @options.title, "opname" => @op_name }
 57      files = []
 58      @files.each do |f|
 59	files << { "html_file_name" => f.path }
 60      end
 61
 62      values['all_html_files'] = files
 63      
 64      File.open(@project_name, "w") do |f|
 65        template.write_html_on(f, values)
 66      end
 67    end
 68
 69    # The contents is a list of all files and modules.
 70    # For each we include  as sub-entries the list
 71    # of methods they contain. As we build the contents
 72    # we also build an index file
 73
 74    def create_contents_and_index
 75      contents = []
 76      index    = []
 77
 78      (@files+@classes).sort.each do |entry|
 79	content_entry = { "c_name" => entry.name, "ref" => entry.path }
 80	index << { "name" => entry.name, "aref" => entry.path }
 81
 82	internals = []
 83
 84	methods = entry.build_method_summary_list(entry.path)
 85
 86	content_entry["methods"] = methods unless methods.empty?
 87        contents << content_entry
 88	index.concat methods
 89      end
 90
 91      values = { "contents" => contents }
 92      template = TemplatePage.new(RDoc::Page::CONTENTS)
 93      File.open("contents.hhc", "w") do |f|
 94	template.write_html_on(f, values)
 95      end
 96
 97      values = { "index" => index }
 98      template = TemplatePage.new(RDoc::Page::CHM_INDEX)
 99      File.open("index.hhk", "w") do |f|
100	template.write_html_on(f, values)
101      end      
102    end
103
104    # Invoke the windows help compiler to compiler the project
105    def compile_project
106      system(HHC_PATH, @project_name)
107    end
108
109  end
110
111
112end