1 require 'rdoc/generator/html'
3 class RDoc::Generator::CHM < RDoc::Generator::HTML
5 HHC_PATH = "c:/Program Files/HTML Help Workshop/hhc.exe"
8 # Standard generator factory
16 @op_name = @options.op_name || "rdoc"
17 check_for_html_help_workshop
20 def check_for_html_help_workshop
21 stat = File.stat(HHC_PATH)
24 "\n.chm output generation requires that Microsoft's Html Help\n" <<
25 "Workshop is installed. RDoc looks for it in:\n\n " <<
27 "\n\nYou can download a copy for free from:\n\n" <<
28 " http://msdn.microsoft.com/library/default.asp?" <<
29 "url=/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp\n\n"
33 # Generate the html as normal, then wrap it in a help project
37 @project_name = @op_name + ".hhp"
42 # The project contains the project file, a table of contents and an index
44 def create_help_project
46 create_contents_and_index
51 # The project file links together all the various
52 # files that go to make up the help.
54 def create_project_file
55 template = RDoc::TemplatePage.new @template::HPP_FILE
56 values = { "title" => @options.title, "opname" => @op_name }
59 files << { "html_file_name" => f.path }
62 values['all_html_files'] = files
64 File.open(@project_name, "w") do |f|
65 template.write_html_on(f, values)
70 # The contents is a list of all files and modules.
71 # For each we include as sub-entries the list
72 # of methods they contain. As we build the contents
73 # we also build an index file
75 def create_contents_and_index
79 (@files+@classes).sort.each do |entry|
80 content_entry = { "c_name" => entry.name, "ref" => entry.path }
81 index << { "name" => entry.name, "aref" => entry.path }
85 methods = entry.build_method_summary_list(entry.path)
87 content_entry["methods"] = methods unless methods.empty?
88 contents << content_entry
92 values = { "contents" => contents }
93 template = RDoc::TemplatePage.new @template::CONTENTS
94 File.open("contents.hhc", "w") do |f|
95 template.write_html_on(f, values)
98 values = { "index" => index }
99 template = RDoc::TemplatePage.new @template::CHM_INDEX
100 File.open("index.hhk", "w") do |f|
101 template.write_html_on(f, values)
106 # Invoke the windows help compiler to compiler the project
109 system(HHC_PATH, @project_name)