| Class | Generators::CHMGenerator |
| In: |
generators/chm_generator.rb
|
| Parent: | HTMLGenerator |
| HHC_PATH | = | "c:/Program Files/HTML Help Workshop/hhc.exe" |
Standard generator factory
# File generators/chm_generator.rb, line 10
10: def CHMGenerator.for(options)
11: CHMGenerator.new(options)
12: end
# File generators/chm_generator.rb, line 15
15: def initialize(*args)
16: super
17: @op_name = @options.op_name || "rdoc"
18: check_for_html_help_workshop
19: end
# File generators/chm_generator.rb, line 21
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
Invoke the windows help compiler to compiler the project
# File generators/chm_generator.rb, line 105
105: def compile_project
106: system(HHC_PATH, @project_name)
107: end
The contents is a list of all files and modules. For each we include as sub-entries the list of methods they contain. As we build the contents we also build an index file
# File generators/chm_generator.rb, line 74
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
The project contains the project file, a table of contents and an index
# File generators/chm_generator.rb, line 45
45: def create_help_project
46: create_project_file
47: create_contents_and_index
48: compile_project
49: end
The project file links together all the various files that go to make up the help.
# File generators/chm_generator.rb, line 54
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