diff options
author | dave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-24 04:24:29 +0000 |
---|---|---|
committer | dave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-24 04:24:29 +0000 |
commit | f0346bd249ae29cdf4d9c2e88b09e63c41ff1ce8 (patch) | |
tree | c945829da8f2e7555a6b4cb7e11601dfafdc4d78 /lib/rdoc | |
parent | 52975bb7a77b3a6409e50609b4baeafade035b3d (diff) |
Forgot to save buffer.... sigh
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/code_objects.rb | 4 | ||||
-rw-r--r-- | lib/rdoc/generators/html_generator.rb | 57 | ||||
-rw-r--r-- | lib/rdoc/generators/ri_generator.rb | 10 | ||||
-rw-r--r-- | lib/rdoc/generators/template/html/css2.rb | 631 | ||||
-rw-r--r-- | lib/rdoc/generators/template/html/html.rb | 1085 | ||||
-rw-r--r-- | lib/rdoc/generators/template/html/old_html.rb | 768 | ||||
-rw-r--r-- | lib/rdoc/markup/simple_markup/inline.rb | 3 | ||||
-rw-r--r-- | lib/rdoc/parsers/parse_c.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/ri/ri_cache.rb | 6 | ||||
-rw-r--r-- | lib/rdoc/ri/ri_formatter.rb | 309 | ||||
-rw-r--r-- | lib/rdoc/ri/ri_options.rb | 55 | ||||
-rw-r--r-- | lib/rdoc/ri/ri_reader.rb | 14 |
12 files changed, 1645 insertions, 1299 deletions
diff --git a/lib/rdoc/code_objects.rb b/lib/rdoc/code_objects.rb index 7fdbbde027..bfacff1321 100644 --- a/lib/rdoc/code_objects.rb +++ b/lib/rdoc/code_objects.rb @@ -527,6 +527,9 @@ module RDoc attr_overridable :params, :param, :parameters, :parameter + attr_accessor :call_seq + + include TokenStream def initialize(text, name) @@ -540,6 +543,7 @@ module RDoc @aliases = [] @is_alias_for = nil @comment = "" + @call_seq = nil end def <=>(other) diff --git a/lib/rdoc/generators/html_generator.rb b/lib/rdoc/generators/html_generator.rb index 89349f4b00..c5a12eee39 100644 --- a/lib/rdoc/generators/html_generator.rb +++ b/lib/rdoc/generators/html_generator.rb @@ -394,16 +394,21 @@ module Generators def build_method_detail_list outer = [] + methods = @methods.sort for singleton in [true, false] for vis in [ :public, :protected, :private ] res = [] - @methods.each do |m| + methods.each do |m| if m.document_self and m.visibility == vis and m.singleton == singleton row = {} - row["name"] = CGI.escapeHTML(m.name) + if m.call_seq + row["callseq"] = m.call_seq + else + row["name"] = CGI.escapeHTML(m.name) + row["params"] = m.params + end desc = m.description.strip row["m_desc"] = desc unless desc.empty? - row["params"] = m.params row["aref"] = m.aref row["visibility"] = m.visibility.to_s @@ -878,20 +883,33 @@ module Generators @context.singleton end + def call_seq + cs = @context.call_seq + if cs + cs.gsub(/\n/, "<br />\n") + else + nil + end + end + def params - p = @context.params.gsub(/\s*\#.*/, '') - p = p.tr("\n", " ").squeeze(" ") - p = "(" + p + ")" unless p[0] == ?( - - if (block = @context.block_params) - block.gsub!(/\s*\#.*/, '') - block = block.tr("\n", " ").squeeze(" ") - if block[0] == ?( - block.sub!(/^\(/, '').sub!(/\)/, '') + # 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(" ") + p = "(" + p + ")" unless p[0] == ?( + + if (block = @context.block_params) + block.gsub!(/\s*\#.*/, '') + block = block.tr("\n", " ").squeeze(" ") + if block[0] == ?( + block.sub!(/^\(/, '').sub!(/\)/, '') + end + p << " {|#{block.strip}| ...}" end - p << " {|#{block.strip}| ...}" end - CGI.escapeHTML(p) end @@ -948,16 +966,7 @@ module Generators end text = CGI.escapeHTML(t.text) -# case t -# when RubyToken::TkKW -# style = "kw" -# when RubyToken::TkCOMMENT -# style = "cmt" -# when RubyToken::TkSTRING -# style = "str" -# when RubyToken::TkREGEXP -# style = "re" -# end + if style src << "<span class=\"#{style}\">#{text}</span>" else diff --git a/lib/rdoc/generators/ri_generator.rb b/lib/rdoc/generators/ri_generator.rb index 22467e4ba9..705ad7da06 100644 --- a/lib/rdoc/generators/ri_generator.rb +++ b/lib/rdoc/generators/ri_generator.rb @@ -189,11 +189,11 @@ module Generators end def params_of(method) - params = method.params || "" - - if params =~ /^!verb!(.*)/m - p = $1 + if method.call_seq + method.call_seq else + params = method.params || "" + p = params.gsub(/\s*\#.*/, '') p = p.tr("\n", " ").squeeze(" ") p = "(" + p + ")" unless p[0] == ?( @@ -206,8 +206,8 @@ module Generators end p << " {|#{block.strip}| ...}" end + p end - p end def markup(comment) diff --git a/lib/rdoc/generators/template/html/css2.rb b/lib/rdoc/generators/template/html/css2.rb deleted file mode 100644 index 0109ae3e7f..0000000000 --- a/lib/rdoc/generators/template/html/css2.rb +++ /dev/null @@ -1,631 +0,0 @@ -# -# = CSS2 RDoc HTML template -# -# This is a template for RDoc that uses XHTML 1.0 Transitional and dictates a -# bit more of the appearance of the output to cascading stylesheets than the -# default. It was designed for clean inline code display, and uses DHTMl to -# toggle the visbility of each method's source with each click on the '[source]' -# link. -# -# == Authors -# -# * Michael Granger <ged@FaerieMUD.org> -# -# Copyright (c) 2002, 2003 The FaerieMUD Consortium. Some rights reserved. -# -# This work is licensed under the Creative Commons Attribution License. To view -# a copy of this license, visit http://creativecommons.org/licenses/by/1.0/ or -# send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California -# 94305, USA. -# - -module RDoc - module Page - - FONTS = "Verdana,Arial,Helvetica,sans-serif" - -STYLE = %{ -body { - margin: 0; - padding: 0; -} - -h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; } -h1 { font-size: 120%; } -h2,h3,h4 { margin-top: 1em; } - -a { background: #eef; color: #039; text-decoration: none; } -a:hover { background: #039; color: #eef; } - -/* Override the base stylesheet's Anchor inside a table cell */ -td > a { - background: transparent; - color: #039; - text-decoration: none; -} - -/* === Structural elements =================================== */ - -div#index { - margin: 0; - padding: 0; - font-size: 0.9em; -} - -div#index a { - margin-left: 0.7em; -} - -div#classHeader { - width: auto; - background: #039; - color: white; - padding: 0.5em 1.5em 0.5em 1.5em; - margin: 0; - border-bottom: 3px solid #006; -} - -div#classHeader a { - background: inherit; - color: white; -} - -div#classHeader td { - background: inherit; - color: white; -} - -div#fileHeader { - width: auto; - background: #039; - color: white; - padding: 0.5em 1.5em 0.5em 1.5em; - margin: 0; - border-bottom: 3px solid #006; -} - -div#fileHeader a { - background: inherit; - color: white; -} - -div#fileHeader td { - background: inherit; - color: white; -} - -div#bodyContent { - padding: 0 1.5em 0 1.5em; -} - -div#description { - padding: 0.5em 1.5em; - background: #efefef; - border: 1px dotted #999; -} - -div#description h1,h2,h3,h4,h5,h6 { - color: black; - background: transparent; -} - -div#validator-badges { - text-align: center; -} -div#validator-badges img { border: 0; } - -div#copyright { - color: #333; - background: #efefef; - font: 0.75em sans-serif; - margin-top: 5em; - margin-bottom: 0; - padding: 0.5em 2em; -} - - -/* === Classes =================================== */ - -table.header-table { - color: white; - font-size: small; -} - -.type-note { - font-size: small; - color: #DEDEDE; -} - -.section-bar { - background: #eee; - color: #333; - padding: 3px; - border: 1px solid #999; -} - -.top-aligned-row { vertical-align: vertical-align: top } - -/* --- Context section classes ----------------------- */ - -.context-row { } -.context-item-name { font-family: monospace; font-weight: bold; color: black; } -.context-item-value { font-size: x-small; color: #448; } -.context-item-desc { background: #efefef; } - -/* --- Method classes -------------------------- */ -.method-detail { - background: #EFEFEF; - padding: 0; - margin-top: 0.5em; - margin-bottom: 0.5em; - border: 1px dotted #DDD; -} -.method-heading { - color: black; - background: #AAA; - border-bottom: 1px solid #666; - padding: 0.2em 0.5em 0 0.5em; -} -.method-signature { color: black; background: inherit; } -.method-name { font-weight: bold; } -.method-args { font-style: italic; } -.method-description { padding: 0 0.5em 0 0.5em; } - -/* --- Source code sections -------------------- */ - -a.source-toggle { font-size: 90%; } -div.method-source-code { - background: #262626; - color: #ffdead; - margin: 1em; - padding: 0.5em; - border: 1px dashed #999; - overflow: hidden; -} - -div.method-source-code pre { color: #ffdead; overflow: hidden; } - -/* --- Ruby keyword styles --------------------- */ -/* (requires a hacked html_generator.rb to add more class-types) */ -.ruby-constant { color: #7fffd4; background: transparent; } -.ruby-keyword { color: #00ffff; background: transparent; } -.ruby-ivar { color: #eedd82; background: transparent; } -.ruby-operator { color: #00ffee; background: transparent; } -.ruby-identifier { color: #ffdead; background: transparent; } -.ruby-node { color: #ffa07a; background: transparent; } -.ruby-comment { color: #b22222; font-weight: bold; background: transparent; } -.ruby-regexp { color: #ffa07a; background: transparent; } -.ruby-value { color: #7fffd4; background: transparent; } -} - - -##################################################################### -### H E A D E R T E M P L A T E -##################################################################### - -XHTML_PREAMBLE = %{<?xml version="1.0" encoding="%charset%"?> -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "DTD/xhtml1-transitional.dtd"> -} - -HEADER = XHTML_PREAMBLE + %{ -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> - <title>%title%</title> - <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> - <meta http-equiv="Content-Script-Type" content="text/javascript" /> - <link rel="stylesheet" href="%style_url%" type="text/css" media="screen" /> - <script type="text/javascript"> - // <![CDATA[ - - function popupCode( url ) { - window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") - } - - function toggleCode( id ) { - if ( document.getElementById ) - elem = document.getElementById( id ); - else if ( document.all ) - elem = eval( "document.all." + id ); - else - return false; - - elemStyle = elem.style; - - if ( elemStyle.display != "block" ) { - elemStyle.display = "block" - } else { - elemStyle.display = "none" - } - - return true; - } - - // Make codeblocks hidden by default - document.writeln( "<style type=\\"text/css\\">div.method-source-code { display: none }</style>" ) - - // ]]> - </script> - -</head> -<body> -} - - -##################################################################### -### C O N T E X T C O N T E N T T E M P L A T E -##################################################################### - -CONTEXT_CONTENT = %{ - <div id="contextContent"> -IF:diagram - <div id="diagram"> - %diagram% - </div> -ENDIF:diagram - -IF:description - <div id="description"> - %description% - </div> -ENDIF:description - -IF:requires - <div id="requires-list"> - <h2 class="section-bar">Required files</h2> - - <div class="name-list"> -START:requires - HREF:aref:name: -END:requires - </div> - </div> -ENDIF:requires - -IF:methods - <div id="method-list"> - <h2 class="section-bar">Methods</h2> - - <div class="name-list"> -START:methods - HREF:aref:name: -END:methods - </div> - </div> -ENDIF:methods - -IF:constants - <div id="constants-list"> - <h2 class="section-bar">Constants</h2> - - <div class="name-list"> - <table summary="Constants"> -START:constants - <tr class="top-aligned-row context-row"> - <td class="context-item-name">%name%</td> - <td>=</td> - <td class="context-item-value">%value%</td> - </tr> -IF:desc - <tr class="top-aligned-row context-row"> - <td> </td> - <td colspan="2" class="context-item-desc">%desc%</td> - </tr> -ENDIF:desc -END:constants - </table> - </div> - </div> -ENDIF:constants - -IF:aliases - <div id="aliases-list"> - <h2 class="section-bar">External Aliases</h2> - - <div class="name-list"> -START:aliases - %old_name% -> %new_name% <br /> -END:aliases - </div> - </div> -ENDIF:aliases - - -IF:attributes - <div id="attribute-list"> - <h2 class="section-bar">Attributes</h2> - - <div class="name-list"> - <table> -START:attributes - <tr class="top-aligned-row context-row"> - <td class="context-item-name">%name%</td> - <td class="context-item-value"> [%rw%] </td> - <td class="context-item-desc">%a_desc%</td> - </tr> -END:attributes - </table> - </div> - </div> -ENDIF:attributes - -IF:classlist - <div id="class-list"> - <h2 class="section-bar">Classes and Modules</h2> - - %classlist% - </div> -ENDIF:classlist - - </div> - -} - - -##################################################################### -### F O O T E R T E M P L A T E -##################################################################### -FOOTER = %{ -<div id="validator-badges"> - <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> -</div> - -</body> -</html> -} - - -##################################################################### -### F I L E P A G E H E A D E R T E M P L A T E -##################################################################### - -FILE_PAGE = %{ - <div id="fileHeader"> - <h1>%short_name%</h1> - <table class="header-table"> - <tr class="top-aligned-row"> - <td><strong>Path:</strong></td> - <td>%full_path% -IF:cvsurl - (<a href="%cvsurl%">CVS</a>) -ENDIF:cvsurl - </td> - </tr> - <tr class="top-aligned-row"> - <td><strong>Last Update:</strong></td> - <td>%dtm_modified%</td> - </tr> - </table> - </div> -} - - -##################################################################### -### C L A S S P A G E H E A D E R T E M P L A T E -##################################################################### - -CLASS_PAGE = %{ - <div id="classHeader"> - <h1>%full_name% <sup class="type-note">(%classmod%)</sup></h1> - <table class="header-table"> - <tr class="top-aligned-row"> - <td><strong>In:</strong></td> - <td> -START:infiles -IF:full_path_url - <a href="%full_path_url%"> -ENDIF:full_path_url - %full_path% -IF:full_path_url - </a> -ENDIF:full_path_url -IF:cvsurl - (<a href="%cvsurl%">CVS</a>) -ENDIF:cvsurl - <br /> -END:infiles - </td> - </tr> - -IF:parent - <tr class="top-aligned-row"> - <td><strong>Parent:</strong></td> - <td> -IF:par_url - <a href="%par_url%"> -ENDIF:par_url - %parent% -IF:par_url - </a> -ENDIF:par_url - </td> - </tr> -ENDIF:parent - </table> - </div> -} - - -##################################################################### -### M E T H O D L I S T T E M P L A T E -##################################################################### - -METHOD_LIST = %{ - - <!-- if includes --> -IF:includes - <div id="includes"> - <h2 class="section-bar">Included Modules</h2> - - <div id="includes-list"> -START:includes - <span class="include-name">HREF:aref:name:</span> -END:includes - </div> - </div> -ENDIF:includes - - - <!-- if method_list --> -IF:method_list - <div id="methods"> -START:method_list -IF:methods - <h2 class="section-bar">%type% %category% methods</h2> - -START:methods - <!-- %name%%params% --> - <div id="method-%aref%" class="method-detail"> - <a name="%aref%"></a> - - <div class="method-heading"> -IF:codeurl - <a href="%codeurl%" target="Code" class="method-signature" - onclick="popupCode('%codeurl%');return false;"> -ENDIF:codeurl -IF:sourcecode - <a href="#%aref%" class="method-signature"> -ENDIF:sourcecode - <span class="method-name">%name%</span><span class="method-args">%params%</span> -IF:codeurl - </a> -ENDIF:codeurl -IF:sourcecode - </a> -ENDIF:sourcecode - </div> - - <div class="method-description"> -IF:m_desc - %m_desc% -ENDIF:m_desc -IF:sourcecode - <p><a class="source-toggle" href="#" - onclick="toggleCode('%aref%-source');return false;">[Source]</a></p> - <div class="method-source-code" id="%aref%-source"> -<pre> -%sourcecode% -</pre> - </div> -ENDIF:sourcecode - </div> - </div> - -END:methods -ENDIF:methods -END:method_list - - </div> -ENDIF:method_list -} - - -##################################################################### -### B O D Y T E M P L A T E -##################################################################### - -BODY = HEADER + %{ - -!INCLUDE! <!-- banner header --> - - <div id="bodyContent"> - -} + CONTEXT_CONTENT + METHOD_LIST + %{ - - </div> - -} + FOOTER - - - -##################################################################### -### S O U R C E C O D E T E M P L A T E -##################################################################### - -SRC_PAGE = XHTML_PREAMBLE + %{ -<!-- - - %title% - - --> -<html> -<head> - <title>%title%</title> - <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> - <link rel="stylesheet" href="http://www.FaerieMUD.org/stylesheets/rdoc.css" type="text/css" /> -</head> -<body> - <pre>%code%</pre> -</body> -</html> -} - - -##################################################################### -### I N D E X F I L E T E M P L A T E S -##################################################################### - -FR_INDEX_BODY = %{ -!INCLUDE! -} - -FILE_INDEX = XHTML_PREAMBLE + %{ -<!-- - - %list_title% - - --> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> - <title>%list_title%</title> - <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> - <link rel="stylesheet" href="%style_url%" type="text/css" /> - <base target="docwin" /> -</head> -<body> -<div id="index"> - <h1 class="section-bar">%list_title%</h1> - <div id="index-entries"> -START:entries - <a href="%href%">%name%</a><br /> -END:entries - </div> -</div> -</body> -</html> -} - -CLASS_INDEX = FILE_INDEX -METHOD_INDEX = FILE_INDEX - -INDEX = %{<?xml version="1.0" encoding="%charset%"?> -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" - "DTD/xhtml1-frameset.dtd"> - -<!-- - - %title% - - --> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> - <title>%title%</title> - <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> -</head> -<frameset rows="20%, 80%"> - <frameset cols="25%,35%,45%"> - <frame src="fr_file_index.html" title="Files" name="Files" /> - <frame src="fr_class_index.html" name="Classes" /> - <frame src="fr_method_index.html" name="Methods" /> - </frameset> - <frame src="%initial_page%" name="docwin" /> -</frameset> -</html> -} - - - end # module Page -end # class RDoc - diff --git a/lib/rdoc/generators/template/html/html.rb b/lib/rdoc/generators/template/html/html.rb index 18ad9dcb3b..8ac631490c 100644 --- a/lib/rdoc/generators/template/html/html.rb +++ b/lib/rdoc/generators/template/html/html.rb @@ -1,762 +1,635 @@ -module RDoc - -# This is how you define the HTML that RDoc generates. Simply create -# a file in rdoc/generators/html_templates that creates the -# module RDoc::Page and populate it as described below. Then invoke -# rdoc using the --template <name of your file> option, and -# your template will be used. -# -# The constants defining pages use a simple templating system: -# -# * The templating system is passed a hash. Keys in the hash correspond -# to tags on this page. The tag %abc% is looked up in the hash, -# and is replaced by the corresponding hash value. -# -# * Some tags are optional. You can detect this using IF/ENDIF -# -# IF: title -# The value of title is %title% -# ENDIF: title -# -# * Some entries in the hash have values that are arrays, where each -# entry in the array is itself a hash. These are used to generate -# lists using the START: construct. For example, given a hash -# containing -# -# { 'people' => [ { 'name' => 'Fred', 'age' => '12' }, -# { 'name' => 'Mary', 'age' => '21' } ] -# -# You could generate a simple table using -# -# <table> -# START:people -# <tr><td>%name%<td>%age%</tr> -# END:people -# </table> -# -# These lists can be nested to an arbitrary depth -# -# * the construct HREF:url:name: generates <a href="%url%">%name%</a> -# if +url+ is defined in the hash, or %name% otherwise. -# -# -# Your file must contain the following constants -# -# [*FONTS*] a list of fonts to be used -# [*STYLE*] a CSS section (without the <style> or comments). This is -# used to generate a style.css file -# -# [*BODY*] -# The main body of all non-index RDoc pages. BODY will contain -# two !INCLUDE!s. The first is used to include a document-type -# specific header (FILE_PAGE or CLASS_PAGE). The second include -# is for the method list (METHOD_LIST). THe body is passed: -# -# %title%:: -# the page's title -# -# %style_url%:: -# the url of a style sheet for this page -# -# %diagram%:: -# the optional URL of a diagram for this page -# -# %description%:: -# a (potentially multi-paragraph) string containing the -# description for th file/class/module. -# -# %requires%:: -# an optional list of %aref%/%name% pairs, one for each module -# required by this file. -# -# %methods%:: -# an optional list of %aref%/%name%, one for each method -# documented on this page. This is intended to be an index. -# -# %attributes%:: -# An optional list. For each attribute it contains: -# %name%:: the attribute name -# %rw%:: r/o, w/o, or r/w -# %a_desc%:: description of the attribute -# -# %classlist%:: -# An optional string containing an already-formatted list of -# classes and modules documented in this file -# -# For FILE_PAGE entries, the body will be passed -# -# %short_name%:: -# The name of the file -# -# %full_path%:: -# The full path to the file -# -# %dtm_modified%:: -# The date/time the file was last changed -# -# For class and module pages, the body will be passed -# -# %classmod%:: -# The name of the class or module -# -# %files%:: -# A list. For each file this class is defined in, it contains: -# %full_path_url%:: an (optional) URL of the RDoc page -# for this file -# %full_path%:: the name of the file # -# %par_url%:: -# The (optional) URL of the RDoc page documenting this class's -# parent class +# = CSS2 RDoc HTML template # -# %parent%:: -# The name of this class's parent. +# This is a template for RDoc that uses XHTML 1.0 Transitional and dictates a +# bit more of the appearance of the output to cascading stylesheets than the +# default. It was designed for clean inline code display, and uses DHTMl to +# toggle the visbility of each method's source with each click on the '[source]' +# link. # -# For both files and classes, the body is passed the following information -# on includes and methods: +# == Authors # -# %includes%:: -# Optional list of included modules. For each, it receives -# %aref%:: optional URL to RDoc page for the module -# %name%:: the name of the module +# * Michael Granger <ged@FaerieMUD.org> # -# %method_list%:: -# Optional list of methods of a particular class and category. +# Copyright (c) 2002, 2003 The FaerieMUD Consortium. Some rights reserved. # -# Each method list entry contains: +# This work is licensed under the Creative Commons Attribution License. To view +# a copy of this license, visit http://creativecommons.org/licenses/by/1.0/ or +# send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California +# 94305, USA. # -# %type%:: public/private/protected -# %category%:: instance/class -# %methods%:: a list of method descriptions -# -# Each method description contains: -# -# %aref%:: a target aref, used when referencing this method -# description. You should code this as <a name="%aref%"> -# %codeurl%:: the optional URL to the page containing this method's -# source code. -# %name%:: the method's name -# %params%:: the method's parameters -# %m_desc%:: the (potentially multi-paragraph) description of -# this method. -# -# [*CLASS_PAGE*] -# Header for pages documenting classes and modules. See -# BODY above for the available parameters. -# -# [*FILE_PAGE*] -# Header for pages documenting files. See -# BODY above for the available parameters. -# -# [*METHOD_LIST*] -# Controls the display of the listing of methods. See BODY for -# parameters. -# -# [*INDEX*] -# The top-level index page. For a browser-like environment -# define a frame set that includes the file, class, and -# method indices. Passed -# %title%:: title of page -# %initial_page% :: url of initial page to display -# -# [*CLASS_INDEX*] -# Individual files for the three indexes. Passed: -# %index_url%:: URL of main index page -# %entries%:: List of -# %name%:: name of an index entry -# %href%:: url of corresponding page -# [*METHOD_INDEX*] -# Same as CLASS_INDEX for methods -# -# [*FILE_INDEX*] -# Same as CLASS_INDEX for methods -# -# [*FR_INDEX_BODY*] -# A wrapper around CLASS_INDEX, METHOD_INDEX, and FILE_INDEX. -# If those index strings contain the complete HTML for the -# output, then FR_INDEX_BODY can simply be !INCLUDE! -# -# [*SRC_PAGE*] -# Page used to display source code. Passed %title% and %code%, -# the latter being a multi-line string of code. -module Page +module RDoc + module Page -FONTS = "Verdana, Arial, Helvetica, sans-serif" + FONTS = "Verdana,Arial,Helvetica,sans-serif" STYLE = %{ -body,td,p { font-family: %fonts%; - color: #000040; +body { + margin: 0; + padding: 0; +} + +h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; } +h1 { font-size: 120%; } +h2,h3,h4 { margin-top: 1em; } + +a { background: #eef; color: #039; text-decoration: none; } +a:hover { background: #039; color: #eef; } + +/* Override the base stylesheet's Anchor inside a table cell */ +td > a { + background: transparent; + color: #039; + text-decoration: none; } -.attr-rw { font-size: x-small; color: #444488 } +/* === Structural elements =================================== */ -.title-row { background: #0000aa; - color: #eeeeff; +div#index { + margin: 0; + padding: 0; + font-size: 0.9em; } -.big-title-font { color: white; - font-family: %fonts%; - font-size: large; - height: 50px} +div#index a { + margin-left: 0.7em; +} -.small-title-font { color: aqua; - font-family: %fonts%; - font-size: xx-small; } +div#classHeader { + width: auto; + background: #039; + color: white; + padding: 0.5em 1.5em 0.5em 1.5em; + margin: 0; + border-bottom: 3px solid #006; +} -.aqua { color: aqua } +div#classHeader a { + background: inherit; + color: white; +} -.method-name, attr-name { - font-family: monospace; font-weight: bold; +div#classHeader td { + background: inherit; + color: white; } -.tablesubtitle, .tablesubsubtitle { - width: 100%; - margin-top: 1ex; - margin-bottom: .5ex; - padding: 5px 0px 5px 20px; - font-size: large; - color: aqua; - background: #3333cc; +div#fileHeader { + width: auto; + background: #039; + color: white; + padding: 0.5em 1.5em 0.5em 1.5em; + margin: 0; + border-bottom: 3px solid #006; } -.name-list { - font-family: monospace; - margin-left: 40px; - margin-bottom: 2ex; - line-height: 140%; +div#fileHeader a { + background: inherit; + color: white; } -.description { - margin-left: 40px; - margin-top: -2ex; - margin-bottom: 2ex; +div#fileHeader td { + background: inherit; + color: white; } -.description p { - line-height: 140%; +div#bodyContent { + padding: 0 1.5em 0 1.5em; } -.aka { - margin-left: 40px; - margin-bottom: 2ex; - line-height: 100%; - font-size: small; - color: #808080; +div#description { + padding: 0.5em 1.5em; + background: #efefef; + border: 1px dotted #999; } -.methodtitle { - font-size: medium; - text-decoration: none; - color: #0000AA; - background: white; +div#description h1,h2,h3,h4,h5,h6 { + color: black; + background: transparent; } -.paramsig { - font-size: small; +div#validator-badges { + text-align: center; +} +div#validator-badges img { border: 0; } + +div#copyright { + color: #333; + background: #efefef; + font: 0.75em sans-serif; + margin-top: 5em; + margin-bottom: 0; + padding: 0.5em 2em; } -.srcbut { float: right } -pre { font-size: 1.2em; } -tt { font-size: 1.2em; } +/* === Classes =================================== */ -pre.source { - border-style: groove; - background-color: #ddddff; - margin-left: 40px; - padding: 1em 0em 1em 2em; +table.header-table { + color: white; + font-size: small; } -.classlist { - margin-left: 40px; - margin-bottom: 2ex; - line-height: 140%; +.type-note { + font-size: small; + color: #DEDEDE; } -li { - display: list-item; - margin-top: .6em; +.section-bar { + background: #eee; + color: #333; + padding: 3px; + border: 1px solid #999; } -.ruby-comment { color: green; font-style: italic } -.ruby-constant { color: #4433aa; font-weight: bold; } -.ruby-identifier { color: #222222; } -.ruby-ivar { color: #2233dd; } -.ruby-keyword { color: #3333FF; font-weight: bold } -.ruby-node { color: #777777; } -.ruby-operator { color: #111111; } -.ruby-regexp { color: #662222; } -.ruby-value { color: #662222; font-style: italic } +.top-aligned-row { vertical-align: vertical-align: top } +/* --- Context section classes ----------------------- */ + +.context-row { } +.context-item-name { font-family: monospace; font-weight: bold; color: black; } +.context-item-value { font-size: x-small; color: #448; } +.context-item-desc { background: #efefef; } + +/* --- Method classes -------------------------- */ +.method-detail { + background: #EFEFEF; + padding: 0; + margin-top: 0.5em; + margin-bottom: 0.5em; + border: 1px dotted #DDD; +} +.method-heading { + color: black; + background: #AAA; + border-bottom: 1px solid #666; + padding: 0.2em 0.5em 0 0.5em; +} +.method-signature { color: black; background: inherit; } +.method-name { font-weight: bold; } +.method-args { font-style: italic; } +.method-description { padding: 0 0.5em 0 0.5em; } + +/* --- Source code sections -------------------- */ + +a.source-toggle { font-size: 90%; } +div.method-source-code { + background: #262626; + color: #ffdead; + margin: 1em; + padding: 0.5em; + border: 1px dashed #999; + overflow: hidden; +} + +div.method-source-code pre { color: #ffdead; overflow: hidden; } + +/* --- Ruby keyword styles --------------------- */ +/* (requires a hacked html_generator.rb to add more class-types) */ +.ruby-constant { color: #7fffd4; background: transparent; } +.ruby-keyword { color: #00ffff; background: transparent; } +.ruby-ivar { color: #eedd82; background: transparent; } +.ruby-operator { color: #00ffee; background: transparent; } +.ruby-identifier { color: #ffdead; background: transparent; } +.ruby-node { color: #ffa07a; background: transparent; } +.ruby-comment { color: #b22222; font-weight: bold; background: transparent; } +.ruby-regexp { color: #ffa07a; background: transparent; } +.ruby-value { color: #7fffd4; background: transparent; } } -############################################################################ +##################################################################### +### H E A D E R T E M P L A T E +##################################################################### +XHTML_PREAMBLE = %{<?xml version="1.0" encoding="%charset%"?> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "DTD/xhtml1-transitional.dtd"> +} -HEADER = %{ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" -"DTD/xhtml1-strict.dtd"> +HEADER = XHTML_PREAMBLE + %{ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> - <title>%title%</title> - <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> - <link rel=StyleSheet href="%style_url%" type="text/css" media="screen" /> - <script type="text/javascript" language="JavaScript"> - <!-- - function popCode(url) { - window.open(url, "Code", - "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") - } - //--> - </script> + <title>%title%</title> + <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> + <meta http-equiv="Content-Script-Type" content="text/javascript" /> + <link rel="stylesheet" href="%style_url%" type="text/css" media="screen" /> + <script type="text/javascript"> + // <![CDATA[ + + function popupCode( url ) { + window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") + } + + function toggleCode( id ) { + if ( document.getElementById ) + elem = document.getElementById( id ); + else if ( document.all ) + elem = eval( "document.all." + id ); + else + return false; + + elemStyle = elem.style; + + if ( elemStyle.display != "block" ) { + elemStyle.display = "block" + } else { + elemStyle.display = "none" + } + + return true; + } + + // Make codeblocks hidden by default + document.writeln( "<style type=\\"text/css\\">div.method-source-code { display: none }</style>" ) + + // ]]> + </script> + </head> +<body> } -################################################################### - -METHOD_LIST = %{ -IF:includes -<table summary="Included modules" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">Included modules</td></tr> -</table> -<div class="name-list"> -START:includes - <span class="method-name">HREF:aref:name:</span> -END:includes -</div> -ENDIF:includes - -IF:method_list -START:method_list -IF:methods -<table summary="Method list" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">%type% %category% methods</td></tr> -</table> -START:methods -<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> -<tr><td class="methodtitle"> -<a name="%aref%"></a> -IF:codeurl -<a href="%codeurl%" target="Code" class="methodtitle" - onClick="popCode('%codeurl%');return false;"> -ENDIF:codeurl -<b>%name%</b>%params% -IF:codeurl -</a> -ENDIF:codeurl -</td></tr> -</table> -IF:m_desc -<div class="description"> -%m_desc% -</div> -ENDIF:m_desc -IF:aka -<div class="aka"> -This method is also aliased as -START:aka -<a href="%aref%">%name%</a> -END:aka -</div> -ENDIF:aka -IF:sourcecode -<pre class="source"> -%sourcecode% -</pre> -ENDIF:sourcecode -END:methods -ENDIF:methods -END:method_list -ENDIF:method_list -} - -################################################################### +##################################################################### +### C O N T E X T C O N T E N T T E M P L A T E +##################################################################### CONTEXT_CONTENT = %{ + <div id="contextContent"> IF:diagram -<table summary="Diagram of classes and modules" width="100%"> -<tr><td align="center"> -%diagram% -</td></tr></table> + <div id="diagram"> + %diagram% + </div> ENDIF:diagram - IF:description -<div class="description">%description%</div> + <div id="description"> + %description% + </div> ENDIF:description IF:requires -<table summary="Requires" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">Required files</td></tr> -</table> -<div class="name-list"> + <div id="requires-list"> + <h2 class="section-bar">Required files</h2> + + <div class="name-list"> START:requires -HREF:aref:name: + HREF:aref:name: END:requires -</div> + </div> + </div> ENDIF:requires IF:methods -<table summary="Methods" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">Methods</td></tr> -</table> -<div class="name-list"> + <div id="method-list"> + <h2 class="section-bar">Methods</h2> + + <div class="name-list"> START:methods -HREF:aref:name: + HREF:aref:name: END:methods -</div> + </div> + </div> ENDIF:methods IF:constants -<table summary="Constants" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">Constants</td></tr> -</table> -<table cellpadding="5"> + <div id="constants-list"> + <h2 class="section-bar">Constants</h2> + + <div class="name-list"> + <table summary="Constants"> START:constants -<tr valign="top"><td>%name%</td><td>=</td><td>%value%</td></tr> + <tr class="top-aligned-row context-row"> + <td class="context-item-name">%name%</td> + <td>=</td> + <td class="context-item-value">%value%</td> + </tr> IF:desc -<tr><td></td><td></td><td>%desc%</td></tr> + <tr class="top-aligned-row context-row"> + <td> </td> + <td colspan="2" class="context-item-desc">%desc%</td> + </tr> ENDIF:desc END:constants -</table> + </table> + </div> + </div> ENDIF:constants IF:aliases -<table summary="Aliases" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">External Aliases</td></tr> -</table> -<div class="name-list"> + <div id="aliases-list"> + <h2 class="section-bar">External Aliases</h2> + + <div class="name-list"> START:aliases -%old_name% -> %new_name%<br /> + %old_name% -> %new_name% <br /> END:aliases -</div> + </div> + </div> ENDIF:aliases + IF:attributes -<table summary="Attributes" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">Attributes</td></tr> -</table> -<table summary="Attribute details" cellspacing="5"> + <div id="attribute-list"> + <h2 class="section-bar">Attributes</h2> + + <div class="name-list"> + <table> START:attributes - <tr valign="top"> - <td class="attr-name">%name%</td> -IF:rw - <td align="center" class="attr-rw"> [%rw%] </td> -ENDIF:rw -IFNOT:rw - <td></td> -ENDIF:rw - <td>%a_desc%</td> - </tr> + <tr class="top-aligned-row context-row"> + <td class="context-item-name">%name%</td> + <td class="context-item-value"> [%rw%] </td> + <td class="context-item-desc">%a_desc%</td> + </tr> END:attributes -</table> + </table> + </div> + </div> ENDIF:attributes - + IF:classlist -<table summary="List of classes" cellpadding="5" width="100%"> -<tr><td class="tablesubtitle">Classes and Modules</td></tr> -</table> -<div class="classlist"> -%classlist% -</div> + <div id="class-list"> + <h2 class="section-bar">Classes and Modules</h2> + + %classlist% + </div> ENDIF:classlist + + </div> + } -############################################################################### -BODY = HEADER + %{ -<body bgcolor="white"> -!INCLUDE! <!-- banner header --> -} + -CONTEXT_CONTENT + METHOD_LIST + -%{ +##################################################################### +### F O O T E R T E M P L A T E +##################################################################### +FOOTER = %{ +<div id="validator-badges"> + <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> +</div> + </body> </html> } -############################################################################### +##################################################################### +### F I L E P A G E H E A D E R T E M P L A T E +##################################################################### -FILE_PAGE = <<_FILE_PAGE_ -<table summary="Information on file" width="100%"> - <tr class="title-row"> - <td><table summary="layout" width="100%"><tr> - <td class="big-title-font" colspan="2">%short_name%</td> - <td align="right"><table summary="layout" cellspacing="0" cellpadding="2"> - <tr> - <td class="small-title-font">Path:</td> - <td class="small-title-font">%full_path% +FILE_PAGE = %{ + <div id="fileHeader"> + <h1>%short_name%</h1> + <table class="header-table"> + <tr class="top-aligned-row"> + <td><strong>Path:</strong></td> + <td>%full_path% IF:cvsurl (<a href="%cvsurl%">CVS</a>) ENDIF:cvsurl - </td> - </tr> - <tr> - <td class="small-title-font">Modified:</td> - <td class="small-title-font">%dtm_modified%</td> - </tr> - </table> - </td></tr></table></td> - </tr> -</table> -_FILE_PAGE_ + </td> + </tr> + <tr class="top-aligned-row"> + <td><strong>Last Update:</strong></td> + <td>%dtm_modified%</td> + </tr> + </table> + </div> +} -################################################################### + +##################################################################### +### C L A S S P A G E H E A D E R T E M P L A T E +##################################################################### CLASS_PAGE = %{ -<table summary="Information on class" width="100%" border="0" cellspacing="0"> - <tr class="title-row"> - <td class="big-title-font"> - <sup><font color="aqua">%classmod%</font></sup> %full_name% - </td> - <td align="right"> - <table summary="layout" cellspacing="0" cellpadding="2"> - <tr valign="top"> - <td class="small-title-font">In:</td> - <td class="small-title-font"> + <div id="classHeader"> + <h1>%full_name% <sup class="type-note">(%classmod%)</sup></h1> + <table class="header-table"> + <tr class="top-aligned-row"> + <td><strong>In:</strong></td> + <td> START:infiles IF:full_path_url - <a href="%full_path_url%" class="aqua"> + <a href="%full_path_url%"> ENDIF:full_path_url -%full_path% + %full_path% IF:full_path_url - </a> + </a> ENDIF:full_path_url IF:cvsurl - (<a href="%cvsurl%">CVS</a>) + (<a href="%cvsurl%">CVS</a>) ENDIF:cvsurl -<br /> + <br /> END:infiles - </td> - </tr> + </td> + </tr> + IF:parent - <tr> - <td class="small-title-font">Parent:</td> - <td class="small-title-font"> + <tr class="top-aligned-row"> + <td><strong>Parent:</strong></td> + <td> IF:par_url - <a href="%par_url%" class="aqua"> + <a href="%par_url%"> ENDIF:par_url -%parent% + %parent% IF:par_url - </a> + </a> ENDIF:par_url - </td> - </tr> + </td> + </tr> ENDIF:parent - </table> - </td> - </tr> -</table> -} - -=begin -=end - -########################## Source code ########################## - -SRC_PAGE = %{ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=%charset%"> -<title>%title%</title> -<link rel=StyleSheet href="%style_url%" type="text/css" media="screen" /> -</head> -<body bgcolor="white"> -<pre>%code%</pre> -</body> -</html> -} - -########################## Index ################################ - -FR_INDEX_BODY = %{ -!INCLUDE! -} - -FILE_INDEX = %{ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=%charset%"> -<title>%list_title%</title> -<style type="text/css"> -<!-- - body { -background-color: #ddddff; - font-family: #{FONTS}; - font-size: 11px; - font-style: normal; - line-height: 14px; - color: #000040; - } -div.banner { - background: #0000aa; - color: white; - padding: 1; - margin: 0; - font-size: 90%; - font-weight: bold; - line-height: 1.1; - text-align: center; - width: 100%; -} - -A.xx { color: white; font-weight: bold; } ---> -</style> -<base target="docwin"> -</head> -<body> -<div class="banner"><a href="%index_url%" class="xx">%list_title%</a></div> -START:entries -<a href="%href%">%name%</a><br /> -END:entries -</body></html> -} - -CLASS_INDEX = FILE_INDEX -METHOD_INDEX = FILE_INDEX - -INDEX = %{ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=%charset%"> -<title>%title%</title></head> - -<frameset rows="20%, 80%"> - <frameset cols="25%,35%,45%"> - <frame src="fr_file_index.html" title="Files" name="Files"> - <frame src="fr_class_index.html" name="Classes"> - <frame src="fr_method_index.html" name="Methods"> - </frameset> - <frame src="%initial_page%" name="docwin"> - <noframes> - <body bgcolor="white"> - Sorry, RDoc currently only generates HTML using frames. - </body> - </noframes> -</frameset> - -</html> + </table> + </div> } -###################################################################### -# -# The following is used for the -1 option -# -CONTENTS_XML = %{ -IF:description -%description% -ENDIF:description +##################################################################### +### M E T H O D L I S T T E M P L A T E +##################################################################### -IF:requires -<h4>Requires:</h4> -<ul> -START:requires -IF:aref -<li><a href="%aref%">%name%</a></li> -ENDIF:aref -IFNOT:aref -<li>%name%</li> -ENDIF:aref -END:requires -</ul> -ENDIF:requires - -IF:attributes -<h4>Attributes</h4> -<table> -START:attributes -<tr><td>%name%</td><td>%rw%</td><td>%a_desc%</td></tr> -END:attributes -</table> -ENDIF:attributes +METHOD_LIST = %{ + <!-- if includes --> IF:includes -<h4>Includes</h4> -<ul> + <div id="includes"> + <h2 class="section-bar">Included Modules</h2> + + <div id="includes-list"> START:includes -IF:aref -<li><a href="%aref%">%name%</a></li> -ENDIF:aref -IFNOT:aref -<li>%name%</li> -ENDIF:aref + <span class="include-name">HREF:aref:name:</span> END:includes -</ul> + </div> + </div> ENDIF:includes + + <!-- if method_list --> IF:method_list -<h3>Methods</h3> + <div id="methods"> START:method_list IF:methods + <h2 class="section-bar">%type% %category% methods</h2> + START:methods -<h4>%type% %category% method: <a name="%aref%">%name%%params%</a></h4> + <div id="method-%aref%" class="method-detail"> + <a name="%aref%"></a> + <div class="method-heading"> +IF:codeurl + <a href="%codeurl%" target="Code" class="method-signature" + onclick="popupCode('%codeurl%');return false;"> +ENDIF:codeurl +IF:sourcecode + <a href="#%aref%" class="method-signature"> +ENDIF:sourcecode +IF:callseq + <span class="method-name">%callseq%</span> +ENDIF:callseq +IFNOT:callseq + <span class="method-name">%name%</span><span class="method-args">%params%</span> +ENDIF:callseq +IF:codeurl + </a> +ENDIF:codeurl +IF:sourcecode + </a> +ENDIF:sourcecode + </div> + + <div class="method-description"> IF:m_desc -%m_desc% + %m_desc% ENDIF:m_desc - IF:sourcecode -<blockquote><pre> + <p><a class="source-toggle" href="#" + onclick="toggleCode('%aref%-source');return false;">[Source]</a></p> + <div class="method-source-code" id="%aref%-source"> +<pre> %sourcecode% -</pre></blockquote> +</pre> + </div> ENDIF:sourcecode + </div> + </div> + END:methods ENDIF:methods END:method_list + + </div> ENDIF:method_list } -######################################################################## -ONE_PAGE = %{ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +##################################################################### +### B O D Y T E M P L A T E +##################################################################### + +BODY = HEADER + %{ + +!INCLUDE! <!-- banner header --> + + <div id="bodyContent"> + +} + CONTEXT_CONTENT + METHOD_LIST + %{ + + </div> + +} + FOOTER + + + +##################################################################### +### S O U R C E C O D E T E M P L A T E +##################################################################### + +SRC_PAGE = XHTML_PREAMBLE + %{ +<!-- + + %title% + + --> <html> <head> - <title>%title%</title> - <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> + <title>%title%</title> + <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> + <link rel="stylesheet" href="http://www.FaerieMUD.org/stylesheets/rdoc.css" type="text/css" /> </head> <body> -START:files -<h2>File: %short_name%</h2> -<table> - <tr><td>Path:</td><td>%full_path%</td></tr> - <tr><td>Modified:</td><td>%dtm_modified%</td></tr> -</table> -} + CONTENTS_XML + %{ -END:files - -IF:classes -<h2>Classes</h2> -START:classes -IF:parent -<h3>%classmod% %full_name% < HREF:par_url:parent:</h3> -ENDIF:parent -IFNOT:parent -<h3>%classmod% %full_name%</h3> -ENDIF:parent + <pre>%code%</pre> +</body> +</html> +} -IF:infiles -(in files -START:infiles -HREF:full_path_url:full_path: -END:infiles -) -ENDIF:infiles -} + CONTENTS_XML + %{ -END:classes -ENDIF:classes + +##################################################################### +### I N D E X F I L E T E M P L A T E S +##################################################################### + +FR_INDEX_BODY = %{ +!INCLUDE! +} + +FILE_INDEX = XHTML_PREAMBLE + %{ +<!-- + + %list_title% + + --> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>%list_title%</title> + <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> + <link rel="stylesheet" href="%style_url%" type="text/css" /> + <base target="docwin" /> +</head> +<body> +<div id="index"> + <h1 class="section-bar">%list_title%</h1> + <div id="index-entries"> +START:entries + <a href="%href%">%name%</a><br /> +END:entries + </div> +</div> </body> </html> } -end -end +CLASS_INDEX = FILE_INDEX +METHOD_INDEX = FILE_INDEX + +INDEX = %{<?xml version="1.0" encoding="%charset%"?> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" + "DTD/xhtml1-frameset.dtd"> + +<!-- + + %title% + + --> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>%title%</title> + <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> +</head> +<frameset rows="20%, 80%"> + <frameset cols="25%,35%,45%"> + <frame src="fr_file_index.html" title="Files" name="Files" /> + <frame src="fr_class_index.html" name="Classes" /> + <frame src="fr_method_index.html" name="Methods" /> + </frameset> + <frame src="%initial_page%" name="docwin" /> +</frameset> +</html> +} + + + end # module Page +end # class RDoc + diff --git a/lib/rdoc/generators/template/html/old_html.rb b/lib/rdoc/generators/template/html/old_html.rb new file mode 100644 index 0000000000..3398dc808f --- /dev/null +++ b/lib/rdoc/generators/template/html/old_html.rb @@ -0,0 +1,768 @@ +module RDoc + +# This is how you define the HTML that RDoc generates. Simply create +# a file in rdoc/generators/html_templates that creates the +# module RDoc::Page and populate it as described below. Then invoke +# rdoc using the --template <name of your file> option, and +# your template will be used. +# +# The constants defining pages use a simple templating system: +# +# * The templating system is passed a hash. Keys in the hash correspond +# to tags on this page. The tag %abc% is looked up in the hash, +# and is replaced by the corresponding hash value. +# +# * Some tags are optional. You can detect this using IF/ENDIF +# +# IF: title +# The value of title is %title% +# ENDIF: title +# +# * Some entries in the hash have values that are arrays, where each +# entry in the array is itself a hash. These are used to generate +# lists using the START: construct. For example, given a hash +# containing +# +# { 'people' => [ { 'name' => 'Fred', 'age' => '12' }, +# { 'name' => 'Mary', 'age' => '21' } ] +# +# You could generate a simple table using +# +# <table> +# START:people +# <tr><td>%name%<td>%age%</tr> +# END:people +# </table> +# +# These lists can be nested to an arbitrary depth +# +# * the construct HREF:url:name: generates <a href="%url%">%name%</a> +# if +url+ is defined in the hash, or %name% otherwise. +# +# +# Your file must contain the following constants +# +# [*FONTS*] a list of fonts to be used +# [*STYLE*] a CSS section (without the <style> or comments). This is +# used to generate a style.css file +# +# [*BODY*] +# The main body of all non-index RDoc pages. BODY will contain +# two !INCLUDE!s. The first is used to include a document-type +# specific header (FILE_PAGE or CLASS_PAGE). The second include +# is for the method list (METHOD_LIST). THe body is passed: +# +# %title%:: +# the page's title +# +# %style_url%:: +# the url of a style sheet for this page +# +# %diagram%:: +# the optional URL of a diagram for this page +# +# %description%:: +# a (potentially multi-paragraph) string containing the +# description for th file/class/module. +# +# %requires%:: +# an optional list of %aref%/%name% pairs, one for each module +# required by this file. +# +# %methods%:: +# an optional list of %aref%/%name%, one for each method +# documented on this page. This is intended to be an index. +# +# %attributes%:: +# An optional list. For each attribute it contains: +# %name%:: the attribute name +# %rw%:: r/o, w/o, or r/w +# %a_desc%:: description of the attribute +# +# %classlist%:: +# An optional string containing an already-formatted list of +# classes and modules documented in this file +# +# For FILE_PAGE entries, the body will be passed +# +# %short_name%:: +# The name of the file +# +# %full_path%:: +# The full path to the file +# +# %dtm_modified%:: +# The date/time the file was last changed +# +# For class and module pages, the body will be passed +# +# %classmod%:: +# The name of the class or module +# +# %files%:: +# A list. For each file this class is defined in, it contains: +# %full_path_url%:: an (optional) URL of the RDoc page +# for this file +# %full_path%:: the name of the file +# +# %par_url%:: +# The (optional) URL of the RDoc page documenting this class's +# parent class +# +# %parent%:: +# The name of this class's parent. +# +# For both files and classes, the body is passed the following information +# on includes and methods: +# +# %includes%:: +# Optional list of included modules. For each, it receives +# %aref%:: optional URL to RDoc page for the module +# %name%:: the name of the module +# +# %method_list%:: +# Optional list of methods of a particular class and category. +# +# Each method list entry contains: +# +# %type%:: public/private/protected +# %category%:: instance/class +# %methods%:: a list of method descriptions +# +# Each method description contains: +# +# %aref%:: a target aref, used when referencing this method +# description. You should code this as <a name="%aref%"> +# %codeurl%:: the optional URL to the page containing this method's +# source code. +# %name%:: the method's name +# %params%:: the method's parameters +# %callseq%:: a full calling sequence +# %m_desc%:: the (potentially multi-paragraph) description of +# this method. +# +# [*CLASS_PAGE*] +# Header for pages documenting classes and modules. See +# BODY above for the available parameters. +# +# [*FILE_PAGE*] +# Header for pages documenting files. See +# BODY above for the available parameters. +# +# [*METHOD_LIST*] +# Controls the display of the listing of methods. See BODY for +# parameters. +# +# [*INDEX*] +# The top-level index page. For a browser-like environment +# define a frame set that includes the file, class, and +# method indices. Passed +# %title%:: title of page +# %initial_page% :: url of initial page to display +# +# [*CLASS_INDEX*] +# Individual files for the three indexes. Passed: +# %index_url%:: URL of main index page +# %entries%:: List of +# %name%:: name of an index entry +# %href%:: url of corresponding page +# [*METHOD_INDEX*] +# Same as CLASS_INDEX for methods +# +# [*FILE_INDEX*] +# Same as CLASS_INDEX for methods +# +# [*FR_INDEX_BODY*] +# A wrapper around CLASS_INDEX, METHOD_INDEX, and FILE_INDEX. +# If those index strings contain the complete HTML for the +# output, then FR_INDEX_BODY can simply be !INCLUDE! +# +# [*SRC_PAGE*] +# Page used to display source code. Passed %title% and %code%, +# the latter being a multi-line string of code. + +module Page + +FONTS = "Verdana, Arial, Helvetica, sans-serif" + +STYLE = %{ +body,td,p { font-family: %fonts%; + color: #000040; +} + +.attr-rw { font-size: x-small; color: #444488 } + +.title-row { background: #0000aa; + color: #eeeeff; +} + +.big-title-font { color: white; + font-family: %fonts%; + font-size: large; + height: 50px} + +.small-title-font { color: aqua; + font-family: %fonts%; + font-size: xx-small; } + +.aqua { color: aqua } + +.method-name, attr-name { + font-family: monospace; font-weight: bold; +} + +.tablesubtitle, .tablesubsubtitle { + width: 100%; + margin-top: 1ex; + margin-bottom: .5ex; + padding: 5px 0px 5px 20px; + font-size: large; + color: aqua; + background: #3333cc; +} + +.name-list { + font-family: monospace; + margin-left: 40px; + margin-bottom: 2ex; + line-height: 140%; +} + +.description { + margin-left: 40px; + margin-top: -2ex; + margin-bottom: 2ex; +} + +.description p { + line-height: 140%; +} + +.aka { + margin-left: 40px; + margin-bottom: 2ex; + line-height: 100%; + font-size: small; + color: #808080; +} + +.methodtitle { + font-size: medium; + text-decoration: none; + color: #0000AA; + background: white; +} + +.paramsig { + font-size: small; +} + +.srcbut { float: right } + +pre { font-size: 1.2em; } +tt { font-size: 1.2em; } + +pre.source { + border-style: groove; + background-color: #ddddff; + margin-left: 40px; + padding: 1em 0em 1em 2em; +} + +.classlist { + margin-left: 40px; + margin-bottom: 2ex; + line-height: 140%; +} + +li { + display: list-item; + margin-top: .6em; +} + +.ruby-comment { color: green; font-style: italic } +.ruby-constant { color: #4433aa; font-weight: bold; } +.ruby-identifier { color: #222222; } +.ruby-ivar { color: #2233dd; } +.ruby-keyword { color: #3333FF; font-weight: bold } +.ruby-node { color: #777777; } +.ruby-operator { color: #111111; } +.ruby-regexp { color: #662222; } +.ruby-value { color: #662222; font-style: italic } + +} + + +############################################################################ + + +HEADER = %{ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>%title%</title> + <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> + <link rel=StyleSheet href="%style_url%" type="text/css" media="screen" /> + <script type="text/javascript" language="JavaScript"> + <!-- + function popCode(url) { + window.open(url, "Code", + "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") + } + //--> + </script> +</head> +} + + +################################################################### + +METHOD_LIST = %{ +IF:includes +<table summary="Included modules" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">Included modules</td></tr> +</table> +<div class="name-list"> +START:includes + <span class="method-name">HREF:aref:name:</span> +END:includes +</div> +ENDIF:includes + +IF:method_list +START:method_list +IF:methods +<table summary="Method list" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">%type% %category% methods</td></tr> +</table> +START:methods +<table summary="method" width="100%" cellspacing="0" cellpadding="5" border="0"> +<tr><td class="methodtitle"> +<a name="%aref%"></a> +IF:codeurl +<a href="%codeurl%" target="Code" class="methodtitle" + onClick="popCode('%codeurl%');return false;"> +ENDIF:codeurl +IF:callseq +<b>%callseq%</b> +ENDIF:callseq +IFNOT:callseq +<b>%name%</b>%params% +ENDIF:callseq +IF:codeurl +</a> +ENDIF:codeurl +</td></tr> +</table> +IF:m_desc +<div class="description"> +%m_desc% +</div> +ENDIF:m_desc +IF:aka +<div class="aka"> +This method is also aliased as +START:aka +<a href="%aref%">%name%</a> +END:aka +</div> +ENDIF:aka +IF:sourcecode +<pre class="source"> +%sourcecode% +</pre> +ENDIF:sourcecode +END:methods +ENDIF:methods +END:method_list +ENDIF:method_list +} + +################################################################### + +CONTEXT_CONTENT = %{ +IF:diagram +<table summary="Diagram of classes and modules" width="100%"> +<tr><td align="center"> +%diagram% +</td></tr></table> +ENDIF:diagram + + +IF:description +<div class="description">%description%</div> +ENDIF:description + +IF:requires +<table summary="Requires" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">Required files</td></tr> +</table> +<div class="name-list"> +START:requires +HREF:aref:name: +END:requires +</div> +ENDIF:requires + +IF:methods +<table summary="Methods" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">Methods</td></tr> +</table> +<div class="name-list"> +START:methods +HREF:aref:name: +END:methods +</div> +ENDIF:methods + +IF:constants +<table summary="Constants" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">Constants</td></tr> +</table> +<table cellpadding="5"> +START:constants +<tr valign="top"><td>%name%</td><td>=</td><td>%value%</td></tr> +IF:desc +<tr><td></td><td></td><td>%desc%</td></tr> +ENDIF:desc +END:constants +</table> +ENDIF:constants + +IF:aliases +<table summary="Aliases" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">External Aliases</td></tr> +</table> +<div class="name-list"> +START:aliases +%old_name% -> %new_name%<br /> +END:aliases +</div> +ENDIF:aliases + +IF:attributes +<table summary="Attributes" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">Attributes</td></tr> +</table> +<table summary="Attribute details" cellspacing="5"> +START:attributes + <tr valign="top"> + <td class="attr-name">%name%</td> +IF:rw + <td align="center" class="attr-rw"> [%rw%] </td> +ENDIF:rw +IFNOT:rw + <td></td> +ENDIF:rw + <td>%a_desc%</td> + </tr> +END:attributes +</table> +ENDIF:attributes + +IF:classlist +<table summary="List of classes" cellpadding="5" width="100%"> +<tr><td class="tablesubtitle">Classes and Modules</td></tr> +</table> +<div class="classlist"> +%classlist% +</div> +ENDIF:classlist +} + +############################################################################### + +BODY = HEADER + %{ +<body bgcolor="white"> +!INCLUDE! <!-- banner header --> +} + +CONTEXT_CONTENT + METHOD_LIST + +%{ +</body> +</html> +} + + +############################################################################### + +FILE_PAGE = <<_FILE_PAGE_ +<table summary="Information on file" width="100%"> + <tr class="title-row"> + <td><table summary="layout" width="100%"><tr> + <td class="big-title-font" colspan="2">%short_name%</td> + <td align="right"><table summary="layout" cellspacing="0" cellpadding="2"> + <tr> + <td class="small-title-font">Path:</td> + <td class="small-title-font">%full_path% +IF:cvsurl + (<a href="%cvsurl%">CVS</a>) +ENDIF:cvsurl + </td> + </tr> + <tr> + <td class="small-title-font">Modified:</td> + <td class="small-title-font">%dtm_modified%</td> + </tr> + </table> + </td></tr></table></td> + </tr> +</table> +_FILE_PAGE_ + +################################################################### + +CLASS_PAGE = %{ +<table summary="Information on class" width="100%" border="0" cellspacing="0"> + <tr class="title-row"> + <td class="big-title-font"> + <sup><font color="aqua">%classmod%</font></sup> %full_name% + </td> + <td align="right"> + <table summary="layout" cellspacing="0" cellpadding="2"> + <tr valign="top"> + <td class="small-title-font">In:</td> + <td class="small-title-font"> +START:infiles +IF:full_path_url + <a href="%full_path_url%" class="aqua"> +ENDIF:full_path_url +%full_path% +IF:full_path_url + </a> +ENDIF:full_path_url +IF:cvsurl + (<a href="%cvsurl%">CVS</a>) +ENDIF:cvsurl +<br /> +END:infiles + </td> + </tr> +IF:parent + <tr> + <td class="small-title-font">Parent:</td> + <td class="small-title-font"> +IF:par_url + <a href="%par_url%" class="aqua"> +ENDIF:par_url +%parent% +IF:par_url + </a> +ENDIF:par_url + </td> + </tr> +ENDIF:parent + </table> + </td> + </tr> +</table> +} + +=begin +=end + +########################## Source code ########################## + +SRC_PAGE = %{ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=%charset%"> +<title>%title%</title> +<link rel=StyleSheet href="%style_url%" type="text/css" media="screen" /> +</head> +<body bgcolor="white"> +<pre>%code%</pre> +</body> +</html> +} + +########################## Index ################################ + +FR_INDEX_BODY = %{ +!INCLUDE! +} + +FILE_INDEX = %{ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=%charset%"> +<title>%list_title%</title> +<style type="text/css"> +<!-- + body { +background-color: #ddddff; + font-family: #{FONTS}; + font-size: 11px; + font-style: normal; + line-height: 14px; + color: #000040; + } +div.banner { + background: #0000aa; + color: white; + padding: 1; + margin: 0; + font-size: 90%; + font-weight: bold; + line-height: 1.1; + text-align: center; + width: 100%; +} + +A.xx { color: white; font-weight: bold; } +--> +</style> +<base target="docwin"> +</head> +<body> +<div class="banner"><a href="%index_url%" class="xx">%list_title%</a></div> +START:entries +<a href="%href%">%name%</a><br /> +END:entries +</body></html> +} + +CLASS_INDEX = FILE_INDEX +METHOD_INDEX = FILE_INDEX + +INDEX = %{ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=%charset%"> +<title>%title%</title></head> + +<frameset rows="20%, 80%"> + <frameset cols="25%,35%,45%"> + <frame src="fr_file_index.html" title="Files" name="Files"> + <frame src="fr_class_index.html" name="Classes"> + <frame src="fr_method_index.html" name="Methods"> + </frameset> + <frame src="%initial_page%" name="docwin"> + <noframes> + <body bgcolor="white"> + Sorry, RDoc currently only generates HTML using frames. + </body> + </noframes> +</frameset> + +</html> +} + +###################################################################### +# +# The following is used for the -1 option +# + +CONTENTS_XML = %{ +IF:description +%description% +ENDIF:description + +IF:requires +<h4>Requires:</h4> +<ul> +START:requires +IF:aref +<li><a href="%aref%">%name%</a></li> +ENDIF:aref +IFNOT:aref +<li>%name%</li> +ENDIF:aref +END:requires +</ul> +ENDIF:requires + +IF:attributes +<h4>Attributes</h4> +<table> +START:attributes +<tr><td>%name%</td><td>%rw%</td><td>%a_desc%</td></tr> +END:attributes +</table> +ENDIF:attributes + +IF:includes +<h4>Includes</h4> +<ul> +START:includes +IF:aref +<li><a href="%aref%">%name%</a></li> +ENDIF:aref +IFNOT:aref +<li>%name%</li> +ENDIF:aref +END:includes +</ul> +ENDIF:includes + +IF:method_list +<h3>Methods</h3> +START:method_list +IF:methods +START:methods +<h4>%type% %category% method: <a name="%aref%">%name%%params%</a></h4> + +IF:m_desc +%m_desc% +ENDIF:m_desc + +IF:sourcecode +<blockquote><pre> +%sourcecode% +</pre></blockquote> +ENDIF:sourcecode +END:methods +ENDIF:methods +END:method_list +ENDIF:method_list +} + +######################################################################## + +ONE_PAGE = %{ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> + <title>%title%</title> + <meta http-equiv="Content-Type" content="text/html; charset=%charset%" /> +</head> +<body> +START:files +<h2>File: %short_name%</h2> +<table> + <tr><td>Path:</td><td>%full_path%</td></tr> + <tr><td>Modified:</td><td>%dtm_modified%</td></tr> +</table> +} + CONTENTS_XML + %{ +END:files + +IF:classes +<h2>Classes</h2> +START:classes +IF:parent +<h3>%classmod% %full_name% < HREF:par_url:parent:</h3> +ENDIF:parent +IFNOT:parent +<h3>%classmod% %full_name%</h3> +ENDIF:parent + +IF:infiles +(in files +START:infiles +HREF:full_path_url:full_path: +END:infiles +) +ENDIF:infiles +} + CONTENTS_XML + %{ +END:classes +ENDIF:classes +</body> +</html> +} + +end +end diff --git a/lib/rdoc/markup/simple_markup/inline.rb b/lib/rdoc/markup/simple_markup/inline.rb index 684ff4b275..7b476e559d 100644 --- a/lib/rdoc/markup/simple_markup/inline.rb +++ b/lib/rdoc/markup/simple_markup/inline.rb @@ -227,7 +227,8 @@ module SM add_html("em", :EM) add_html("i", :EM) add_html("b", :BOLD) - add_html("tt", :TT) + add_html("tt", :TT) + add_html("code", :TT) end def add_word_pair(start, stop, name) diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb index 1de4797c5f..83fd3a0209 100644 --- a/lib/rdoc/parsers/parse_c.rb +++ b/lib/rdoc/parsers/parse_c.rb @@ -324,7 +324,7 @@ module RDoc if comment.sub!(/call-seq:(.*?)^\s*\*?\s*$/m, '') seq = $1 seq.gsub!(/^\s*\*\s*/, '') - meth_obj.params = "!verb!" + seq + meth_obj.call_seq = seq end # meth_obj.params = params diff --git a/lib/rdoc/ri/ri_cache.rb b/lib/rdoc/ri/ri_cache.rb index 9e8c897d36..8d7c982409 100644 --- a/lib/rdoc/ri/ri_cache.rb +++ b/lib/rdoc/ri/ri_cache.rb @@ -53,6 +53,10 @@ module RI @inferior_classes.find_all {|c| c.name[name]} end + def classes_and_modules + @inferior_classes + end + # Return an exact match to a particular name def contained_class_named(name) @inferior_classes.find {|c| c.name == name} @@ -60,7 +64,7 @@ module RI # return the list of local methods matching name # We're split into two because we need distinct behavior - # when called from the toplevel + # when called from the _toplevel_ def methods_matching(name, is_class_method) local_methods_matching(name, is_class_method) end diff --git a/lib/rdoc/ri/ri_formatter.rb b/lib/rdoc/ri/ri_formatter.rb index b3024d4c6c..03fee89d8f 100644 --- a/lib/rdoc/ri/ri_formatter.rb +++ b/lib/rdoc/ri/ri_formatter.rb @@ -1,8 +1,17 @@ module RI class TextFormatter - def TextFormatter.create(options, indent) - new(options, indent) + def TextFormatter.list + "plain, bs, ansi" + end + + def TextFormatter.for(name) + case name + when /plain/i then TextFormatter + when /bs/i then OverstrikeFormatter + when /ansi/i then AnsiFormatter + else nil + end end attr_reader :indent @@ -20,7 +29,10 @@ module RI len = @width len -= (label.size+1) if label print "-"*len - print(" ", label) if label + if label + print(" ") + bold_print(label) + end puts end @@ -55,6 +67,12 @@ module RI ###################################################################### + def bold_print(txt) + print txt + end + + ###################################################################### + # convert HTML entities back to ASCII def conv_html(txt) txt. @@ -126,7 +144,7 @@ module RI else display_flow_item(item) end - end + end end ###################################################################### @@ -147,24 +165,7 @@ module RI blankline when SM::Flow::H - text = conv_html(item.text.join) - case item.level - when 1 - ul = "=" * text.length - puts - puts text.upcase - puts ul - puts - - when 2 - ul = "-" * text.length - puts - puts text - puts ul - puts - else - print "\n", @indent, text, "\n\n" - end + display_heading(conv_html(item.text.join), item.level, @indent) else fail "Unknown flow element: #{item.class}" end @@ -172,13 +173,277 @@ module RI ###################################################################### + def display_heading(text, level, indent) + case level + when 1 + ul = "=" * text.length + puts + puts text.upcase + puts ul +# puts + + when 2 + ul = "-" * text.length + puts + puts text + puts ul +# puts + else + print indent, text, "\n" + end + end + + ###################################################################### + def display_flow(flow) flow.each do |f| display_flow_item(f) end end end + + + # Handle text with attributes. We're a base class: there are + # different presentation classes (one, for example, uses overstrikes + # to handle bold and underlinig, while another using ANSI escape + # sequences + + class AttributeFormatter < TextFormatter + + BOLD = 1 + ITALIC = 2 + CODE = 4 + + ATTR_MAP = { + "b" => BOLD, + "code" => CODE, + "em" => ITALIC, + "i" => ITALIC, + "tt" => CODE + } + + # TODO: struct? + class AttrChar + attr_reader :char + attr_reader :attr + + def initialize(char, attr) + @char = char + @attr = attr + end + end + + + class AttributeString + def initialize + @txt = [] + @optr = 0 + end + + def <<(char) + @txt << char + end + + def empty? + @optr >= @txt.length + end + + # accept non space, then all following spaces + def next_word + start = @optr + len = @txt.length + + while @optr < len && @txt[@optr].char != " " + @optr += 1 + end + + while @optr < len && @txt[@optr].char == " " + @optr += 1 + end + + @txt[start...@optr] + end + end + + ###################################################################### + # overrides base class. Looks for <tt>...</tt> etc sequences + # and generates an array of AttrChars. This array is then used + # as the basis for the split + + def wrap(txt, prefix=@indent, linelen=@width) + return unless txt && !txt.empty? + + txt = add_attributes_to(txt) + + line = [] + + until txt.empty? + word = txt.next_word + if word.size + line.size > linelen - @indent.size + write_attribute_text(line) + line = [] + end + line.concat(word) + end + + write_attribute_text(line) if line.length > 0 + end + + protected + + # overridden in specific formatters + + def write_attribute_text(line) + print @indent + line.each do |achar| + print achar.char + end + puts + end + + # again, overridden + + def bold_print(txt) + print txt + end + + private + + def add_attributes_to(txt) + tokens = txt.split(%r{(</?(?:b|code|em|i|tt)>)}) + text = AttributeString.new + attributes = 0 + tokens.each do |tok| + case tok + when %r{^</(\w+)>$} then attributes &= ~(ATTR_MAP[$1]||0) + when %r{^<(\w+)>$} then attributes |= (ATTR_MAP[$1]||0) + else + tok.split(//).each {|ch| text << AttrChar.new(ch, attributes)} + end + end + text + end + + end + + + ################################################## + + # This formatter generates overstrike-style formatting, which + # works with pages such as man and less. + + class OverstrikeFormatter < AttributeFormatter + + BS = "\C-h" + + def write_attribute_text(line) + print @indent + line.each do |achar| + attr = achar.attr + if (attr & (ITALIC+CODE)) != 0 + print "_", BS + end + if (attr & BOLD) != 0 + print achar.char, BS + end + print achar.char + end + puts + end + + # draw a string in bold + def bold_print(text) + text.split(//).each do |ch| + print ch, BS, ch + end + end + end + + ################################################## + + # This formatter uses ANSI escape sequences + # to colorize stuff + # works with pages such as man and less. + + class AnsiFormatter < AttributeFormatter + + BS = "\C-h" + + def initialize(*args) + print "\033[0m" + super + end + + def write_attribute_text(line) + print @indent + curr_attr = 0 + line.each do |achar| + attr = achar.attr + if achar.attr != curr_attr + update_attributes(achar.attr) + curr_attr = achar.attr + end + print achar.char + end + update_attributes(0) unless curr_attr.zero? + puts + end + + + def bold_print(txt) + print "\033[1m#{txt}\033[m" + end + + HEADINGS = { + 1 => "\033[1;32m%s\033[m", + 2 => "\033[4;32m%s\033[m", + 3 => "\033[32m%s\033[m" + } + + def display_heading(text, level, indent) + level = 3 if level > 3 + print indent + printf(HEADINGS[level], text) + puts + end + + private + + ATTR_MAP = { + BOLD => "1", + ITALIC => "33", + CODE => "36" + } + + def update_attributes(attr) + str = "\033[" + for quality in [ BOLD, ITALIC, CODE] + unless (attr & quality).zero? + str << ATTR_MAP[quality] + end + end + print str, "m" + end + end +# options = "options" +# def options.width +# 70 +# end +# a = OverstrikeFormatter.new(options, " ") +# a.wrap( +# "The quick <b>brown</b> and <i>italic</i> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " + +# "The quick <b>brown and <i>italic</i></b> dog " +# ) end diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb index 3ec6d4657c..9b0704d421 100644 --- a/lib/rdoc/ri/ri_options.rb +++ b/lib/rdoc/ri/ri_options.rb @@ -18,13 +18,24 @@ module RI # The width of the output line attr_reader :width - + + # the formatting we apply to the output + attr_reader :formatter + module OptionList OPTION_LIST = [ [ "--help", "-h", nil, "you're looking at it" ], - + + [ "--format", "-f", "<name>", + "Format to use when displaying output:\n" + + " " + RI::TextFormatter.list + "\n" + + "Use 'bs' (backspace) with most pager programs.\n" + + "To use ANSI, either also use the -T option, or\n\n" + + "tell your pager to allow control characters\n" + + "(for example using the -R option to less)"], + [ "--no-pager", "-T", nil, "Send output directly to stdout." ], @@ -63,7 +74,7 @@ module RI # Show usage and exit - def OptionList.usage + def OptionList.usage(short_form=false) puts puts(RI::VERSION_STRING) @@ -96,12 +107,15 @@ module RI containing puncuation: ri 'Array.[]' - ri compact\! - - Options: + ri compact\\! EOT - + + if short_form + class_list + puts "For help, type 'ri -h'" + else + puts "Options:\n\n" OPTION_LIST.each do |long, short, arg, desc| opt = sprintf("%20s", "#{long}, #{short}") oparg = sprintf("%-7s", arg) @@ -120,6 +134,23 @@ module RI exit 0 end + end + + def OptionList.class_list + paths = RI::Paths::PATH + if paths.empty? + puts "Before using ri, you need to generate documentation" + puts "using 'rdoc' with the --ri option" + else + @ri_reader = RI::RiReader.new(RI::RiCache.new(paths)) + puts + puts "Classes and modules I know about:" + puts + puts @ri_reader.class_names.sort.join(", ") + puts + end + end + end # Parse command line options. @@ -128,7 +159,8 @@ module RI @use_stdout = !STDOUT.tty? @width = 72 - + @formatter = RI::TextFormatter.for("plain") + begin go = GetoptLong.new(*OptionList.options) @@ -138,6 +170,13 @@ module RI case opt when "--help" then OptionList.usage when "--no-pager" then @use_stdout = true + when "--format" + @formatter = RI::TextFormatter.for(arg) + unless @formatter + $stderr.print "Invalid formatter (should be one of " + $stderr.puts RI::TextFormatter.list + ")" + exit 1 + end when "--width" begin @width = Integer(arg) diff --git a/lib/rdoc/ri/ri_reader.rb b/lib/rdoc/ri/ri_reader.rb index dd647b3f89..ddce38f101 100644 --- a/lib/rdoc/ri/ri_reader.rb +++ b/lib/rdoc/ri/ri_reader.rb @@ -52,5 +52,19 @@ module RI File.open(path) {|f| RI::Description.deserialize(f) } end + # return the names of all classes and modules + def class_names + res = [] + find_classes_in(res, @cache.toplevel) + end + + def find_classes_in(res, klass) + classes = klass.classes_and_modules + for c in classes + res << c.name + find_classes_in(res, c) + end + res + end end end |