1 |
|
---|
2 | require 'ftools'
|
---|
3 |
|
---|
4 | require 'rdoc/options'
|
---|
5 | require 'rdoc/markup/simple_markup'
|
---|
6 | require 'rdoc/markup/simple_markup/to_html'
|
---|
7 | require 'rdoc/generators/html_generator'
|
---|
8 |
|
---|
9 | module Generators
|
---|
10 |
|
---|
11 | # Generate XML output as one big file
|
---|
12 |
|
---|
13 | class XMLGenerator < HTMLGenerator
|
---|
14 |
|
---|
15 | # Standard generator factory
|
---|
16 | def XMLGenerator.for(options)
|
---|
17 | XMLGenerator.new(options)
|
---|
18 | end
|
---|
19 |
|
---|
20 |
|
---|
21 | def initialize(*args)
|
---|
22 | super
|
---|
23 | end
|
---|
24 |
|
---|
25 | ##
|
---|
26 | # Build the initial indices and output objects
|
---|
27 | # based on an array of TopLevel objects containing
|
---|
28 | # the extracted information.
|
---|
29 |
|
---|
30 | def generate(info)
|
---|
31 | @info = info
|
---|
32 | @files = []
|
---|
33 | @classes = []
|
---|
34 | @hyperlinks = {}
|
---|
35 |
|
---|
36 | build_indices
|
---|
37 | generate_xml
|
---|
38 | end
|
---|
39 |
|
---|
40 |
|
---|
41 | ##
|
---|
42 | # Generate:
|
---|
43 | #
|
---|
44 | # * a list of HtmlFile objects for each TopLevel object.
|
---|
45 | # * a list of HtmlClass objects for each first level
|
---|
46 | # class or module in the TopLevel objects
|
---|
47 | # * a complete list of all hyperlinkable terms (file,
|
---|
48 | # class, module, and method names)
|
---|
49 |
|
---|
50 | def build_indices
|
---|
51 |
|
---|
52 | @info.each do |toplevel|
|
---|
53 | @files << HtmlFile.new(toplevel, @options, FILE_DIR)
|
---|
54 | end
|
---|
55 |
|
---|
56 | RDoc::TopLevel.all_classes_and_modules.each do |cls|
|
---|
57 | build_class_list(cls, @files[0], CLASS_DIR)
|
---|
58 | end
|
---|
59 | end
|
---|
60 |
|
---|
61 | def build_class_list(from, html_file, class_dir)
|
---|
62 | @classes << HtmlClass.new(from, html_file, class_dir, @options)
|
---|
63 | from.each_classmodule do |mod|
|
---|
64 | build_class_list(mod, html_file, class_dir)
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|
68 | ##
|
---|
69 | # Generate all the HTML. For the one-file case, we generate
|
---|
70 | # all the information in to one big hash
|
---|
71 | #
|
---|
72 | def generate_xml
|
---|
73 | values = {
|
---|
74 | 'charset' => @options.charset,
|
---|
75 | 'files' => gen_into(@files),
|
---|
76 | 'classes' => gen_into(@classes)
|
---|
77 | }
|
---|
78 |
|
---|
79 | # this method is defined in the template file
|
---|
80 | write_extra_pages if defined? write_extra_pages
|
---|
81 |
|
---|
82 | template = TemplatePage.new(RDoc::Page::ONE_PAGE)
|
---|
83 |
|
---|
84 | if @options.op_name
|
---|
85 | opfile = File.open(@options.op_name, "w")
|
---|
86 | else
|
---|
87 | opfile = $stdout
|
---|
88 | end
|
---|
89 | template.write_html_on(opfile, values)
|
---|
90 | end
|
---|
91 |
|
---|
92 | def gen_into(list)
|
---|
93 | res = []
|
---|
94 | list.each do |item|
|
---|
95 | res << item.value_hash
|
---|
96 | end
|
---|
97 | res
|
---|
98 | end
|
---|
99 |
|
---|
100 | def gen_file_index
|
---|
101 | gen_an_index(@files, 'Files')
|
---|
102 | end
|
---|
103 |
|
---|
104 | def gen_class_index
|
---|
105 | gen_an_index(@classes, 'Classes')
|
---|
106 | end
|
---|
107 |
|
---|
108 | def gen_method_index
|
---|
109 | gen_an_index(HtmlMethod.all_methods, 'Methods')
|
---|
110 | end
|
---|
111 |
|
---|
112 |
|
---|
113 | def gen_an_index(collection, title)
|
---|
114 | res = []
|
---|
115 | collection.sort.each do |f|
|
---|
116 | if f.document_self
|
---|
117 | res << { "href" => f.path, "name" => f.index_name }
|
---|
118 | end
|
---|
119 | end
|
---|
120 |
|
---|
121 | return {
|
---|
122 | "entries" => res,
|
---|
123 | 'list_title' => title,
|
---|
124 | 'index_url' => main_url,
|
---|
125 | }
|
---|
126 | end
|
---|
127 |
|
---|
128 | end
|
---|
129 |
|
---|
130 | end
|
---|