Change soft-fail to use the config, rather than env
[rbx.git] / lib / rdoc / generator / chm.rb
blob7537365842f060b5837cf2df265cbdbe8303e260
1 require 'rdoc/generator/html'
3 class RDoc::Generator::CHM < RDoc::Generator::HTML
5   HHC_PATH = "c:/Program Files/HTML Help Workshop/hhc.exe"
7   ##
8   # Standard generator factory
10   def self.for(options)
11     new(options)
12   end
14   def initialize(*args)
15     super
16     @op_name = @options.op_name || "rdoc"
17     check_for_html_help_workshop
18   end
20   def check_for_html_help_workshop
21     stat = File.stat(HHC_PATH)
22   rescue
23     $stderr <<
24       "\n.chm output generation requires that Microsoft's Html Help\n" <<
25       "Workshop is installed. RDoc looks for it in:\n\n    " <<
26       HHC_PATH <<
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"
30   end
32   ##
33   # Generate the html as normal, then wrap it in a help project
35   def generate(info)
36     super
37     @project_name = @op_name + ".hhp"
38     create_help_project
39   end
41   ##
42   # The project contains the project file, a table of contents and an index
44   def create_help_project
45     create_project_file
46     create_contents_and_index
47     compile_project
48   end
50   ##
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 }
57     files = []
58     @files.each do |f|
59       files << { "html_file_name" => f.path }
60     end
62     values['all_html_files'] = files
64     File.open(@project_name, "w") do |f|
65       template.write_html_on(f, values)
66     end
67   end
69   ##
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
76     contents = []
77     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 }
83       internals = []
85       methods = entry.build_method_summary_list(entry.path)
87       content_entry["methods"] = methods unless methods.empty?
88       contents << content_entry
89       index.concat methods
90     end
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)
96     end
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)
102     end
103   end
105   ##
106   # Invoke the windows help compiler to compiler the project
108   def compile_project
109     system(HHC_PATH, @project_name)
110   end