/, '') res.sub!(/<\/p>$/, '') end res end end class XHTMLGenerator < HTMLGenerator def XHTMLGenerator.gen_url(path, target) Generators::HTMLGenerator.gen_url(path, target) end def XHTMLGenerator.for(options) AllReferences::reset HtmlMethod::reset if options.all_one_file XHTMLGeneratorInOne.new(options) else XHTMLGenerator.new(options) end end def generate(toplevels) super(toplevels) copy_xsls end private def build_indices @toplevels.each do |toplevel| @files << XHtmlFile.new(toplevel, @options, FILE_DIR) end RDoc::TopLevel.all_classes_and_modules.each do |cls| build_class_list(cls, @files[0], CLASS_DIR) end end def build_class_list(from, html_file, class_dir) @classes << XHtmlClass.new(from, html_file, class_dir, @options) from.each_classmodule do |mod| build_class_list(mod, html_file, class_dir) end end def gen_method_index gen_an_index(XHtmlMethod.all_methods, 'Methods', RDoc::Page::METHOD_INDEX, "fr_method_index.html") end def gen_an_index(collection, title, template, filename) template = TemplatePage.new(RDoc::Page::FR_INDEX_BODY, template) res = [] collection.sort.each do |f| if f.document_self res << { "href" => f.path, "name" => f.index_name } end end values = { "entries" => res, 'list_title' => CGI.escapeHTML(title), 'index_url' => main_url, 'charset' => @options.charset, 'style_url' => style_url('', @options.css), 'mathml_xsl_url' => style_url('', "mathml.xsl"), } File.open(filename, "w") do |f| template.write_html_on(f, values) end end def copy_xsls xsl_files = ["mathml.xsl", "pmathmlcss.xsl", "ctop.xsl", "pmathml.xsl"] xsl_dir = "rdoc/generators/template/xhtml" hit = 0 $LOAD_PATH.each{ |path| hit = 0 xsl_files.each{ |file| hit += 1 if File.exist?(File.join(path, xsl_dir, file)) } if hit >= 4 xsl_files.each{ |file| File.copy(File.join(path, xsl_dir, file), "./") } break else hit = 0 end } if hit < 4 $stderr.puts "Couldn't find xsl files (#{xsl_files.join(', ')})\n" exit end end end class XHTMLGeneratorInOne < HTMLGeneratorInOne def build_class_list(from, html_file, class_dir) @classes << XHtmlClass.new(from, html_file, class_dir, @options) from.each_classmodule do |mod| build_class_list(mod, html_file, class_dir) end end def build_indices @toplevels.each do |toplevel| @files << XHtmlFile.new(toplevel, @options, FILE_DIR) end RDoc::TopLevel.all_classes_and_modules.each do |cls| build_class_list(cls, @files[0], CLASS_DIR) end end def gen_method_index gen_an_index(XHtmlMethod.all_methods, 'Methods') end end class XHtmlClass < HtmlClass def value_hash super @values["mathml_xsl_url"] = style_url(path, "mathml.xsl") @values end def collect_methods list = @context.method_list unless @options.show_all list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation } end @methods = list.collect {|m| XHtmlMethod.new(m, self, @options) } end end class XHtmlFile < HtmlFile def value_hash super @values["mathml_xsl_url"] = style_url(path, "mathml.xsl") @values end def collect_methods list = @context.method_list unless @options.show_all list = list.find_all {|m| m.visibility == :public || m.visibility == :protected || m.force_documentation } end @methods = list.collect {|m| XHtmlMethod.new(m, self, @options) } end end class XHtmlMethod < HtmlMethod def create_source_code_file(code_body) template_regexp = Regexp.new("\\." + @options.template + "$") meth_path = @html_class.path.sub(template_regexp, '.src') File.makedirs(meth_path) file_path = File.join(meth_path, @seq) + '.' + @options.template template = TemplatePage.new(RDoc::Page::SRC_PAGE) File.open(file_path, "w") do |f| values = { 'title' => CGI.escapeHTML(index_name), 'code' => code_body, 'style_url' => style_url(file_path, @options.css), 'mathml_xsl_url' => style_url('', "mathml.xsl"), 'charset' => @options.charset } template.write_html_on(f, values) end XHTMLGenerator.gen_url(path, file_path) end end end