diff --git a/ChangeLog b/ChangeLog index 9ff3c430e9..883d48692e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Jan 13 12:01:32 2008 Eric Hodel + + * lib/rdoc/generators*: Reorganize RDoc generators. + Sun Jan 13 11:41:11 2008 NARUSE, Yui * encoding.c (ENCINDEX_EUC_JP, ENCINDEX_SJIS): removed. diff --git a/lib/rdoc/generators.rb b/lib/rdoc/generators.rb index ac45622235..2970c89827 100644 --- a/lib/rdoc/generators.rb +++ b/lib/rdoc/generators.rb @@ -1,9 +1,25 @@ require 'cgi' +require 'rdoc' require 'rdoc/options' require 'rdoc/markup/simple_markup' require 'rdoc/template' -module RDoc; end # HACK +module RDoc::Generators -module RDoc::Generators; end + ## + # Name of sub-direcory that holds file descriptions + + FILE_DIR = "files" + + ## + # Name of sub-direcory that holds class descriptions + + CLASS_DIR = "classes" + + ## + # Name of the RDoc CSS file + + CSS_NAME = "rdoc-style.css" + +end diff --git a/lib/rdoc/generators/chm_generator.rb b/lib/rdoc/generators/chm.rb similarity index 89% rename from lib/rdoc/generators/chm_generator.rb rename to lib/rdoc/generators/chm.rb index c3272c9af3..ce05d38d50 100644 --- a/lib/rdoc/generators/chm_generator.rb +++ b/lib/rdoc/generators/chm.rb @@ -1,6 +1,6 @@ -require 'rdoc/generators/html_generator' +require 'rdoc/generators/html' -class RDoc::Generators::CHMGenerator < RDoc::Generators::HTMLGenerator +class RDoc::Generators::CHM < RDoc::Generators::HTML HHC_PATH = "c:/Program Files/HTML Help Workshop/hhc.exe" @@ -52,7 +52,7 @@ class RDoc::Generators::CHMGenerator < RDoc::Generators::HTMLGenerator # files that go to make up the help. def create_project_file - template = RDoc::TemplatePage.new RDoc::Page::HPP_FILE + template = RDoc::TemplatePage.new @template::HPP_FILE values = { "title" => @options.title, "opname" => @op_name } files = [] @files.each do |f| @@ -90,13 +90,13 @@ class RDoc::Generators::CHMGenerator < RDoc::Generators::HTMLGenerator end values = { "contents" => contents } - template = RDoc::TemplatePage.new RDoc::Page::CONTENTS + template = RDoc::TemplatePage.new @template::CONTENTS File.open("contents.hhc", "w") do |f| template.write_html_on(f, values) end values = { "index" => index } - template = RDoc::TemplatePage.new RDoc::Page::CHM_INDEX + template = RDoc::TemplatePage.new @template::CHM_INDEX File.open("index.hhk", "w") do |f| template.write_html_on(f, values) end diff --git a/lib/rdoc/generators/template/chm/chm.rb b/lib/rdoc/generators/chm/chm.rb similarity index 74% rename from lib/rdoc/generators/template/chm/chm.rb rename to lib/rdoc/generators/chm/chm.rb index 1932023416..4134420668 100644 --- a/lib/rdoc/generators/template/chm/chm.rb +++ b/lib/rdoc/generators/chm/chm.rb @@ -1,14 +1,26 @@ -module RDoc::Page +require 'rdoc/generators/chm' +require 'rdoc/generators/html/html' -require "rdoc/generators/template/html/html" +module RDoc::Generators::CHM::CHM -# This is a nasty little hack, but hhc doesn't support the /, '') -SRC_PAGE.sub!(/<\?xml.*\?>/, '') + INDEX = HTML::INDEX -HPP_FILE = %{ + CLASS_INDEX = HTML::CLASS_INDEX + CLASS_PAGE = HTML::CLASS_PAGE + FILE_INDEX = HTML::FILE_INDEX + FILE_PAGE = HTML::FILE_PAGE + METHOD_INDEX = HTML::METHOD_INDEX + METHOD_LIST = HTML::METHOD_LIST + + FR_INDEX_BODY = HTML::FR_INDEX_BODY + + # This is a nasty little hack, but hhc doesn't support the /, '') + SRC_PAGE = HTML::SRC_PAGE.sub!(/<\?xml.*\?>/, '') + + HPP_FILE = <<-EOF [OPTIONS] Auto Index = Yes Compatibility=1.1 or later @@ -23,9 +35,9 @@ Title=<%= values["title"] %> <% values["all_html_files"].each do |all_html_files| %> <%= all_html_files["html_file_name"] %> <% end # values["all_html_files"] %> -} + EOF -CONTENTS = %{ + CONTENTS = <<-EOF @@ -57,9 +69,9 @@ CONTENTS = %{ <% end # values["contents"] %> -} + EOF -CHM_INDEX = %{ + CHM_INDEX = <<-EOF @@ -80,7 +92,7 @@ CHM_INDEX = %{ <% end # values["index"] %> -} + EOF end diff --git a/lib/rdoc/generators/html_generator.rb b/lib/rdoc/generators/html.rb similarity index 95% rename from lib/rdoc/generators/html_generator.rb rename to lib/rdoc/generators/html.rb index a887bd84dc..10244576df 100644 --- a/lib/rdoc/generators/html_generator.rb +++ b/lib/rdoc/generators/html.rb @@ -5,21 +5,6 @@ require 'rdoc/markup/simple_markup/to_html' module RDoc::Generators - ## - # Name of sub-direcory that holds file descriptions - - FILE_DIR = "files" - - ## - # Name of sub-direcory that holds class descriptions - - CLASS_DIR = "classes" - - ## - # Name of the RDoc CSS file - - CSS_NAME = "rdoc-style.css" - ## # Build a hash of all items that can be cross-referenced. # This is used when we output required and included names: @@ -126,7 +111,7 @@ module RDoc::Generators if path[0,1] == '#' # is this meaningful? url = path else - url = HTMLGenerator.gen_url(@from_path, path) + url = HTML.gen_url(@from_path, path) end end @@ -235,7 +220,7 @@ module RDoc::Generators if %r{^(https?:/)?/} =~ css_name return css_name else - return HTMLGenerator.gen_url(path, css_name) + return HTML.gen_url(path, css_name) end end @@ -268,6 +253,9 @@ module RDoc::Generators def initialize(context, options) @context = context @options = options + + # HACK ugly + @template = options.template_class end ## @@ -285,7 +273,7 @@ module RDoc::Generators if @options.all_one_file "#" + path else - HTMLGenerator.gen_url(from_path, path) + HTML.gen_url(from_path, path) end end @@ -513,7 +501,7 @@ module RDoc::Generators end def url(target) - HTMLGenerator.gen_url(path, target) + HTML.gen_url(path, target) end def aref_to(target) @@ -618,9 +606,9 @@ module RDoc::Generators def write_on(f) value_hash - template = RDoc::TemplatePage.new(RDoc::Page::BODY, - RDoc::Page::CLASS_PAGE, - RDoc::Page::METHOD_LIST) + template = RDoc::TemplatePage.new(@template::BODY, + @template::CLASS_PAGE, + @template::METHOD_LIST) template.write_html_on(f, @values) end @@ -851,9 +839,11 @@ module RDoc::Generators def write_on(f) value_hash - template = RDoc::TemplatePage.new(RDoc::Page::BODY, - RDoc::Page::FILE_PAGE, - RDoc::Page::METHOD_LIST) + + template = RDoc::TemplatePage.new(@template::BODY, + @template::FILE_PAGE, + @template::METHOD_LIST) + template.write_html_on(f, @values) end @@ -903,6 +893,10 @@ module RDoc::Generators @context = context @html_class = html_class @options = options + + # HACK ugly + @template = options.template_class + @@seq = @@seq.succ @seq = @@seq @@all_methods << self @@ -913,7 +907,7 @@ module RDoc::Generators @source_code = markup_code(ts) unless @options.inline_source @src_url = create_source_code_file(@source_code) - @img_url = HTMLGenerator.gen_url(path, 'source.png') + @img_url = HTML.gen_url(path, 'source.png') end end @@ -928,7 +922,7 @@ module RDoc::Generators if @options.all_one_file "#" + path else - HTMLGenerator.gen_url(from_path, path) + HTML.gen_url(from_path, path) end end @@ -988,7 +982,6 @@ module RDoc::Generators def params # params coming from a call-seq in 'C' will start with the # method name - p = @context.params if p !~ /^\w/ p = @context.params.gsub(/\s*\#.*/, '') p = p.tr("\n", " ").squeeze(" ") @@ -1016,7 +1009,7 @@ module RDoc::Generators FileUtils.mkdir_p(meth_path) file_path = File.join(meth_path, @seq) + ".html" - template = RDoc::TemplatePage.new(RDoc::Page::SRC_PAGE) + template = RDoc::TemplatePage.new(@template::SRC_PAGE) File.open(file_path, "w") do |f| values = { 'title' => CGI.escapeHTML(index_name), @@ -1026,7 +1019,7 @@ module RDoc::Generators } template.write_html_on(f, values) end - HTMLGenerator.gen_url(path, file_path) + HTML.gen_url(path, file_path) end def self.all_methods @@ -1149,7 +1142,7 @@ module RDoc::Generators # # HTML is generated using the Template class. - class HTMLGenerator + class HTML include MarkUp @@ -1183,9 +1176,9 @@ module RDoc::Generators HtmlMethod.reset if options.all_one_file - HTMLGeneratorInOne.new(options) + HTMLInOne.new(options) else - HTMLGenerator.new(options) + HTML.new(options) end end @@ -1226,12 +1219,17 @@ module RDoc::Generators def load_html_template template = @options.template - unless template =~ %r{/|\\} - template = File.join("rdoc/generators/template", + + unless template =~ %r{/|\\} then + template = File.join("rdoc/generators", @options.generator.key, template) end + require template - extend RDoc::Page + + @template = self.class.const_get @options.template.upcase + @options.template_class = @template + rescue LoadError $stderr.puts "Could not find HTML template '#{template}'" exit 99 @@ -1241,10 +1239,20 @@ module RDoc::Generators # Write out the style sheet used by the main frames def write_style_sheet - template = RDoc::TemplatePage.new(RDoc::Page::STYLE) - unless @options.css + return unless @template.constants.include? :STYLE or + @template.constants.include? 'STYLE' + + template = RDoc::TemplatePage.new @template::STYLE + + unless @options.css then File.open(CSS_NAME, "w") do |f| - values = { "fonts" => RDoc::Page::FONTS } + values = {} + + if @template.constants.include? :FONTS or + @template.constants.include? 'FONTS' then + values["fonts"] = @template::FONTS + end + template.write_html_on(f, values) end end @@ -1316,25 +1324,21 @@ module RDoc::Generators end def gen_file_index - gen_an_index(@files, 'Files', - RDoc::Page::FILE_INDEX, - "fr_file_index.html") + gen_an_index @files, 'Files', @template::FILE_INDEX, "fr_file_index.html" end def gen_class_index - gen_an_index(@classes, 'Classes', - RDoc::Page::CLASS_INDEX, + gen_an_index(@classes, 'Classes', @template::CLASS_INDEX, "fr_class_index.html") end def gen_method_index - gen_an_index(HtmlMethod.all_methods, 'Methods', - RDoc::Page::METHOD_INDEX, + gen_an_index(HtmlMethod.all_methods, 'Methods', @template::METHOD_INDEX, "fr_method_index.html") end def gen_an_index(collection, title, template, filename) - template = RDoc::TemplatePage.new(RDoc::Page::FR_INDEX_BODY, template) + template = RDoc::TemplatePage.new @template::FR_INDEX_BODY, template res = [] collection.sort.each do |f| if f.document_self @@ -1362,7 +1366,7 @@ module RDoc::Generators # line. def gen_main_index - template = RDoc::TemplatePage.new RDoc::Page::INDEX + template = RDoc::TemplatePage.new @template::INDEX open 'index.html', 'w' do |f| classes = @classes.sort.map { |klass| klass.value_hash } @@ -1413,7 +1417,7 @@ module RDoc::Generators end - class HTMLGeneratorInOne < HTMLGenerator + class HTMLInOne < HTML def initialize(*args) super @@ -1476,7 +1480,7 @@ module RDoc::Generators # this method is defined in the template file write_extra_pages if defined? write_extra_pages - template = RDoc::TemplatePage.new(RDoc::Page::ONE_PAGE) + template = RDoc::TemplatePage.new @template::ONE_PAGE if @options.op_name opfile = File.open(@options.op_name, "w") diff --git a/lib/rdoc/generators/template/html/hefss.rb b/lib/rdoc/generators/html/hefss.rb similarity index 89% rename from lib/rdoc/generators/template/html/hefss.rb rename to lib/rdoc/generators/html/hefss.rb index a7baac6fd3..c7b4fcc449 100644 --- a/lib/rdoc/generators/template/html/hefss.rb +++ b/lib/rdoc/generators/html/hefss.rb @@ -1,15 +1,16 @@ -module RDoc -module Page +require 'rdoc/generators/html' +require 'rdoc/generators/html/html' +module RDoc::Generators::HTML::HEFSS -FONTS = "Verdana, Arial, Helvetica, sans-serif" + FONTS = "Verdana, Arial, Helvetica, sans-serif" -STYLE = %{ -body,p { font-family: Verdana, Arial, Helvetica, sans-serif; +STYLE = <<-EOF +body,p { font-family: Verdana, Arial, Helvetica, sans-serif; color: #000040; background: #BBBBBB; } -td { font-family: Verdana, Arial, Helvetica, sans-serif; +td { font-family: Verdana, Arial, Helvetica, sans-serif; color: #000040; } @@ -21,7 +22,7 @@ td { font-family: Verdana, Arial, Helvetica, sans-serif; .big-title-font { color: white; font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: large; + font-size: large; height: 50px} .small-title-font { color: purple; @@ -104,13 +105,9 @@ td { font-family: Verdana, Arial, Helvetica, sans-serif; .srcbut { float: right } -} + EOF - -############################################################################ - - -BODY = %{ + BODY = <<-EOF <%= values["title"] %> "> @@ -198,11 +195,9 @@ BODY = %{ -} + EOF -############################################################################### - -FILE_PAGE = <<_FILE_PAGE_ + FILE_PAGE = <<-EOF
@@ -224,11 +219,9 @@ FILE_PAGE = <<_FILE_PAGE_

