2007-12-24 09:09:57 -05:00
|
|
|
require 'fileutils'
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-12 22:13:37 -05:00
|
|
|
require 'rdoc/generator'
|
2008-01-13 22:34:05 -05:00
|
|
|
require 'rdoc/markup/to_html'
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
|
|
|
# We're responsible for generating all the HTML files from the object tree
|
|
|
|
# defined in code_objects.rb. We generate:
|
|
|
|
#
|
|
|
|
# [files] an html file for each input file given. These
|
|
|
|
# input files appear as objects of class
|
|
|
|
# TopLevel
|
|
|
|
#
|
|
|
|
# [classes] an html file for each class or module encountered.
|
|
|
|
# These classes are not grouped by file: if a file
|
|
|
|
# contains four classes, we'll generate an html
|
|
|
|
# file for the file itself, and four html files
|
|
|
|
# for the individual classes.
|
|
|
|
#
|
|
|
|
# [indices] we generate three indices for files, classes,
|
|
|
|
# and methods. These are displayed in a browser
|
|
|
|
# like window with three index panes across the
|
|
|
|
# top and the selected description below
|
|
|
|
#
|
|
|
|
# Method descriptions appear in whatever entity (file, class, or module) that
|
|
|
|
# contains them.
|
|
|
|
#
|
|
|
|
# We generate files in a structure below a specified subdirectory, normally
|
|
|
|
# +doc+.
|
|
|
|
#
|
|
|
|
# opdir
|
|
|
|
# |
|
|
|
|
# |___ files
|
|
|
|
# | |__ per file summaries
|
|
|
|
# |
|
|
|
|
# |___ classes
|
|
|
|
# |__ per class/module descriptions
|
|
|
|
#
|
|
|
|
# HTML is generated using the Template class.
|
|
|
|
|
|
|
|
class RDoc::Generator::HTML
|
|
|
|
|
|
|
|
include RDoc::Generator::MarkUp
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
##
|
2008-02-09 22:59:08 -05:00
|
|
|
# Generator may need to return specific subclasses depending on the
|
|
|
|
# options they are passed. Because of this we create them using a factory
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def self.for(options)
|
|
|
|
RDoc::Generator::AllReferences.reset
|
|
|
|
RDoc::Generator::Method.reset
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
if options.all_one_file
|
|
|
|
RDoc::Generator::HTMLInOne.new options
|
|
|
|
else
|
|
|
|
new options
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-02-09 22:59:08 -05:00
|
|
|
end
|
2004-05-09 23:14:35 -04:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
class << self
|
|
|
|
protected :new
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2008-02-09 22:59:08 -05:00
|
|
|
# Set up a new HTML generator. Basically all we do here is load up the
|
|
|
|
# correct output temlate
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def initialize(options) #:not-new:
|
|
|
|
@options = options
|
|
|
|
load_html_template
|
2008-04-04 17:16:19 -04:00
|
|
|
@main_page_path = nil
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-01-06 19:42:03 -05:00
|
|
|
##
|
2008-02-09 22:59:08 -05:00
|
|
|
# Build the initial indices and output objects
|
|
|
|
# based on an array of TopLevel objects containing
|
|
|
|
# the extracted information.
|
|
|
|
|
|
|
|
def generate(toplevels)
|
|
|
|
@toplevels = toplevels
|
|
|
|
@files = []
|
|
|
|
@classes = []
|
|
|
|
|
|
|
|
write_style_sheet
|
2008-07-17 20:46:16 -04:00
|
|
|
gen_sub_directories
|
2008-02-09 22:59:08 -05:00
|
|
|
build_indices
|
|
|
|
generate_html
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
private
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
|
|
|
# Load up the HTML template specified in the options.
|
|
|
|
# If the template name contains a slash, use it literally
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def load_html_template
|
|
|
|
template = @options.template
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
unless template =~ %r{/|\\} then
|
|
|
|
template = File.join('rdoc', 'generator', @options.generator.key,
|
|
|
|
template)
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
require template
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
@template = self.class.const_get @options.template.upcase
|
|
|
|
@options.template_class = @template
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
rescue LoadError
|
|
|
|
$stderr.puts "Could not find HTML template '#{template}'"
|
|
|
|
exit 99
|
2008-01-06 19:42:03 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-06 19:42:03 -05:00
|
|
|
##
|
2008-02-09 22:59:08 -05:00
|
|
|
# Write out the style sheet used by the main frames
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def write_style_sheet
|
|
|
|
return unless @template.constants.include? :STYLE or
|
|
|
|
@template.constants.include? 'STYLE'
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
template = RDoc::TemplatePage.new @template::STYLE
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
unless @options.css then
|
|
|
|
open RDoc::Generator::CSS_NAME, 'w' do |f|
|
|
|
|
values = {}
|
2008-01-12 22:02:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
if @template.constants.include? :FONTS or
|
|
|
|
@template.constants.include? 'FONTS' then
|
|
|
|
values["fonts"] = @template::FONTS
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
template.write_html_on(f, values)
|
2004-11-20 10:02:57 -05:00
|
|
|
end
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-01-06 19:42:03 -05:00
|
|
|
##
|
2008-02-09 22:59:08 -05:00
|
|
|
# See the comments at the top for a description of the directory structure
|
|
|
|
|
|
|
|
def gen_sub_directories
|
|
|
|
FileUtils.mkdir_p RDoc::Generator::FILE_DIR
|
|
|
|
FileUtils.mkdir_p RDoc::Generator::CLASS_DIR
|
|
|
|
rescue
|
|
|
|
$stderr.puts $!.message
|
|
|
|
exit 1
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def build_indices
|
|
|
|
@files, @classes = RDoc::Generator::Context.build_indicies(@toplevels,
|
|
|
|
@options)
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-01-06 19:42:03 -05:00
|
|
|
##
|
2008-02-09 22:59:08 -05:00
|
|
|
# Generate all the HTML
|
|
|
|
|
|
|
|
def generate_html
|
|
|
|
# the individual descriptions for files and classes
|
|
|
|
gen_into(@files)
|
|
|
|
gen_into(@classes)
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
# and the index files
|
|
|
|
gen_file_index
|
|
|
|
gen_class_index
|
|
|
|
gen_method_index
|
|
|
|
gen_main_index
|
|
|
|
|
|
|
|
# this method is defined in the template file
|
|
|
|
write_extra_pages if defined? write_extra_pages
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_into(list)
|
2008-07-17 20:46:16 -04:00
|
|
|
@file_list ||= index_to_links @files
|
|
|
|
@class_list ||= index_to_links @classes
|
|
|
|
@method_list ||= index_to_links RDoc::Generator::Method.all_methods
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
list.each do |item|
|
2008-07-17 20:46:16 -04:00
|
|
|
next unless item.document_self
|
|
|
|
|
|
|
|
op_file = item.path
|
|
|
|
|
|
|
|
FileUtils.mkdir_p File.dirname(op_file)
|
|
|
|
|
|
|
|
open op_file, 'w' do |io|
|
|
|
|
item.write_on io, @file_list, @class_list, @method_list
|
2003-12-23 23:24:29 -05:00
|
|
|
end
|
|
|
|
end
|
2008-02-09 22:59:08 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_file_index
|
|
|
|
gen_an_index @files, 'Files', @template::FILE_INDEX, "fr_file_index.html"
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_class_index
|
|
|
|
gen_an_index(@classes, 'Classes', @template::CLASS_INDEX,
|
|
|
|
"fr_class_index.html")
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_method_index
|
|
|
|
gen_an_index(RDoc::Generator::Method.all_methods, 'Methods',
|
|
|
|
@template::METHOD_INDEX, "fr_method_index.html")
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_an_index(collection, title, template, filename)
|
|
|
|
template = RDoc::TemplatePage.new @template::FR_INDEX_BODY, template
|
|
|
|
res = []
|
|
|
|
collection.sort.each do |f|
|
|
|
|
if f.document_self
|
|
|
|
res << { "href" => f.path, "name" => f.index_name }
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
values = {
|
|
|
|
"entries" => res,
|
|
|
|
'list_title' => CGI.escapeHTML(title),
|
|
|
|
'index_url' => main_url,
|
|
|
|
'charset' => @options.charset,
|
|
|
|
'style_url' => style_url('', @options.css),
|
|
|
|
}
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
open filename, 'w' do |f|
|
|
|
|
template.write_html_on(f, values)
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-06 19:42:03 -05:00
|
|
|
##
|
2008-02-09 22:59:08 -05:00
|
|
|
# The main index page is mostly a template frameset, but includes the
|
|
|
|
# initial page. If the <tt>--main</tt> option was given, we use this as
|
|
|
|
# our main page, otherwise we use the first file specified on the command
|
|
|
|
# line.
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_main_index
|
2008-07-17 20:46:16 -04:00
|
|
|
if @template.const_defined? :FRAMELESS then
|
|
|
|
main = @files.find do |file|
|
|
|
|
@main_page == file.name
|
|
|
|
end
|
|
|
|
|
|
|
|
if main.nil? then
|
|
|
|
main = @classes.find do |klass|
|
|
|
|
main_page == klass.context.full_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
main = RDoc::TemplatePage.new @template::INDEX
|
|
|
|
end
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
open 'index.html', 'w' do |f|
|
2008-07-17 20:46:16 -04:00
|
|
|
style_url = style_url '', @options.css
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
classes = @classes.sort.map { |klass| klass.value_hash }
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
values = {
|
|
|
|
'main_page' => @main_page,
|
|
|
|
'initial_page' => main_url,
|
|
|
|
'style_url' => style_url('', @options.css),
|
|
|
|
'title' => CGI.escapeHTML(@options.title),
|
|
|
|
'charset' => @options.charset,
|
|
|
|
'classes' => classes,
|
|
|
|
}
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
values['inline_source'] = @options.inline_source
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
if main.respond_to? :write_on then
|
|
|
|
main.write_on f, @file_list, @class_list, @method_list, values
|
|
|
|
else
|
|
|
|
main.write_html_on f, values
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-02-09 22:59:08 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def index_to_links(collection)
|
|
|
|
collection.sort.map do |f|
|
|
|
|
next unless f.document_self
|
|
|
|
{ "href" => f.path, "name" => f.index_name }
|
|
|
|
end.compact
|
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
|
|
|
# Returns the url of the main page
|
|
|
|
|
|
|
|
def main_url
|
|
|
|
@main_page = @options.main_page
|
|
|
|
@main_page_ref = nil
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
if @main_page then
|
2008-03-08 19:59:23 -05:00
|
|
|
@main_page_ref = RDoc::Generator::AllReferences[@main_page]
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
if @main_page_ref then
|
|
|
|
@main_page_path = @main_page_ref.path
|
2003-12-01 02:12:49 -05:00
|
|
|
else
|
2008-02-09 22:59:08 -05:00
|
|
|
$stderr.puts "Could not find main page #{@main_page}"
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
unless @main_page_path then
|
2008-04-04 17:16:19 -04:00
|
|
|
file = @files.find { |context| context.document_self }
|
2008-02-09 22:59:08 -05:00
|
|
|
@main_page_path = file.path if file
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
unless @main_page_path then
|
|
|
|
$stderr.puts "Couldn't find anything to document"
|
|
|
|
$stderr.puts "Perhaps you've used :stopdoc: in all classes"
|
2003-12-01 02:12:49 -05:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
@main_page_path
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
class RDoc::Generator::HTMLInOne < RDoc::Generator::HTML
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def initialize(*args)
|
|
|
|
super
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
|
|
|
# Build the initial indices and output objects
|
|
|
|
# based on an array of TopLevel objects containing
|
|
|
|
# the extracted information.
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def generate(info)
|
|
|
|
@toplevels = info
|
|
|
|
@hyperlinks = {}
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
build_indices
|
|
|
|
generate_xml
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
|
|
|
# Generate:
|
|
|
|
#
|
|
|
|
# * a list of RDoc::Generator::File objects for each TopLevel object.
|
|
|
|
# * a list of RDoc::Generator::Class 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
|
|
|
|
@files, @classes = RDoc::Generator::Context.build_indices(@toplevels,
|
|
|
|
@options)
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
|
|
|
# Generate all the HTML. For the one-file case, we generate
|
|
|
|
# all the information in to one big hash
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def generate_xml
|
|
|
|
values = {
|
|
|
|
'charset' => @options.charset,
|
|
|
|
'files' => gen_into(@files),
|
|
|
|
'classes' => gen_into(@classes),
|
|
|
|
'title' => CGI.escapeHTML(@options.title),
|
|
|
|
}
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
# this method is defined in the template file
|
|
|
|
write_extra_pages if defined? write_extra_pages
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
template = RDoc::TemplatePage.new @template::ONE_PAGE
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
if @options.op_name
|
|
|
|
opfile = open @options.op_name, 'w'
|
|
|
|
else
|
|
|
|
opfile = $stdout
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-02-09 22:59:08 -05:00
|
|
|
template.write_html_on(opfile, values)
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_into(list)
|
|
|
|
res = []
|
|
|
|
list.each do |item|
|
|
|
|
res << item.value_hash
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-02-09 22:59:08 -05:00
|
|
|
res
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_file_index
|
|
|
|
gen_an_index(@files, 'Files')
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_class_index
|
|
|
|
gen_an_index(@classes, 'Classes')
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_method_index
|
|
|
|
gen_an_index(RDoc::Generator::Method.all_methods, 'Methods')
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def gen_an_index(collection, title)
|
|
|
|
return {
|
2008-07-17 20:46:16 -04:00
|
|
|
"entries" => index_to_links(collection),
|
2008-02-09 22:59:08 -05:00
|
|
|
'list_title' => title,
|
|
|
|
'index_url' => main_url,
|
|
|
|
}
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-01-06 19:42:03 -05:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-01-06 19:42:03 -05:00
|
|
|
|