1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rdoc/code_objects.rb: Make some attributes accessible for reuse.

* lib/rdoc/generator/html.rb: Pull out ContextUser classes and related
	  methods for reuse.
	* lib/rdoc/generator.rb: Move ContextUser classes to
	  RDoc::Generator::Context for reuse.
	* lib/rdoc/rdoc.rb: Make RDoc::RDoc initialization a little easier.
	* lib/rdoc/options.rb: Make RDoc::Options easier to use without
	  parsing an ARGV.
	* lib/rdoc/markup/to_*.rb: Subclass RDoc::Markup::Formatter.
	* lib/rdoc/markup/formatter.rb: Add RDoc::Markup::Formatter to make
	  RDoc markup conversion easier.
	* lib/rdoc/markup/fragments.rb: Make RDoc::Markup::ListItem easier to
	  test.
	* lib/rdoc/markup/to_html_hyperlink.rb: Pulled out of the HTML
	  generator for easier reusability.
	* lib/rdoc/markup.rb: Fix bug with labeled lists containing bullet
	  lists.
	* lib/rdoc/generators/html/html.rb: Fix Constant display.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2008-02-10 03:59:08 +00:00
parent d44f24c47c
commit 455b051a00
21 changed files with 1839 additions and 1588 deletions

View file

@ -1,3 +1,24 @@
Sun Feb 10 12:58:33 2008 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/code_objects.rb: Make some attributes accessible for reuse.
* lib/rdoc/generator/html.rb: Pull out ContextUser classes and related
methods for reuse.
* lib/rdoc/generator.rb: Move ContextUser classes to
RDoc::Generator::Context for reuse.
* lib/rdoc/rdoc.rb: Make RDoc::RDoc initialization a little easier.
* lib/rdoc/options.rb: Make RDoc::Options easier to use without
parsing an ARGV.
* lib/rdoc/markup/to_*.rb: Subclass RDoc::Markup::Formatter.
* lib/rdoc/markup/formatter.rb: Add RDoc::Markup::Formatter to make
RDoc markup conversion easier.
* lib/rdoc/markup/fragments.rb: Make RDoc::Markup::ListItem easier to
test.
* lib/rdoc/markup/to_html_hyperlink.rb: Pulled out of the HTML
generator for easier reusability.
* lib/rdoc/markup.rb: Fix bug with labeled lists containing bullet
lists.
* lib/rdoc/generators/html/html.rb: Fix Constant display.
Sat Feb 9 23:44:29 2008 Tanaka Akira <akr@fsij.org> Sat Feb 9 23:44:29 2008 Tanaka Akira <akr@fsij.org>
* missing/tgamma.c (tgamma): use lgamma_r if available. * missing/tgamma.c (tgamma): use lgamma_r if available.

View file

@ -5,10 +5,10 @@ require 'rdoc/tokenstream'
module RDoc module RDoc
##
# We contain the common stuff for contexts (which are containers) # We contain the common stuff for contexts (which are containers)
# and other elements (methods, attributes and so on) # and other elements (methods, attributes and so on)
#
class CodeObject class CodeObject
attr_accessor :parent attr_accessor :parent
@ -82,8 +82,7 @@ module RDoc
# Access the code object's comment # Access the code object's comment
attr_reader :comment attr_reader :comment
# Update the comment, but don't overwrite a real comment # Update the comment, but don't overwrite a real comment with an empty one
# with an empty one
def comment=(comment) def comment=(comment)
@comment = comment unless comment.empty? @comment = comment unless comment.empty?
end end
@ -94,7 +93,7 @@ module RDoc
# those directives. Wehn a comment is assigned, we then extract # those directives. Wehn a comment is assigned, we then extract
# out any matching directives and update our object # out any matching directives and update our object
def CodeObject.attr_overridable(name, *aliases) def self.attr_overridable(name, *aliases)
@overridables ||= {} @overridables ||= {}
attr_accessor name attr_accessor name
@ -623,7 +622,7 @@ module RDoc
end end
end end
##
# AnyMethod is the base class for objects representing methods # AnyMethod is the base class for objects representing methods
class AnyMethod < CodeObject class AnyMethod < CodeObject
@ -632,14 +631,18 @@ module RDoc
attr_accessor :block_params attr_accessor :block_params
attr_accessor :dont_rename_initialize attr_accessor :dont_rename_initialize
attr_accessor :singleton attr_accessor :singleton
attr_reader :aliases # list of other names for this method attr_reader :text
attr_accessor :is_alias_for # or a method we're aliasing
# list of other names for this method
attr_reader :aliases
# method we're aliasing
attr_accessor :is_alias_for
attr_overridable :params, :param, :parameters, :parameter attr_overridable :params, :param, :parameters, :parameter
attr_accessor :call_seq attr_accessor :call_seq
include TokenStream include TokenStream
def initialize(text, name) def initialize(text, name)
@ -693,7 +696,6 @@ $stderr.puts p
end end
end end
# Represent an alias, which is an old_name/ new_name pair associated # Represent an alias, which is an old_name/ new_name pair associated
# with a particular context # with a particular context
class Alias < CodeObject class Alias < CodeObject

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -478,14 +478,14 @@ EOF
<div class="name-list"> <div class="name-list">
<table summary="Constants"> <table summary="Constants">
<% values["constants"].each do |constants| $stderr.puts({ :constants => constants }.inspect) %> <% values["constants"].each do |constants| %>
<tr class="top-aligned-row context-row"> <tr class="top-aligned-row context-row">
<td class="context-item-name"><%= values["name"] %></td> <td class="context-item-name"><%= constants["name"] %></td>
<td>=</td> <td>=</td>
<td class="context-item-value"><%= values["value"] %></td> <td class="context-item-value"><%= constants["value"] %></td>
<% if values["desc"] then %> <% if values["desc"] then %>
<td width="3em">&nbsp;</td> <td width="3em">&nbsp;</td>
<td class="context-item-desc"><%= values["desc"] %></td> <td class="context-item-desc"><%= constants["desc"] %></td>
<% end %> <% end %>
</tr> </tr>
<% end # values["constants"] %> <% end # values["constants"] %>