-_FILE_PAGE_ + EOF -################################################################### - -CLASS_PAGE = %{ + CLASS_PAGE = <<-EOF
@@ -265,11 +258,9 @@ CLASS_PAGE = %{

-} + EOF -################################################################### - -METHOD_LIST = %{ + METHOD_LIST = <<-EOF <% if values["includes"] then %>
Uses

@@ -308,14 +299,9 @@ METHOD_LIST = %{ <% end %> <% end # values["sections"] %> <% end %> -} + EOF -=begin -=end - -########################## Source code ########################## - -SRC_PAGE = %{ + SRC_PAGE = <<-EOF <%= values["title"] %> "> @@ -339,15 +325,13 @@ SRC_PAGE = %{
<%= values["code"] %>
-} + EOF -########################## Index ################################ - -FR_INDEX_BODY = %{ + FR_INDEX_BODY = %{ <%= template_include %> } -FILE_INDEX = %{ + FILE_INDEX = <<-EOF "> @@ -355,10 +339,10 @@ FILE_INDEX = %{ @@ -620,13 +618,11 @@ BODY = HEADER + %{ } + FOOTER - - ##################################################################### ### S O U R C E C O D E T E M P L A T E ##################################################################### -SRC_PAGE = XHTML_PREAMBLE + <<-EOF + SRC_PAGE = XHTML_PREAMBLE + <<-EOF <%= values["title"] %> @@ -637,18 +633,18 @@ SRC_PAGE = XHTML_PREAMBLE + <<-EOF
<%= values["code"] %>
-EOF + EOF ##################################################################### ### I N D E X F I L E T E M P L A T E S ##################################################################### -FR_INDEX_BODY = %{ + FR_INDEX_BODY = %{ <%= template_include %> } -FILE_INDEX = XHTML_PREAMBLE + %{ + FILE_INDEX = XHTML_PREAMBLE + <<-EOF @@ -383,12 +366,12 @@ div.banner { "><%= entries["name"] %>
<% end # values["entries"] %> -} + EOF -CLASS_INDEX = FILE_INDEX -METHOD_INDEX = FILE_INDEX + CLASS_INDEX = FILE_INDEX + METHOD_INDEX = FILE_INDEX -INDEX = %{ + INDEX = <<-EOF <%= values["title"] %> @@ -419,17 +402,17 @@ INDEX = %{ -} + EOF -# and a blank page to use as a target -BLANK = %{ + # A blank page to use as a target + BLANK = %{ } -def write_extra_pages - template = TemplatePage.new(BLANK) - File.open("blank.html", "w") { |f| template.write_html_on(f, {}) } -end + def write_extra_pages + template = TemplatePage.new(BLANK) + File.open("blank.html", "w") { |f| template.write_html_on(f, {}) } + end end -end + diff --git a/lib/rdoc/generators/template/html/one_page_html.rb b/lib/rdoc/generators/html/one_page_html.rb similarity index 96% rename from lib/rdoc/generators/template/html/one_page_html.rb rename to lib/rdoc/generators/html/one_page_html.rb index 170bbf23c8..dbac9e2f5a 100644 --- a/lib/rdoc/generators/template/html/one_page_html.rb +++ b/lib/rdoc/generators/html/one_page_html.rb @@ -1,6 +1,8 @@ -module RDoc::Page +require 'rdoc/generators/html' -CONTENTS_XML = %{ +module RDoc::Generators::HTML::ONE_PAGE_HTML + + CONTENTS_XML = <<-EOF <% if defined? classes and classes["description"] then %> <%= classes["description"] %> <% end %> @@ -72,11 +74,9 @@ CONTENTS_XML = %{ <% end %> <% end # classes["sections"] %> <% end %> -} + EOF -######################################################################## - -ONE_PAGE = %{ + ONE_PAGE = %{ diff --git a/lib/rdoc/generators/ri_generator.rb b/lib/rdoc/generators/ri.rb similarity index 98% rename from lib/rdoc/generators/ri_generator.rb rename to lib/rdoc/generators/ri.rb index 111a232856..a8cacc7501 100644 --- a/lib/rdoc/generators/ri_generator.rb +++ b/lib/rdoc/generators/ri.rb @@ -6,7 +6,7 @@ require 'rdoc/ri/reader' require 'rdoc/ri/writer' require 'rdoc/ri/descriptions' -class RDoc::Generators::RIGenerator +class RDoc::Generators::RI ## # Generators may need to return specific subclasses depending on the @@ -21,7 +21,7 @@ class RDoc::Generators::RIGenerator end ## - # Set up a new RIGenerator. + # Set up a new RDoc::Generators::RI. def initialize(options) #:not-new: @options = options diff --git a/lib/rdoc/generators/xml_generator.rb b/lib/rdoc/generators/xml.rb similarity index 93% rename from lib/rdoc/generators/xml_generator.rb rename to lib/rdoc/generators/xml.rb index fe772f9ef4..d84cecc05c 100644 --- a/lib/rdoc/generators/xml_generator.rb +++ b/lib/rdoc/generators/xml.rb @@ -1,9 +1,9 @@ -require 'rdoc/generators/html_generator' +require 'rdoc/generators/html' ## # Generate XML output as one big file -class RDoc::Generators::XMLGenerator < RDoc::Generators::HTMLGenerator +class RDoc::Generators::XML < RDoc::Generators::HTML ## # Standard generator factory @@ -71,7 +71,7 @@ class RDoc::Generators::XMLGenerator < RDoc::Generators::HTMLGenerator # this method is defined in the template file write_extra_pages if defined? write_extra_pages - template = RDoc::TemplatePage.new(RDoc::Page::ONE_PAGE) + template = RDoc::TemplatePage.new @template::ONE_PAGE if @options.op_name opfile = File.open(@options.op_name, "w") diff --git a/lib/rdoc/generators/template/xml/rdf.rb b/lib/rdoc/generators/xml/rdf.rb similarity index 95% rename from lib/rdoc/generators/template/xml/rdf.rb rename to lib/rdoc/generators/xml/rdf.rb index fbeb599ce6..3f6643e15b 100644 --- a/lib/rdoc/generators/template/xml/rdf.rb +++ b/lib/rdoc/generators/xml/rdf.rb @@ -1,6 +1,8 @@ -module RDoc::Page +require 'rdoc/generators/xml' -CONTENTS_RDF = %{ +module RDoc::Generators::XML::RDF + + CONTENTS_RDF = <<-EOF <% if defined? classes and classes["description"] then %> <%= classes["description"] %> @@ -63,11 +65,11 @@ CONTENTS_RDF = %{ <% end # classes["sections"] %> <% end %> -} + EOF ######################################################################## -ONE_PAGE = %{ + ONE_PAGE = %{ diff --git a/lib/rdoc/generators/template/xml/xml.rb b/lib/rdoc/generators/xml/xml.rb similarity index 93% rename from lib/rdoc/generators/template/xml/xml.rb rename to lib/rdoc/generators/xml/xml.rb index ab6355a1c5..e711b514fa 100644 --- a/lib/rdoc/generators/template/xml/xml.rb +++ b/lib/rdoc/generators/xml/xml.rb @@ -1,6 +1,8 @@ -module RDoc::Page +require 'rdoc/generators/xml' -CONTENTS_XML = %{ +module RDoc::Generators::XML::XML + + CONTENTS_XML = <<-EOF <% if defined? classes and classes["description"] then %> <%= classes["description"] %> @@ -11,7 +13,7 @@ CONTENTS_XML = %{ <% files["requires"].each do |requires| %> " -<% if requires["aref"] then %> +<% if requires["aref"] then %> href="<%= requires["aref"] %>" <% end %> /> @@ -69,11 +71,9 @@ CONTENTS_XML = %{ <% end %> -} + EOF -######################################################################## - -ONE_PAGE = %{ + ONE_PAGE = %{ <% values["files"].each do |files| %> @@ -91,7 +91,7 @@ ONE_PAGE = %{ <<%= classes["classmod"] %> name="<%= classes["full_name"] %>" id="<%= classes["full_name"] %>"> <% if classes["infiles"] then %> - + <% classes["infiles"].each do |infiles| %> <%= href infiles["full_path_url"], infiles["full_path"] %> <% end # classes["infiles"] %> diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 078635121c..a36fb017ad 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -132,6 +132,13 @@ class RDoc::Options attr_reader :template + ## + # Template class for file generation + #-- + # HACK around dependencies in lib/rdoc/generators/html.rb + + attr_accessor :template_class # :nodoc: + ## # Documentation title @@ -156,6 +163,7 @@ class RDoc::Options @rdoc_include = [] @title = nil @template = nil + @template_class = nil @diagram = false @fileboxes = false @show_hash = false @@ -379,6 +387,7 @@ Usage: #{opt.program_name} [options] [names...] "Put all the output into a single file.") do |value| @all_one_file = value @inline_source = value if value + @template = 'one_page_html' end opt.separator nil @@ -411,7 +420,7 @@ Usage: #{opt.program_name} [options] [names...] opt.on("--quiet", "-q", "Don't show progress as we parse.") do |value| - @quite = value + @quiet = value end opt.separator nil diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 115cb69f37..b376653549 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -68,11 +68,11 @@ module RDoc File.directory? "#{d}/rdoc/generators" end.each do |dir| Dir.entries("#{dir}/rdoc/generators").each do |gen| - next unless /(\w+)_generator.rb$/ =~ gen + next unless /(\w+)\.rb$/ =~ gen type = $1 unless GENERATORS.has_key? type GENERATORS[type] = Generator.new("rdoc/generators/#{gen}", - "#{type.upcase}Generator".intern, + "#{type.upcase}".intern, type) end end