summaryrefslogtreecommitdiff
path: root/lib/rdoc/generator/xml.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-13 03:13:37 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-13 03:13:37 +0000
commitec519b9b43db7756fcc2c19020ece2d7e2263fe4 (patch)
treedf6a1e6827f788c68e430d44a5ff913a62af6cf7 /lib/rdoc/generator/xml.rb
parent937b7ab8b59346f02da81ef324b8955b01d7cc25 (diff)
Complete RDoc namespace change
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/generator/xml.rb')
-rw-r--r--lib/rdoc/generator/xml.rb120
1 files changed, 120 insertions, 0 deletions
diff --git a/lib/rdoc/generator/xml.rb b/lib/rdoc/generator/xml.rb
new file mode 100644
index 0000000000..3335f2ce7c
--- /dev/null
+++ b/lib/rdoc/generator/xml.rb
@@ -0,0 +1,120 @@
+require 'rdoc/generator/html'
+
+##
+# Generate XML output as one big file
+
+class RDoc::Generator::XML < RDoc::Generator::HTML
+
+ ##
+ # Standard generator factory
+
+ def self.for(options)
+ new(options)
+ end
+
+ def initialize(*args)
+ super
+ end
+
+ ##
+ # Build the initial indices and output objects
+ # based on an array of TopLevel objects containing
+ # the extracted information.
+
+ def generate(info)
+ @info = info
+ @files = []
+ @classes = []
+ @hyperlinks = {}
+
+ build_indices
+ generate_xml
+ end
+
+ ##
+ # Generate:
+ #
+ # * a list of HtmlFile objects for each TopLevel object.
+ # * a list of HtmlClass objects for each first level
+ # class or module in the TopLevel objects
+ # * a complete list of all hyperlinkable terms (file,
+ # class, module, and method names)
+
+ def build_indices
+ @info.each do |toplevel|
+ @files << RDoc::Generator::HtmlFile.new(toplevel, @options, RDoc::Generator::FILE_DIR)
+ end
+
+ RDoc::TopLevel.all_classes_and_modules.each do |cls|
+ build_class_list(cls, @files[0], RDoc::Generator::CLASS_DIR)
+ end
+ end
+
+ def build_class_list(from, html_file, class_dir)
+ @classes << RDoc::Generator::HtmlClass.new(from, html_file, class_dir, @options)
+ from.each_classmodule do |mod|
+ build_class_list(mod, html_file, class_dir)
+ end
+ end
+
+ ##
+ # Generate all the HTML. For the one-file case, we generate
+ # all the information in to one big hash
+
+ def generate_xml
+ values = {
+ 'charset' => @options.charset,
+ 'files' => gen_into(@files),
+ 'classes' => gen_into(@classes)
+ }
+
+ # this method is defined in the template file
+ write_extra_pages if defined? write_extra_pages
+
+ template = RDoc::TemplatePage.new @template::ONE_PAGE
+
+ if @options.op_name
+ opfile = File.open(@options.op_name, "w")
+ else
+ opfile = $stdout
+ end
+ template.write_html_on(opfile, values)
+ end
+
+ def gen_into(list)
+ res = []
+ list.each do |item|
+ res << item.value_hash
+ end
+ res
+ end
+
+ def gen_file_index
+ gen_an_index(@files, 'Files')
+ end
+
+ def gen_class_index
+ gen_an_index(@classes, 'Classes')
+ end
+
+ def gen_method_index
+ gen_an_index(RDoc::Generator::HtmlMethod.all_methods, 'Methods')
+ end
+
+ def gen_an_index(collection, title)
+ res = []
+ collection.sort.each do |f|
+ if f.document_self
+ res << { "href" => f.path, "name" => f.index_name }
+ end
+ end
+
+ return {
+ "entries" => res,
+ 'list_title' => title,
+ 'index_url' => main_url,
+ }
+ end
+
+end
+