View file

@ -146,16 +146,16 @@ require 'rdoc'
# end # end
# end # end
# #
# p = RDoc::Markup.new # m = RDoc::Markup.new
# p.add_word_pair("{", "}", :STRIKE) # m.add_word_pair("{", "}", :STRIKE)
# p.add_html("no", :STRIKE) # m.add_html("no", :STRIKE)
# #
# p.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD) # m.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
# #
# h = WikiHtml.new # h = WikiHtml.new
# h.add_tag(:STRIKE, "<strike>", "</strike>") # h.add_tag(:STRIKE, "<strike>", "</strike>")
# #
# puts "<body>" + p.convert(ARGF.read, h) + "</body>" # puts "<body>" + m.convert(ARGF.read, h) + "</body>"
# #
#-- #--
# Author:: Dave Thomas, dave@pragmaticprogrammer.com # Author:: Dave Thomas, dave@pragmaticprogrammer.com
@ -194,7 +194,7 @@ class RDoc::Markup
# identify significant chunks. # identify significant chunks.
def initialize def initialize
@am = AttributeManager.new @am = RDoc::Markup::AttributeManager.new
@output = nil @output = nil
end end
@ -234,15 +234,16 @@ class RDoc::Markup
# display the result. # display the result.
def convert(str, op) def convert(str, op)
@lines = Lines.new(str.split(/\r?\n/).collect { |aLine| lines = str.split(/\r?\n/).map { |line| Line.new line }
Line.new(aLine) }) @lines = Lines.new lines
return "" if @lines.empty? return "" if @lines.empty?
@lines.normalize @lines.normalize
assign_types_to_lines assign_types_to_lines
group = group_lines group = group_lines
# call the output formatter to handle the result # call the output formatter to handle the result
# group.to_a.each {|i| p i} #group.each { |line| p line }
group.accept(@am, op) group.accept @am, op
end end
private private
@ -252,9 +253,8 @@ class RDoc::Markup
# Blank, a paragraph, a list element, or verbatim text. # Blank, a paragraph, a list element, or verbatim text.
def assign_types_to_lines(margin = 0, level = 0) def assign_types_to_lines(margin = 0, level = 0)
while line = @lines.next while line = @lines.next
if line.isBlank? if line.blank? then
line.stamp :BLANK, level line.stamp :BLANK, level
next next
end end
@ -289,7 +289,6 @@ class RDoc::Markup
# text following them (* xxx, - xxx, and dd. xxx) # text following them (* xxx, - xxx, and dd. xxx)
if SIMPLE_LIST_RE =~ active_line if SIMPLE_LIST_RE =~ active_line
offset = margin + $1.length offset = margin + $1.length
prefix = $2 prefix = $2
prefix_length = prefix.length prefix_length = prefix.length
@ -308,7 +307,6 @@ class RDoc::Markup
next next
end end
if LABEL_LIST_RE =~ active_line if LABEL_LIST_RE =~ active_line
offset = margin + $1.length offset = margin + $1.length
prefix = $2 prefix = $2
@ -366,22 +364,23 @@ class RDoc::Markup
prefix_length = prefix.length prefix_length = prefix.length
text = line.text text = line.text
flag = nil flag = nil
case prefix case prefix
when /^\[/ when /^\[/ then
flag = :LABELED flag = :LABELED
prefix = prefix[1, prefix.length-2] prefix = prefix[1, prefix.length-2]
when /:$/ when /:$/ then
flag = :NOTE flag = :NOTE
prefix.chop! prefix.chop!
else raise "Invalid List Type: #{self.inspect}" else
raise "Invalid List Type: #{self.inspect}"
end end
# body is on the next line # body is on the next line
if text.length <= offset then
if text.length <= offset
original_line = line original_line = line
line = @lines.next line = @lines.next
return(false) unless line return false unless line
text = line.text text = line.text
for i in 0..margin for i in 0..margin
@ -390,15 +389,24 @@ class RDoc::Markup
return false return false
end end
end end
i = margin i = margin
i += 1 while text[i] == SPACE i += 1 while text[i] == SPACE
if i >= text.length
if i >= text.length then
@lines.unget @lines.unget
return false return false
else else
offset = i offset = i
prefix_length = 0 prefix_length = 0
@lines.delete(original_line)
if text[offset..-1] =~ SIMPLE_LIST_RE then
@lines.unget
line = original_line
line.text = ''
else
@lines.delete original_line
end
end end
end end
@ -418,24 +426,26 @@ class RDoc::Markup
def group_lines def group_lines
@lines.rewind @lines.rewind
inList = false in_list = false
wantedType = wantedLevel = nil wanted_type = wanted_level = nil
block = LineCollection.new block = LineCollection.new
group = nil group = nil
while line = @lines.next while line = @lines.next
if line.level == wantedLevel and line.type == wantedType if line.level == wanted_level and line.type == wanted_type
group.add_text(line.text) group.add_text(line.text)
else else
group = block.fragment_for(line) group = block.fragment_for(line)
block.add(group) block.add(group)
if line.type == :LIST if line.type == :LIST
wantedType = :PARAGRAPH wanted_type = :PARAGRAPH
else else
wantedType = line.type wanted_type = line.type
end end
wantedLevel = line.type == :HEADING ? line.param : line.level
wanted_level = line.type == :HEADING ? line.param : line.level
end end
end end
@ -462,4 +472,5 @@ class RDoc::Markup
end end
require 'rdoc/markup/fragments' require 'rdoc/markup/fragments'
require 'rdoc/markup/inline'
require 'rdoc/markup/lines' require 'rdoc/markup/lines'

View file

@ -0,0 +1,14 @@
require 'rdoc/markup'
class RDoc::Markup::Formatter
def initialize
@markup = RDoc::Markup.new
end
def convert(content)
@markup.convert content, self
end
end

View file

@ -83,10 +83,16 @@ class RDoc::Markup
class ListItem < ListBase class ListItem < ListBase
type_name :LIST type_name :LIST
# def label def to_s
# am = AttributeManager.new(@param) text = if [:NOTE, :LABELED].include? type then
# am.flow "#{@param}: #{@txt}"
# end else
@txt
end
"L#@level: #{type} #{self.class.name.split('::')[-1]}\n#{text}"
end
end end
class ListStart < ListBase class ListStart < ListBase
@ -311,9 +317,8 @@ class RDoc::Markup
def tidy_blank_lines def tidy_blank_lines
(@fragments.size - 1).times do |i| (@fragments.size - 1).times do |i|
if @fragments[i].kind_of?(BlankLine) and if BlankLine === @fragments[i] and ListEnd === @fragments[i+1] then
@fragments[i+1].kind_of?(ListEnd) @fragments[i], @fragments[i+1] = @fragments[i+1], @fragments[i]
@fragments[i], @fragments[i+1] = @fragments[i+1], @fragments[i]
end end
end end

View file

@ -12,9 +12,9 @@ class RDoc::Markup
@@name_to_bitmap = { :_SPECIAL_ => SPECIAL } @@name_to_bitmap = { :_SPECIAL_ => SPECIAL }
@@next_bitmap = 2 @@next_bitmap = 2
def Attribute.bitmap_for(name) def self.bitmap_for(name)
bitmap = @@name_to_bitmap[name] bitmap = @@name_to_bitmap[name]
if !bitmap unless bitmap then
bitmap = @@next_bitmap bitmap = @@next_bitmap
@@next_bitmap <<= 1 @@next_bitmap <<= 1
@@name_to_bitmap[name] = bitmap @@name_to_bitmap[name] = bitmap
@ -22,7 +22,7 @@ class RDoc::Markup
bitmap bitmap
end end
def Attribute.as_string(bitmap) def self.as_string(bitmap)
return "none" if bitmap.zero? return "none" if bitmap.zero?
res = [] res = []
@@name_to_bitmap.each do |name, bit| @@name_to_bitmap.each do |name, bit|
@ -31,7 +31,7 @@ class RDoc::Markup
res.join(",") res.join(",")
end end
def Attribute.each_name_of(bitmap) def self.each_name_of(bitmap)
@@name_to_bitmap.each do |name, bit| @@name_to_bitmap.each do |name, bit|
next if bit == SPECIAL next if bit == SPECIAL
yield name.to_s if (bitmap & bit) != 0 yield name.to_s if (bitmap & bit) != 0
@ -85,14 +85,15 @@ class RDoc::Markup
self.text == o.text && self.type == o.type self.text == o.text && self.type == o.type
end end
def to_s
"Special: type=#{type}, name=#{RDoc::Markup::Attribute.as_string type}, text=#{text.dump}"
end
def inspect def inspect
"#<RDoc::Markup::Special:0x%x @type=%p, name=%p @text=%p>" % [ "#<RDoc::Markup::Special:0x%x @type=%p, name=%p @text=%p>" % [
object_id, @type, RDoc::Markup::Attribute.as_string(type), text.dump] object_id, @type, RDoc::Markup::Attribute.as_string(type), text.dump]
end end
def to_s
"Special: type=#{type}, name=#{RDoc::Markup::Attribute.as_string type}, text=#{text.dump}"
end
end end
class AttributeManager class AttributeManager
@ -165,8 +166,10 @@ class RDoc::Markup
def convert_attrs(str, attrs) def convert_attrs(str, attrs)
# first do matching ones # first do matching ones
tags = MATCHING_WORD_PAIRS.keys.join("") tags = MATCHING_WORD_PAIRS.keys.join("")
re = "(^|\\W)([#{tags}])([A-Za-z_]+?)\\2(\\W|\$)" re = "(^|\\W)([#{tags}])([A-Za-z_]+?)\\2(\\W|\$)"
# re = "(^|\\W)([#{tags}])(\\S+?)\\2(\\W|\$)" # re = "(^|\\W)([#{tags}])(\\S+?)\\2(\\W|\$)"
1 while str.gsub!(Regexp.new(re)) { 1 while str.gsub!(Regexp.new(re)) {
attr = MATCHING_WORD_PAIRS[$2]; attr = MATCHING_WORD_PAIRS[$2];
attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr) attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
@ -185,9 +188,9 @@ class RDoc::Markup
end end
def convert_html(str, attrs) def convert_html(str, attrs)
tags = HTML_TAGS.keys.join("|") tags = HTML_TAGS.keys.join '|'
re = "<(#{tags})>(.*?)</\\1>"
1 while str.gsub!(Regexp.new(re, Regexp::IGNORECASE)) { 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) {
attr = HTML_TAGS[$1.downcase] attr = HTML_TAGS[$1.downcase]
html_length = $1.length + 2 html_length = $1.length + 2
seq = NULL * html_length seq = NULL * html_length
@ -210,7 +213,7 @@ class RDoc::Markup
# A \ in front of a character that would normally be processed turns off # A \ in front of a character that would normally be processed turns off
# processing. We do this by turning \< into <#{PROTECT} # processing. We do this by turning \< into <#{PROTECT}
PROTECTABLE = [ "<" << "\\" ] #" PROTECTABLE = [ "<" << "\\" ]
def mask_protected_sequences def mask_protected_sequences
@ -300,7 +303,6 @@ class RDoc::Markup
end end
def split_into_flow def split_into_flow
display_attributes if $DEBUG_RDOC display_attributes if $DEBUG_RDOC
res = [] res = []

View file

@ -59,8 +59,8 @@ class RDoc::Markup
end end
# Return true if this line is blank # Return true if this line is blank
def isBlank? def blank?
@text.length.zero? @text.empty?
end end
# stamp a line with a type, a level, a prefix, and a flag # stamp a line with a type, a level, a prefix, and a flag

View file

@ -1,3 +1,4 @@
require 'rdoc/markup/formatter'
require 'rdoc/markup/fragments' require 'rdoc/markup/fragments'
require 'rdoc/markup/inline' require 'rdoc/markup/inline'
require 'cgi' require 'cgi'
@ -22,7 +23,7 @@ class RDoc::Markup
H = Struct.new(:level, :text) H = Struct.new(:level, :text)
end end
class ToFlow class ToFlow < RDoc::Markup::Formatter
LIST_TYPE_TO_HTML = { LIST_TYPE_TO_HTML = {
:BULLET => [ "<ul>", "</ul>" ], :BULLET => [ "<ul>", "</ul>" ],
:NUMBER => [ "<ol>", "</ol>" ], :NUMBER => [ "<ol>", "</ol>" ],
@ -35,6 +36,8 @@ class RDoc::Markup
InlineTag = Struct.new(:bit, :on, :off) InlineTag = Struct.new(:bit, :on, :off)
def initialize def initialize
super
init_tags init_tags
end end

View file

@ -1,22 +1,25 @@
require 'rdoc/markup/formatter'
require 'rdoc/markup/fragments' require 'rdoc/markup/fragments'
require 'rdoc/markup/inline' require 'rdoc/markup/inline'
require 'cgi' require 'cgi'
class RDoc::Markup::ToHtml class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
LIST_TYPE_TO_HTML = { LIST_TYPE_TO_HTML = {
:BULLET => [ "<ul>", "</ul>" ], :BULLET => %w[<ul> </ul>],
:NUMBER => [ "<ol>", "</ol>" ], :NUMBER => %w[<ol> </ol>],
:UPPERALPHA => [ "<ol>", "</ol>" ], :UPPERALPHA => %w[<ol> </ol>],
:LOWERALPHA => [ "<ol>", "</ol>" ], :LOWERALPHA => %w[<ol> </ol>],
:LABELED => [ "<dl>", "</dl>" ], :LABELED => %w[<dl> </dl>],
:NOTE => [ "<table>", "</table>" ], :NOTE => %w[<table> </table>],
} }
InlineTag = Struct.new(:bit, :on, :off) InlineTag = Struct.new(:bit, :on, :off)
def initialize def initialize
super
init_tags init_tags
end end
@ -94,8 +97,11 @@ class RDoc::Markup::ToHtml
if tag = @in_list_entry.last if tag = @in_list_entry.last
@res << annotate(tag) << "\n" @res << annotate(tag) << "\n"
end end
@res << list_item_start(am, fragment) @res << list_item_start(am, fragment)
@res << wrap(convert_flow(am.flow(fragment.txt))) << "\n" @res << wrap(convert_flow(am.flow(fragment.txt))) << "\n"
@in_list_entry[-1] = list_end_for(fragment.type) @in_list_entry[-1] = list_end_for(fragment.type)
end end

View file

@ -0,0 +1,149 @@
require 'rdoc/markup/to_html'
##
# Subclass of the RDoc::Markup::ToHtml class that supports looking up words in
# the AllReferences list. Those that are found (like AllReferences in this
# comment) will be hyperlinked
class RDoc::Markup::ToHtmlHyperlink < RDoc::Markup::ToHtml
attr_accessor :context
##
# 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, show_hash)
super()
# class names, variable names, or instance variables
@markup.add_special(/(
# A::B.meth(**) (for operator in Fortran95)
\w+(::\w+)*[.\#]\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?
# meth(**) (for operator in Fortran95)
| \#\w+(\([.\w\*\/\+\-\=\<\>]+\))?
| \b([A-Z]\w*(::\w+)*[.\#]\w+) # A::B.meth
| \b([A-Z]\w+(::\w+)*) # A::B
| \#\w+[!?=]? # #meth_name
| \\?\b\w+([_\/\.]+\w+)*[!?=]? # meth_name
)/x,
:CROSSREF)
# external hyperlinks
@markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
# and links of the form <text>[<url>]
@markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
@from_path = from_path
@context = context
@show_hash = show_hash
@seen = {}
end
##
# We're invoked when any text matches the CROSSREF pattern
# (defined in MarkUp). If we fine the corresponding reference,
# generate a hyperlink. If the name we're looking for contains
# no punctuation, we look for it up the module/class chain. For
# example, HyperlinkHtml is found, even without the Generator::
# prefix, because we look for it in module Generator first.
def handle_special_CROSSREF(special)
name = special.text
return @seen[name] if @seen.include? name
if name[0,1] == '#' then
lookup = name[1..-1]
name = lookup unless @show_hash
else
lookup = name
end
# Find class, module, or method in class or module.
if /([A-Z]\w*)[.\#](\w+[!?=]?)/ =~ lookup then
container = $1
method = $2
ref = @context.find_symbol container, method
elsif /([A-Za-z]\w*)[.\#](\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?)/ =~ lookup then
container = $1
method = $2
ref = @context.find_symbol container, method
else
ref = @context.find_symbol lookup
end
out = if lookup =~ /^\\/ then
$'
elsif ref and ref.document_self then
"<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
else
name
end
@seen[name] = out
out
end
##
# Generate a hyperlink for url, labeled with text. Handle the
# special cases for img: and link: described under handle_special_HYPEDLINK
def gen_url(url, text)
if url =~ /([A-Za-z]+):(.*)/ then
type = $1
path = $2
else
type = "http"
path = url
url = "http://#{url}"
end
if type == "link" then
url = if path[0, 1] == '#' then # is this meaningful?
path
else
HTML.gen_url @from_path, path
end
end
if (type == "http" or type == "link") and
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
"<img src=\"#{url}\" />"
else
"<a href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
end
end
##
# And we're invoked with a potential external hyperlink mailto:
# just gets inserted. http: links are checked to see if they
# reference an image. If so, that image gets inserted using an
# <img> tag. Otherwise a conventional <a href> is used. We also
# support a special type of hyperlink, link:, which is a reference
# to a local file whose path is relative to the --op directory.
def handle_special_HYPERLINK(special)
url = special.text
gen_url url, url
end
##
# Here's a hypedlink where the label is different to the URL
# <label>[url]
def handle_special_TIDYLINK(special)
text = special.text
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
label = $1
url = $2
gen_url url, label
end
end

View file

@ -1,3 +1,4 @@
require 'rdoc/markup/formatter'
require 'rdoc/markup/fragments' require 'rdoc/markup/fragments'
require 'rdoc/markup/inline' require 'rdoc/markup/inline'
@ -6,7 +7,7 @@ require 'cgi'
## ##
# Convert SimpleMarkup to basic LaTeX report format. # Convert SimpleMarkup to basic LaTeX report format.
class RDoc::Markup::ToLaTeX class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
BS = "\020" # \ BS = "\020" # \
OB = "\021" # { OB = "\021" # {

View file

@ -1,9 +1,10 @@
require 'rdoc/markup' require 'rdoc/markup'
require 'rdoc/markup/formatter'
## ##
# This Markup outputter is used for testing purposes. # This Markup outputter is used for testing purposes.
class RDoc::Markup::ToTest class RDoc::Markup::ToTest < RDoc::Markup::Formatter
def start_accepting def start_accepting
@res = [] @res = []

View file

@ -49,7 +49,7 @@ class RDoc::Options
## ##
# The list of files to be processed # The list of files to be processed
attr_reader :files attr_accessor :files
## ##
# Scan newer sources than the flag file if true. # Scan newer sources than the flag file if true.
@ -74,7 +74,7 @@ class RDoc::Options
## ##
# Should source code be included inline, or displayed in a popup # Should source code be included inline, or displayed in a popup
attr_reader :inline_source attr_accessor :inline_source
## ##
# Name of the file, class or module to display in the initial index page (if # Name of the file, class or module to display in the initial index page (if

View file

@ -53,13 +53,15 @@ module RDoc
end end
end end
private def initialize
@stats = Stats.new
end
## ##
# Report an error message and exit # Report an error message and exit
def error(msg) def error(msg)
raise RDoc::Error, msg raise ::RDoc::Error, msg
end end
## ##
@ -206,8 +208,6 @@ module RDoc
file_info file_info
end end
public
## ##
# Format up one or more files according to the given arguments. # Format up one or more files according to the given arguments.
# #
@ -223,8 +223,6 @@ module RDoc
def document(argv) def document(argv)
TopLevel::reset TopLevel::reset
@stats = Stats.new
options = Options.new GENERATORS options = Options.new GENERATORS
options.parse argv options.parse argv

View file

@ -12,10 +12,10 @@ class TestRDocMarkup < Test::Unit::TestCase
end end
def line_groups(str, expected) def line_groups(str, expected)
p = RDoc::Markup.new m = RDoc::Markup.new
mock = RDoc::Markup::ToTest.new mock = RDoc::Markup::ToTest.new
block = p.convert(str, mock) block = m.convert(str, mock)
if block != expected if block != expected
rows = (0...([expected.size, block.size].max)).collect{|i| rows = (0...([expected.size, block.size].max)).collect{|i|
@ -29,10 +29,10 @@ class TestRDocMarkup < Test::Unit::TestCase
end end
def line_types(str, expected) def line_types(str, expected)
p = RDoc::Markup.new m = RDoc::Markup.new
mock = RDoc::Markup::ToTest.new mock = RDoc::Markup::ToTest.new
p.convert(str, mock) m.convert(str, mock)
assert_equal(expected, p.get_line_types.map{|type| type.to_s[0,1]}.join('')) assert_equal(expected, m.get_line_types.map{|type| type.to_s[0,1]}.join(''))
end end
def test_groups def test_groups
@ -68,8 +68,8 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1", "L1: BULLET ListItem\nl1",
"L1: ListItem\nl2", "L1: BULLET ListItem\nl2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
@ -83,8 +83,8 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1 l1+", "L1: BULLET ListItem\nl1 l1+",
"L1: ListItem\nl2", "L1: BULLET ListItem\nl2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
@ -98,11 +98,11 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1", "L1: BULLET ListItem\nl1",
"L2: ListStart\n", "L2: ListStart\n",
"L2: ListItem\nl1.1", "L2: BULLET ListItem\nl1.1",
"L2: ListEnd\n", "L2: ListEnd\n",
"L1: ListItem\nl2", "L1: BULLET ListItem\nl2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
@ -122,13 +122,13 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1", "L1: BULLET ListItem\nl1",
"L2: ListStart\n", "L2: ListStart\n",
"L2: ListItem\nl1.1 text", "L2: BULLET ListItem\nl1.1 text",
"L2: Verbatim\n code\n code\n", "L2: Verbatim\n code\n code\n",
"L2: Paragraph\ntext", "L2: Paragraph\ntext",
"L2: ListEnd\n", "L2: ListEnd\n",
"L1: ListItem\nl2", "L1: BULLET ListItem\nl2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
@ -143,11 +143,11 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1", "L1: NUMBER ListItem\nl1",
"L2: ListStart\n", "L2: ListStart\n",
"L2: ListItem\nl1.1", "L2: BULLET ListItem\nl1.1",
"L2: ListEnd\n", "L2: ListEnd\n",
"L1: ListItem\nl2", "L1: NUMBER ListItem\nl2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
@ -161,11 +161,11 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1", "L1: LABELED ListItem\ncat: l1",
"L2: ListStart\n", "L2: ListStart\n",
"L2: ListItem\nl1.1", "L2: BULLET ListItem\nl1.1",
"L2: ListEnd\n", "L2: ListEnd\n",
"L1: ListItem\nl2", "L1: LABELED ListItem\ndog: l2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
@ -179,8 +179,8 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1 continuation", "L1: LABELED ListItem\ncat: l1 continuation",
"L1: ListItem\nl2", "L1: LABELED ListItem\ndog: l2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
@ -218,6 +218,133 @@ class TestRDocMarkup < Test::Unit::TestCase
end end
def test_list_alpha
str = "a. alpha\nb. baker\nB. ALPHA\nA. BAKER"
line_groups(str,
[ "L1: ListStart\n",
"L1: LOWERALPHA ListItem\nalpha",
"L1: LOWERALPHA ListItem\nbaker",
"L1: ListEnd\n",
"L1: ListStart\n",
"L1: UPPERALPHA ListItem\nALPHA",
"L1: UPPERALPHA ListItem\nBAKER",
"L1: ListEnd\n" ])
end
def test_list_bullet_dash
str = "- one\n- two\n"
line_groups(str,
[ "L1: ListStart\n",
"L1: BULLET ListItem\none",
"L1: BULLET ListItem\ntwo",
"L1: ListEnd\n" ])
end
def test_list_bullet_star
str = "* one\n* two\n"
line_groups(str,
[ "L1: ListStart\n",
"L1: BULLET ListItem\none",
"L1: BULLET ListItem\ntwo",
"L1: ListEnd\n" ])
end
def test_list_labeled_bracket
str = "[one] item one\n[two] item two"
line_groups(str,
[ "L1: ListStart\n",
"L1: LABELED ListItem\none: item one",
"L1: LABELED ListItem\ntwo: item two",
"L1: ListEnd\n" ])
end
def test_list_labeled_bracket_continued
str = "[one]\n item one\n[two]\n item two"
line_groups(str,
[ "L1: ListStart\n",
"L1: LABELED ListItem\none: item one",
"L1: LABELED ListItem\ntwo: item two",
"L1: ListEnd\n" ])
end
def test_list_labeled_colon
str = "one:: item one\ntwo:: item two"
line_groups(str,
[ "L1: ListStart\n",
"L1: NOTE ListItem\none:: item one",
"L1: NOTE ListItem\ntwo:: item two",
"L1: ListEnd\n" ])
end
def test_list_labeled_colon_continued
str = "one::\n item one\ntwo::\n item two"
line_groups(str,
[ "L1: ListStart\n",
"L1: NOTE ListItem\none:: item one",
"L1: NOTE ListItem\ntwo:: item two",
"L1: ListEnd\n" ])
end
def test_list_nested_bullet_bullet
str = "* one\n* two\n * cat\n * dog"
line_groups(str,
[ "L1: ListStart\n",
"L1: BULLET ListItem\none",
"L1: BULLET ListItem\ntwo",
"L2: ListStart\n",
"L2: BULLET ListItem\ncat",
"L2: BULLET ListItem\ndog",
"L2: ListEnd\n",
"L1: ListEnd\n" ])
end
def test_list_nested_labeled_bullet
str = "[one]\n * cat\n * dog"
line_groups(str,
[ "L1: ListStart\n",
"L1: LABELED ListItem\none: ",
"L2: ListStart\n",
"L2: BULLET ListItem\ncat",
"L2: BULLET ListItem\ndog",
"L2: ListEnd\n",
"L1: ListEnd\n" ])
end
def test_list_nested_labeled_bullet_bullet
str = "[one]\n * cat\n * dog"
line_groups(str,
[ "L1: ListStart\n",
"L1: LABELED ListItem\none: ",
"L2: ListStart\n",
"L2: BULLET ListItem\ncat",
"L3: ListStart\n",
"L3: BULLET ListItem\ndog",
"L3: ListEnd\n",
"L2: ListEnd\n",
"L1: ListEnd\n" ])
end
def test_list_number
str = "1. one\n2. two\n1. three"
line_groups(str,
[ "L1: ListStart\n",
"L1: NUMBER ListItem\none",
"L1: NUMBER ListItem\ntwo",
"L1: NUMBER ListItem\nthree",
"L1: ListEnd\n" ])
end
def test_list_split def test_list_split
str = %{\ str = %{\
now is now is
@ -229,20 +356,30 @@ class TestRDocMarkup < Test::Unit::TestCase
line_groups(str, line_groups(str,
[ "L0: Paragraph\nnow is", [ "L0: Paragraph\nnow is",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl1", "L1: BULLET ListItem\nl1",
"L1: ListEnd\n", "L1: ListEnd\n",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nn1", "L1: NUMBER ListItem\nn1",
"L1: ListItem\nn2", "L1: NUMBER ListItem\nn2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L1: ListStart\n", "L1: ListStart\n",
"L1: ListItem\nl2", "L1: BULLET ListItem\nl2",
"L1: ListEnd\n", "L1: ListEnd\n",
"L0: Paragraph\nthe time" "L0: Paragraph\nthe time"
]) ])
end end
def test_paragraph
str = "paragraph\n\n*bold* paragraph\n"
line_groups str, [
"L0: Paragraph\nparagraph",
"L0: BlankLine\n",
"L0: Paragraph\n*bold* paragraph"
]
end
def test_tabs def test_tabs
str = "hello\n dave" str = "hello\n dave"
assert_equal(str, basic_conv(str)) assert_equal(str, basic_conv(str))
@ -345,6 +482,15 @@ class TestRDocMarkup < Test::Unit::TestCase
line_types(str, 'PLPLP') line_types(str, 'PLPLP')
end end
def test_verbatim
str = "paragraph\n *bold* verbatim\n"
line_groups str, [
"L0: Paragraph\nparagraph",
"L0: Verbatim\n *bold* verbatim\n"
]
end
def test_verbatim_merge def test_verbatim_merge
str = %{\ str = %{\
now is now is

View file

@ -31,9 +31,9 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) | crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
RDoc::Markup::Attribute.bitmap_for(:CROSSREF) RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
[ @am.changed_attribute_by_name([], [:CROSSREF] | [:_SPECIAL_]), [ @am.changed_attribute_by_name([], [:CROSSREF, :_SPECIAL_]),
RDoc::Markup::Special.new(crossref_bitmap, text), RDoc::Markup::Special.new(crossref_bitmap, text),
@am.changed_attribute_by_name([:CROSSREF] | [:_SPECIAL_], []) @am.changed_attribute_by_name([:CROSSREF, :_SPECIAL_], [])
] ]
end end
@ -90,31 +90,46 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
@am.flow("cat _a__nd_ *dog*")) @am.flow("cat _a__nd_ *dog*"))
end end
def test_html_like def test_html_like_em_bold
assert_equal(["cat ", @tt_on, "dog", @tt_off], @am.flow("cat <tt>dog</Tt>")) assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("cat <i>and </i><b>dog</b>")
end
assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off], def test_html_like_em_bold_SGML
@am.flow("cat <i>and</i> <B>dog</b>")) assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("cat <i>and <b></i>dog</b>")
assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off], end
@am.flow("cat <i>and <B>dog</B></I>"))
assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("cat <i>and </i><b>dog</b>"))
assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("cat <i>and <b></i>dog</b>"))
assert_equal([@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("<tt>cat</tt> <i>and <b></i>dog</b>"))
assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
@am.flow("cat <i>and <b>dog</b></i>"))
def test_html_like_em_bold_nested_1
assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"], assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"],
@am.flow("cat <i><b>and</b></i> dog")) @am.flow("cat <i><b>and</b></i> dog"))
end end
def test_html_like_em_bold_nested_2
assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
@am.flow("cat <i>and <b>dog</b></i>")
end
def test_html_like_em_bold_nested_mixed_case
assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
@am.flow("cat <i>and <B>dog</B></I>")
end
def test_html_like_em_bold_mixed_case
assert_equal ["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
@am.flow("cat <i>and</i> <B>dog</b>")
end
def test_html_like_teletype
assert_equal ["cat ", @tt_on, "dog", @tt_off],
@am.flow("cat <tt>dog</Tt>")
end
def test_html_like_teletype_em_bold_SGML
assert_equal [@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
@am.flow("<tt>cat</tt> <i>and <b></i>dog</b>")
end
def test_protect def test_protect
assert_equal(['cat \\ dog'], @am.flow('cat \\ dog')) assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))

View file

@ -250,6 +250,14 @@ class TestRDocRIFormatter < Test::Unit::TestCase
assert_equal " a b c\n d e f\n\n", @output.string assert_equal " a b c\n d e f\n\n", @output.string
end end
def test_display_verbatim_flow_item_bold
verbatim = RDoc::Markup::Flow::VERB.new "*a* b c"
@f.display_verbatim_flow_item verbatim
assert_equal " *a* b c\n\n", @output.string
end
def test_draw_line def test_draw_line
@f.draw_line @f.draw_line

View file

@ -18,6 +18,14 @@ class TestRDocRIOverstrikeFormatter < Test::Unit::TestCase
@af = RDoc::RI::AttributeFormatter @af = RDoc::RI::AttributeFormatter
end end
def test_display_verbatim_flow_item_bold
verbatim = RDoc::Markup::Flow::VERB.new "*a* b c"
@f.display_verbatim_flow_item verbatim
assert_equal " *a* b c\n\n", @output.string
end
def test_write_attribute_text_bold def test_write_attribute_text_bold
line = [RDoc::RI::AttributeFormatter::AttrChar.new('b', @af::BOLD)] line = [RDoc::RI::AttributeFormatter::AttrChar.new('b', @af::BOLD)]