Skip to content

Commit

Permalink
Convert RDoc to OptionParser, clean up -h output, namespace Options u…
Browse files Browse the repository at this point in the history
…nder RDoc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
drbrain committed Jan 7, 2008
1 parent b912722 commit 4b93d73
Show file tree
Hide file tree
Showing 13 changed files with 635 additions and 594 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Mon Jan 7 15:51:35 2008 Eric Hodel <[email protected]>

* lib/rdoc/options.rb: Convert to OptionParser, clean up -h output,
namespace under RDoc.
* lib/rdoc/*: Namespace RDoc::Options.

Mon Jan 7 15:42:46 2008 NAKAMURA Usaku <[email protected]>

* common.mk, Makefile.in, */Makefile.sub (distclean-local): move
Expand Down
10 changes: 5 additions & 5 deletions bin/rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# search path if necessary.

def adjust_for_existing_rdoc(path)

$stderr.puts %{
It seems as if you have a previously-installed RDoc in
the directory #{path}.
Expand All @@ -44,7 +44,7 @@ def adjust_for_existing_rdoc(path)
end

$:.each do |path|
if /site_ruby/ =~ path
if /site_ruby/ =~ path
rdoc_path = File.join(path, 'rdoc', 'rdoc.rb')
if File.exist?(rdoc_path)
adjust_for_existing_rdoc(path)
Expand All @@ -60,8 +60,8 @@ require 'rdoc/rdoc'

begin
r = RDoc::RDoc.new
r.document(ARGV)
rescue RDoc::RDocError => e
r.document ARGV
rescue RDoc::Error => e
$stderr.puts e.message
exit(1)
exit 1
end
10 changes: 6 additions & 4 deletions lib/rdoc/diagram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# You must have the V1.7 or later in your path
# http://www.research.att.com/sw/tools/graphviz/

require "rdoc/dot"
require 'rdoc/options'
require 'rdoc/dot'

module RDoc

##
# Draw a set of diagrams representing the modules and classes in the
# system. We draw one diagram for each file, and one for each toplevel
# class or module. This means there will be overlap. However, it also
Expand Down Expand Up @@ -167,7 +167,7 @@ def draw_module(mod, graph, toplevel = false, file = nil)

def add_classes(container, graph, file = nil )

use_fileboxes = Options.instance.fileboxes
use_fileboxes = @options.fileboxes

files = {}

Expand Down Expand Up @@ -281,7 +281,7 @@ def add_classes(container, graph, file = nil )
def convert_to_png(file_base, graph)
str = graph.to_s
return @diagram_cache[str] if @diagram_cache[str]
op_type = Options.instance.image_format
op_type = @options.image_format
dotfile = File.join(DOT_PATH, file_base)
src = dotfile + ".dot"
dot = dotfile + "." + op_type
Expand Down Expand Up @@ -332,4 +332,6 @@ def wrap_in_image_map(src, dot)
return res
end
end

end

5 changes: 3 additions & 2 deletions lib/rdoc/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'rdoc/markup/simple_markup'
require 'rdoc/template'

module Generators
end
module RDoc; end # HACK

module RDoc::Generators; end

2 changes: 1 addition & 1 deletion lib/rdoc/generators/chm_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rdoc/generators/html_generator'

class Generators::CHMGenerator < Generators::HTMLGenerator
class RDoc::Generators::CHMGenerator < RDoc::Generators::HTMLGenerator

HHC_PATH = "c:/Program Files/HTML Help Workshop/hhc.exe"

Expand Down
37 changes: 19 additions & 18 deletions lib/rdoc/generators/html_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rdoc/generators'
require 'rdoc/markup/simple_markup/to_html'

module Generators
module RDoc::Generators

##
# Name of sub-direcory that holds file descriptions
Expand Down Expand Up @@ -59,13 +59,16 @@ class HyperlinkHtml < SM::ToHtml
##
# We need to record the html path of our caller so we can generate
# correct relative paths for any hyperlinks that we find
def initialize(from_path, context)
def initialize(from_path, context, options)
super()

@from_path = from_path

@parent_name = context.parent_name
@parent_name += "::" if @parent_name
@context = context

@options = options
end

##
Expand All @@ -80,7 +83,7 @@ def handle_special_CROSSREF(special)
name = special.text
if name[0,1] == '#'
lookup = name[1..-1]
name = lookup unless Options.instance.show_hash
name = lookup unless @options.show_hash
else
lookup = name
end
Expand Down Expand Up @@ -201,7 +204,7 @@ def markup(str, remove_para=false)

end
unless defined? @html_formatter
@html_formatter = HyperlinkHtml.new(self.path, self)
@html_formatter = HyperlinkHtml.new(self.path, self, @options)
end

# Convert leading comment markers to spaces, but only
Expand Down Expand Up @@ -615,9 +618,9 @@ def index_name

def write_on(f)
value_hash
template = TemplatePage.new(RDoc::Page::BODY,
RDoc::Page::CLASS_PAGE,
RDoc::Page::METHOD_LIST)
template = RDoc::TemplatePage.new(RDoc::Page::BODY,
RDoc::Page::CLASS_PAGE,
RDoc::Page::METHOD_LIST)
template.write_html_on(f, @values)
end

Expand Down Expand Up @@ -847,9 +850,9 @@ def value_hash

def write_on(f)
value_hash
template = TemplatePage.new(RDoc::Page::BODY,
RDoc::Page::FILE_PAGE,
RDoc::Page::METHOD_LIST)
template = RDoc::TemplatePage.new(RDoc::Page::BODY,
RDoc::Page::FILE_PAGE,
RDoc::Page::METHOD_LIST)
template.write_html_on(f, @values)
end

Expand Down Expand Up @@ -878,8 +881,6 @@ def <=>(other)

end

##

class HtmlMethod

include MarkUp
Expand Down Expand Up @@ -1014,7 +1015,7 @@ def create_source_code_file(code_body)
FileUtils.mkdir_p(meth_path)
file_path = File.join(meth_path, @seq) + ".html"

template = TemplatePage.new(RDoc::Page::SRC_PAGE)
template = RDoc::TemplatePage.new(RDoc::Page::SRC_PAGE)
File.open(file_path, "w") do |f|
values = {
'title' => CGI.escapeHTML(index_name),
Expand Down Expand Up @@ -1069,7 +1070,7 @@ def markup_code(tokens)
end
end

add_line_numbers(src) if Options.instance.include_line_numbers
add_line_numbers(src) if @options.include_line_numbers
src
end

Expand Down Expand Up @@ -1239,7 +1240,7 @@ def load_html_template
# Write out the style sheet used by the main frames

def write_style_sheet
template = TemplatePage.new(RDoc::Page::STYLE)
template = RDoc::TemplatePage.new(RDoc::Page::STYLE)
unless @options.css
File.open(CSS_NAME, "w") do |f|
values = { "fonts" => RDoc::Page::FONTS }
Expand Down Expand Up @@ -1333,7 +1334,7 @@ def gen_method_index
end

def gen_an_index(collection, title, template, filename)
template = TemplatePage.new(RDoc::Page::FR_INDEX_BODY, template)
template = RDoc::TemplatePage.new(RDoc::Page::FR_INDEX_BODY, template)
res = []
collection.sort.each do |f|
if f.document_self
Expand Down Expand Up @@ -1361,7 +1362,7 @@ def gen_an_index(collection, title, template, filename)
# line.

def gen_main_index
template = TemplatePage.new(RDoc::Page::INDEX)
template = RDoc::TemplatePage.new(RDoc::Page::INDEX)
File.open("index.html", "w") do |f|
values = {
"initial_page" => main_url,
Expand Down Expand Up @@ -1473,7 +1474,7 @@ def generate_xml
# this method is defined in the template file
write_extra_pages if defined? write_extra_pages

template = TemplatePage.new(RDoc::Page::ONE_PAGE)
template = RDoc::TemplatePage.new(RDoc::Page::ONE_PAGE)

if @options.op_name
opfile = File.open(@options.op_name, "w")
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/generators/ri_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'rdoc/ri/ri_writer'
require 'rdoc/ri/ri_descriptions'

class Generators::RIGenerator
class RDoc::Generators::RIGenerator

##
# Generators may need to return specific subclasses depending on the
Expand Down
12 changes: 6 additions & 6 deletions lib/rdoc/generators/xml_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##
# Generate XML output as one big file

class Generators::XMLGenerator < Generators::HTMLGenerator
class RDoc::Generators::XMLGenerator < RDoc::Generators::HTMLGenerator

##
# Standard generator factory
Expand Down Expand Up @@ -42,16 +42,16 @@ def generate(info)

def build_indices
@info.each do |toplevel|
@files << Generators::HtmlFile.new(toplevel, @options, Generators::FILE_DIR)
@files << RDoc::Generators::HtmlFile.new(toplevel, @options, RDoc::Generators::FILE_DIR)
end

RDoc::TopLevel.all_classes_and_modules.each do |cls|
build_class_list(cls, @files[0], Generators::CLASS_DIR)
build_class_list(cls, @files[0], RDoc::Generators::CLASS_DIR)
end
end

def build_class_list(from, html_file, class_dir)
@classes << Generators::HtmlClass.new(from, html_file, class_dir, @options)
@classes << RDoc::Generators::HtmlClass.new(from, html_file, class_dir, @options)
from.each_classmodule do |mod|
build_class_list(mod, html_file, class_dir)
end
Expand All @@ -71,7 +71,7 @@ def generate_xml
# this method is defined in the template file
write_extra_pages if defined? write_extra_pages

template = TemplatePage.new(RDoc::Page::ONE_PAGE)
template = RDoc::TemplatePage.new(RDoc::Page::ONE_PAGE)

if @options.op_name
opfile = File.open(@options.op_name, "w")
Expand All @@ -98,7 +98,7 @@ def gen_class_index
end

def gen_method_index
gen_an_index(Generators::HtmlMethod.all_methods, 'Methods')
gen_an_index(RDoc::Generators::HtmlMethod.all_methods, 'Methods')
end

def gen_an_index(collection, title)
Expand Down
Loading

0 comments on commit 4b93d73

Please sign in to comment.