mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rdoc/markup/to_joined_paragraph.rb: Completed documentation
* lib/rdoc/parser/c.rb: ditto * lib/rdoc/parser/changelog.rb: ditto * lib/rdoc/servlet.rb: ditto * lib/rdoc/store.rb: ditto * lib/rdoc/store.rb: Improved HTML error page. Completed documentation * lib/rdoc/parser/ruby.rb: Fixed bug attaching a comment to A::B = 42 * test/rdoc/test_rdoc_parser_ruby.rb: Test for above * test/rdoc/test_rdoc_comment.rb: Removed garbage git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
08f0db2c68
commit
85e3560a3b
9 changed files with 381 additions and 25 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
Fri Dec 7 14:22:29 2012 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/rdoc/markup/to_joined_paragraph.rb: Completed documentation
|
||||||
|
* lib/rdoc/parser/c.rb: ditto
|
||||||
|
* lib/rdoc/parser/changelog.rb: ditto
|
||||||
|
* lib/rdoc/servlet.rb: ditto
|
||||||
|
* lib/rdoc/store.rb: ditto
|
||||||
|
|
||||||
|
* lib/rdoc/store.rb: Improved HTML error page. Completed
|
||||||
|
documentation
|
||||||
|
|
||||||
|
* lib/rdoc/parser/ruby.rb: Fixed bug attaching a comment to A::B = 42
|
||||||
|
* test/rdoc/test_rdoc_parser_ruby.rb: Test for above
|
||||||
|
|
||||||
|
* test/rdoc/test_rdoc_comment.rb: Removed garbage
|
||||||
|
|
||||||
Fri Dec 7 14:03:59 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Dec 7 14:03:59 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/timeout.rb (Timeout#timeout): since async_interrupt_timing
|
* lib/timeout.rb (Timeout#timeout): since async_interrupt_timing
|
||||||
|
|
|
@ -12,12 +12,15 @@ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
|
||||||
super nil
|
super nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_accepting
|
def start_accepting # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def end_accepting
|
def end_accepting # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Converts the parts of +paragraph+ to a single entry.
|
||||||
|
|
||||||
def accept_paragraph paragraph
|
def accept_paragraph paragraph
|
||||||
parts = []
|
parts = []
|
||||||
string = false
|
string = false
|
||||||
|
|
|
@ -446,6 +446,10 @@ class RDoc::Parser::C < RDoc::Parser
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Creates classes and module that were missing were defined due to the file
|
||||||
|
# order being different than the declaration order.
|
||||||
|
|
||||||
def do_missing
|
def do_missing
|
||||||
return if @missing_dependencies.empty?
|
return if @missing_dependencies.empty?
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,28 @@
|
||||||
require 'time'
|
require 'time'
|
||||||
|
|
||||||
|
##
|
||||||
|
# A ChangeLog file parser.
|
||||||
|
#
|
||||||
|
# This parser converts a ChangeLog into an RDoc::Markup::Document. When
|
||||||
|
# viewed as HTML a ChangeLog page will have an entry for each day's entries in
|
||||||
|
# the sidebar table of contents.
|
||||||
|
#
|
||||||
|
# This parser is meant to parse the MRI ChangeLog, but can be used to parse any
|
||||||
|
# {GNU style Change
|
||||||
|
# Log}[http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html].
|
||||||
|
|
||||||
class RDoc::Parser::ChangeLog < RDoc::Parser
|
class RDoc::Parser::ChangeLog < RDoc::Parser
|
||||||
|
|
||||||
include RDoc::Parser::Text
|
include RDoc::Parser::Text
|
||||||
|
|
||||||
parse_files_matching(/(\/|\\|\A)ChangeLog[^\/\\]*\z/)
|
parse_files_matching(/(\/|\\|\A)ChangeLog[^\/\\]*\z/)
|
||||||
|
|
||||||
|
##
|
||||||
|
# Attaches the +continuation+ of the previous line to the +entry_body+.
|
||||||
|
#
|
||||||
|
# Continued function listings are joined together as a single entry.
|
||||||
|
# Continued descriptions are joined to make a single paragraph.
|
||||||
|
|
||||||
def continue_entry_body entry_body, continuation
|
def continue_entry_body entry_body, continuation
|
||||||
return unless last = entry_body.last
|
return unless last = entry_body.last
|
||||||
|
|
||||||
|
@ -21,6 +38,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Creates an RDoc::Markup::Document given the +groups+ of ChangeLog entries.
|
||||||
|
|
||||||
def create_document groups
|
def create_document groups
|
||||||
doc = RDoc::Markup::Document.new
|
doc = RDoc::Markup::Document.new
|
||||||
doc.omit_headings_below = 2
|
doc.omit_headings_below = 2
|
||||||
|
@ -39,6 +59,10 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
||||||
doc
|
doc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns a list of ChangeLog entries an RDoc::Markup nodes for the given
|
||||||
|
# +entries+.
|
||||||
|
|
||||||
def create_entries entries
|
def create_entries entries
|
||||||
out = []
|
out = []
|
||||||
|
|
||||||
|
@ -52,6 +76,10 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns an RDoc::Markup::List containing the given +items+ in the
|
||||||
|
# ChangeLog
|
||||||
|
|
||||||
def create_items items
|
def create_items items
|
||||||
list = RDoc::Markup::List.new :NOTE
|
list = RDoc::Markup::List.new :NOTE
|
||||||
|
|
||||||
|
@ -69,12 +97,30 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Groups +entries+ by date.
|
||||||
|
|
||||||
def group_entries entries
|
def group_entries entries
|
||||||
entries.group_by do |title, body|
|
entries.group_by do |title, _|
|
||||||
Time.parse(title).strftime "%Y-%m-%d"
|
Time.parse(title).strftime "%Y-%m-%d"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Parses the entries in the ChangeLog.
|
||||||
|
#
|
||||||
|
# Returns an Array of each ChangeLog entry in order of parsing.
|
||||||
|
#
|
||||||
|
# A ChangeLog entry is an Array containing the ChangeLog title (date and
|
||||||
|
# committer) and an Array of ChangeLog items (file and function changed with
|
||||||
|
# description).
|
||||||
|
#
|
||||||
|
# An example result would be:
|
||||||
|
#
|
||||||
|
# [ 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
|
||||||
|
# [ 'README.EXT: Converted to RDoc format',
|
||||||
|
# 'README.EXT.ja: ditto']]
|
||||||
|
|
||||||
def parse_entries
|
def parse_entries
|
||||||
entries = []
|
entries = []
|
||||||
entry_name = nil
|
entry_name = nil
|
||||||
|
@ -122,6 +168,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
||||||
entries
|
entries
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Converts the ChangeLog into an RDoc::Markup::Document
|
||||||
|
|
||||||
def scan
|
def scan
|
||||||
entries = parse_entries
|
entries = parse_entries
|
||||||
grouped_entries = group_entries entries
|
grouped_entries = group_entries entries
|
||||||
|
|
|
@ -240,7 +240,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
||||||
# with :: separated named) and return the ultimate name, the associated
|
# with :: separated named) and return the ultimate name, the associated
|
||||||
# container, and the given name (with the ::).
|
# container, and the given name (with the ::).
|
||||||
|
|
||||||
def get_class_or_module container
|
def get_class_or_module container, ignore_constants = false
|
||||||
skip_tkspace
|
skip_tkspace
|
||||||
name_t = get_tk
|
name_t = get_tk
|
||||||
given_name = ''
|
given_name = ''
|
||||||
|
@ -259,9 +259,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
||||||
while TkCOLON2 === peek_tk do
|
while TkCOLON2 === peek_tk do
|
||||||
prev_container = container
|
prev_container = container
|
||||||
container = container.find_module_named name_t.name
|
container = container.find_module_named name_t.name
|
||||||
container ||= prev_container.add_module RDoc::NormalModule, name_t.name
|
container ||=
|
||||||
|
if ignore_constants then
|
||||||
|
RDoc::Context.new
|
||||||
|
else
|
||||||
|
c = prev_container.add_module RDoc::NormalModule, name_t.name
|
||||||
|
c.ignore unless prev_container.document_children
|
||||||
|
c
|
||||||
|
end
|
||||||
|
|
||||||
container.ignore unless prev_container.document_children
|
container.record_location @top_level
|
||||||
|
|
||||||
get_tk
|
get_tk
|
||||||
skip_tkspace false
|
skip_tkspace false
|
||||||
|
@ -663,9 +670,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Parses a constant in +context+ with +comment+
|
# Parses a constant in +context+ with +comment+. If +ignore_constants+ is
|
||||||
|
# true, no found constants will be added to RDoc.
|
||||||
|
|
||||||
def parse_constant container, tk, comment
|
def parse_constant container, tk, comment, ignore_constants = false
|
||||||
offset = tk.seek
|
offset = tk.seek
|
||||||
line_no = tk.line_no
|
line_no = tk.line_no
|
||||||
|
|
||||||
|
@ -676,6 +684,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
||||||
|
|
||||||
eq_tk = get_tk
|
eq_tk = get_tk
|
||||||
|
|
||||||
|
if TkCOLON2 === eq_tk then
|
||||||
|
unget_tk eq_tk
|
||||||
|
unget_tk tk
|
||||||
|
|
||||||
|
container, name_t, = get_class_or_module container, ignore_constants
|
||||||
|
|
||||||
|
name = name_t.name
|
||||||
|
|
||||||
|
eq_tk = get_tk
|
||||||
|
end
|
||||||
|
|
||||||
unless TkASSIGN === eq_tk then
|
unless TkASSIGN === eq_tk then
|
||||||
unget_tk eq_tk
|
unget_tk eq_tk
|
||||||
return false
|
return false
|
||||||
|
@ -1334,6 +1353,26 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Parses a rescue
|
||||||
|
|
||||||
|
def parse_rescue
|
||||||
|
skip_tkspace false
|
||||||
|
|
||||||
|
while tk = get_tk
|
||||||
|
case tk
|
||||||
|
when TkNL, TkSEMICOLON then
|
||||||
|
break
|
||||||
|
when TkCOMMA then
|
||||||
|
skip_tkspace false
|
||||||
|
|
||||||
|
get_tk if TkNL === peek_tk
|
||||||
|
end
|
||||||
|
|
||||||
|
skip_tkspace false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# The core of the ruby parser.
|
# The core of the ruby parser.
|
||||||
|
|
||||||
|
@ -1407,7 +1446,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
||||||
parse_method container, single, tk, comment
|
parse_method container, single, tk, comment
|
||||||
|
|
||||||
when TkCONSTANT then
|
when TkCONSTANT then
|
||||||
unless parse_constant container, tk, comment then
|
unless parse_constant container, tk, comment, current_method then
|
||||||
try_parse_comment = true
|
try_parse_comment = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1441,6 +1480,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
||||||
when TkSUPER then
|
when TkSUPER then
|
||||||
current_method.calls_super = true if current_method
|
current_method.calls_super = true if current_method
|
||||||
|
|
||||||
|
when TkRESCUE then
|
||||||
|
parse_rescue
|
||||||
|
|
||||||
when TkIDENTIFIER then
|
when TkIDENTIFIER then
|
||||||
if nest == 1 and current_method.nil? then
|
if nest == 1 and current_method.nil? then
|
||||||
case tk.name
|
case tk.name
|
||||||
|
|
|
@ -2,21 +2,60 @@ require 'rdoc'
|
||||||
require 'time'
|
require 'time'
|
||||||
require 'webrick'
|
require 'webrick'
|
||||||
|
|
||||||
|
##
|
||||||
|
# This is a WEBrick servlet that allows you to browse ri documentation.
|
||||||
|
#
|
||||||
|
# You can show documentation through either `ri --server` or, with RubyGems
|
||||||
|
# 2.0 or newer, `gem server`. For ri, the server runs on port 8214 by
|
||||||
|
# default. For RubyGems the server runs on port 8808 by default.
|
||||||
|
#
|
||||||
|
# You can use this servlet in your own project by mounting it on a WEBrick
|
||||||
|
# server:
|
||||||
|
#
|
||||||
|
# require 'webrick'
|
||||||
|
#
|
||||||
|
# server = WEBrick::HTTPServer.new Port: 8000
|
||||||
|
#
|
||||||
|
# server.mount '/', RDoc::Servlet
|
||||||
|
#
|
||||||
|
# If you want to mount the servlet some other place than the root, provide the
|
||||||
|
# base path when mounting:
|
||||||
|
#
|
||||||
|
# server.mount '/rdoc', RDoc::Servlet, '/rdoc'
|
||||||
|
|
||||||
class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
|
|
||||||
@server_stores = Hash.new { |hash, server| hash[server] = {} }
|
@server_stores = Hash.new { |hash, server| hash[server] = {} }
|
||||||
@cache = Hash.new { |hash, store| hash[store] = {} }
|
@cache = Hash.new { |hash, store| hash[store] = {} }
|
||||||
|
|
||||||
|
##
|
||||||
|
# Maps an asset type to its path on the filesystem
|
||||||
|
|
||||||
attr_reader :asset_dirs
|
attr_reader :asset_dirs
|
||||||
|
|
||||||
|
##
|
||||||
|
# An RDoc::Options instance used for rendering options
|
||||||
|
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
|
|
||||||
def self.get_instance server, *options
|
##
|
||||||
|
# Creates an instance of this servlet that shares cached data between
|
||||||
|
# requests.
|
||||||
|
|
||||||
|
def self.get_instance server, *options # :nodoc:
|
||||||
stores = @server_stores[server]
|
stores = @server_stores[server]
|
||||||
|
|
||||||
new server, stores, @cache, *options
|
new server, stores, @cache, *options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Creates a new WEBrick servlet.
|
||||||
|
#
|
||||||
|
# Use +mount_path+ when mounting the servlet somewhere other than /.
|
||||||
|
#
|
||||||
|
# +server+ is provided automatically by WEBrick when mounting. +stores+ and
|
||||||
|
# +cache+ are provided automatically by the servlet.
|
||||||
|
|
||||||
def initialize server, stores, cache, mount_path = nil
|
def initialize server, stores, cache, mount_path = nil
|
||||||
super server
|
super server
|
||||||
|
|
||||||
|
@ -44,6 +83,9 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Serves the asset at the path in +req+ for +generator_name+ via +res+.
|
||||||
|
|
||||||
def asset generator_name, req, res
|
def asset generator_name, req, res
|
||||||
asset_dir = @asset_dirs[generator_name]
|
asset_dir = @asset_dirs[generator_name]
|
||||||
|
|
||||||
|
@ -60,6 +102,9 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# GET request entry point. Fills in +res+ for the path, etc. in +req+.
|
||||||
|
|
||||||
def do_GET req, res
|
def do_GET req, res
|
||||||
req.path.sub!(/^#{Regexp.escape @mount_path}/o, '') if @mount_path
|
req.path.sub!(/^#{Regexp.escape @mount_path}/o, '') if @mount_path
|
||||||
|
|
||||||
|
@ -82,6 +127,13 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
error e, req, res
|
error e, req, res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Fills in +res+ with the class, module or page for +req+ from +store+.
|
||||||
|
#
|
||||||
|
# +path+ is relative to the mount_path and is used to determine the class,
|
||||||
|
# module or page name (/RDoc/Servlet.html becomes RDoc::Servlet).
|
||||||
|
# +generator+ is used to create the page.
|
||||||
|
|
||||||
def documentation_page store, generator, path, req, res
|
def documentation_page store, generator, path, req, res
|
||||||
name = path.sub(/.html$/, '').gsub '/', '::'
|
name = path.sub(/.html$/, '').gsub '/', '::'
|
||||||
|
|
||||||
|
@ -94,6 +146,10 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Creates the JSON search index on +res+ for the given +store+. +generator+
|
||||||
|
# must respond to \#json_index to build. +req+ is ignored.
|
||||||
|
|
||||||
def documentation_search store, generator, req, res
|
def documentation_search store, generator, req, res
|
||||||
json_index = @cache[store].fetch :json_index do
|
json_index = @cache[store].fetch :json_index do
|
||||||
@cache[store][:json_index] =
|
@cache[store][:json_index] =
|
||||||
|
@ -104,6 +160,10 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
res.body = "var search_data = #{json_index}"
|
res.body = "var search_data = #{json_index}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns the RDoc::Store and path relative to +mount_path+ for
|
||||||
|
# documentation at +path+.
|
||||||
|
|
||||||
def documentation_source path
|
def documentation_source path
|
||||||
_, source_name, path = path.split '/', 3
|
_, source_name, path = path.split '/', 3
|
||||||
|
|
||||||
|
@ -119,8 +179,11 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
return store, path
|
return store, path
|
||||||
end
|
end
|
||||||
|
|
||||||
def error e, req, res
|
##
|
||||||
backtrace = e.backtrace.join "\n"
|
# Generates an error page for the +exception+ while handling +req+ on +res+.
|
||||||
|
|
||||||
|
def error exception, req, res
|
||||||
|
backtrace = exception.backtrace.join "\n"
|
||||||
|
|
||||||
res.content_type = 'text/html'
|
res.content_type = 'text/html'
|
||||||
res.status = 500
|
res.status = 500
|
||||||
|
@ -130,7 +193,7 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||||
|
|
||||||
<title>Error - #{ERB::Util.html_escape e.class}</title>
|
<title>Error - #{ERB::Util.html_escape exception.class}</title>
|
||||||
|
|
||||||
<link type="text/css" media="screen" href="#{@mount_path}/rdoc.css" rel="stylesheet">
|
<link type="text/css" media="screen" href="#{@mount_path}/rdoc.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
@ -138,10 +201,17 @@ class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
<h1>Error</h1>
|
<h1>Error</h1>
|
||||||
|
|
||||||
<p>While processing <code>#{ERB::Util.html_escape req.request_uri}</code> the
|
<p>While processing <code>#{ERB::Util.html_escape req.request_uri}</code> the
|
||||||
RDoc server has encountered a <code>#{ERB::Util.html_escape e.class}</code>
|
RDoc (#{ERB::Util.html_escape RDoc::VERSION}) server has encountered a
|
||||||
|
<code>#{ERB::Util.html_escape exception.class}</code>
|
||||||
exception:
|
exception:
|
||||||
|
|
||||||
<pre>#{ERB::Util.html_escape e.message}</pre>
|
<pre>#{ERB::Util.html_escape exception.message}</pre>
|
||||||
|
|
||||||
|
<p>Please report this to the
|
||||||
|
<a href="https://github.com/rdoc/rdoc/issues">RDoc issues tracker</a>. Please
|
||||||
|
include the RDoc version, the URI above and exception class, message and
|
||||||
|
backtrace. If you're viewing a gem's documentation, include the gem name and
|
||||||
|
version. If you're viewing Ruby's documentation, include the version of ruby.
|
||||||
|
|
||||||
<p>Backtrace:
|
<p>Backtrace:
|
||||||
|
|
||||||
|
@ -152,6 +222,9 @@ exception:
|
||||||
BODY
|
BODY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Instantiates a Darkfish generator for +store+
|
||||||
|
|
||||||
def generator_for store
|
def generator_for store
|
||||||
generator = RDoc::Generator::Darkfish.new store, @options
|
generator = RDoc::Generator::Darkfish.new store, @options
|
||||||
generator.file_output = false
|
generator.file_output = false
|
||||||
|
@ -168,6 +241,11 @@ exception:
|
||||||
generator
|
generator
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Handles the If-Modified-Since HTTP header on +req+ for +path+. If the
|
||||||
|
# file has not been modified a Not Modified response is returned. If the
|
||||||
|
# file has been modified a Last-Modified header is added to +res+.
|
||||||
|
|
||||||
def if_modified_since req, res, path = nil
|
def if_modified_since req, res, path = nil
|
||||||
last_modified = File.stat(path).mtime if path
|
last_modified = File.stat(path).mtime if path
|
||||||
|
|
||||||
|
@ -183,6 +261,14 @@ exception:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns an Array of installed documentation.
|
||||||
|
#
|
||||||
|
# Each entry contains the documentation name (gem name, 'Ruby
|
||||||
|
# Documentation', etc.), the path relative to the mount point, whether the
|
||||||
|
# documentation exists, the type of documentation (See RDoc::RI::Paths#each)
|
||||||
|
# and the filesystem to the RDoc::Store for the documentation.
|
||||||
|
|
||||||
def installed_docs
|
def installed_docs
|
||||||
ri_paths.map do |path, type|
|
ri_paths.map do |path, type|
|
||||||
store = RDoc::Store.new path, type
|
store = RDoc::Store.new path, type
|
||||||
|
@ -202,15 +288,24 @@ exception:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns a 404 page built by +generator+ for +req+ on +res+.
|
||||||
|
|
||||||
def not_found generator, req, res
|
def not_found generator, req, res
|
||||||
res.body = generator.generate_servlet_not_found req.path
|
res.body = generator.generate_servlet_not_found req.path
|
||||||
res.status = 404
|
res.status = 404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Enumerates the ri paths. See RDoc::RI::Paths#each
|
||||||
|
|
||||||
def ri_paths &block
|
def ri_paths &block
|
||||||
RDoc::RI::Paths.each true, true, true, :all, &block
|
RDoc::RI::Paths.each true, true, true, :all, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Generates the root page on +res+. +req+ is ignored.
|
||||||
|
|
||||||
def root req, res
|
def root req, res
|
||||||
generator = RDoc::Generator::Darkfish.new nil, @options
|
generator = RDoc::Generator::Darkfish.new nil, @options
|
||||||
|
|
||||||
|
@ -219,6 +314,9 @@ exception:
|
||||||
res.content_type = 'text/html'
|
res.content_type = 'text/html'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Generates a search index for the root page on +res+. +req+ is ignored.
|
||||||
|
|
||||||
def root_search req, res
|
def root_search req, res
|
||||||
search_index = []
|
search_index = []
|
||||||
info = []
|
info = []
|
||||||
|
@ -259,6 +357,10 @@ exception:
|
||||||
res.content_type = 'application/javascript'
|
res.content_type = 'application/javascript'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Displays documentation for +req+ on +res+, whether that be HTML or some
|
||||||
|
# asset.
|
||||||
|
|
||||||
def show_documentation req, res
|
def show_documentation req, res
|
||||||
store, path = documentation_source req.path
|
store, path = documentation_source req.path
|
||||||
|
|
||||||
|
@ -280,6 +382,9 @@ exception:
|
||||||
res.content_type ||= 'text/html'
|
res.content_type ||= 'text/html'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns an RDoc::Store for the given +source_name+ ('ruby' or a gem name).
|
||||||
|
|
||||||
def store_for source_name
|
def store_for source_name
|
||||||
case source_name
|
case source_name
|
||||||
when 'ruby' then
|
when 'ruby' then
|
||||||
|
|
|
@ -59,7 +59,7 @@ class RDoc::Store
|
||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
|
|
||||||
def message
|
def message # :nodoc:
|
||||||
"store at #{@store.path} missing file #{@file} for #{@name}"
|
"store at #{@store.path} missing file #{@file} for #{@name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ call-seq:
|
||||||
comment = RDoc::Comment.new <<-COMMENT, @top_level
|
comment = RDoc::Comment.new <<-COMMENT, @top_level
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# bla => true or false
|
# bla => true or false
|
||||||
#\s
|
#
|
||||||
# moar comment
|
# moar comment
|
||||||
COMMENT
|
COMMENT
|
||||||
|
|
||||||
|
|
|
@ -80,23 +80,53 @@ class C; end
|
||||||
assert_equal 'A', name_t.text
|
assert_equal 'A', name_t.text
|
||||||
assert_equal 'A', given_name
|
assert_equal 'A', given_name
|
||||||
|
|
||||||
cont, name_t, given_name = util_parser('A::B') .get_class_or_module ctxt
|
cont, name_t, given_name = util_parser('B::C') .get_class_or_module ctxt
|
||||||
|
|
||||||
assert_equal @store.find_module_named('A'), cont
|
b = @store.find_module_named('B')
|
||||||
assert_equal 'B', name_t.text
|
assert_equal b, cont
|
||||||
assert_equal 'A::B', given_name
|
assert_equal [@top_level], b.in_files
|
||||||
|
assert_equal 'C', name_t.text
|
||||||
|
assert_equal 'B::C', given_name
|
||||||
|
|
||||||
cont, name_t, given_name = util_parser('A:: B').get_class_or_module ctxt
|
cont, name_t, given_name = util_parser('D:: E').get_class_or_module ctxt
|
||||||
|
|
||||||
assert_equal @store.find_module_named('A'), cont
|
assert_equal @store.find_module_named('D'), cont
|
||||||
assert_equal 'B', name_t.text
|
assert_equal 'E', name_t.text
|
||||||
assert_equal 'A::B', given_name
|
assert_equal 'D::E', given_name
|
||||||
|
|
||||||
assert_raises NoMethodError do
|
assert_raises NoMethodError do
|
||||||
util_parser("A::\nB").get_class_or_module ctxt
|
util_parser("A::\nB").get_class_or_module ctxt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_get_class_or_module_document_children
|
||||||
|
ctxt = @top_level.add_class RDoc::NormalClass, 'A'
|
||||||
|
ctxt.stop_doc
|
||||||
|
|
||||||
|
util_parser('B::C').get_class_or_module ctxt
|
||||||
|
|
||||||
|
b = @store.find_module_named('A::B')
|
||||||
|
assert b.ignored?
|
||||||
|
|
||||||
|
d = @top_level.add_class RDoc::NormalClass, 'A::D'
|
||||||
|
|
||||||
|
util_parser('D::E').get_class_or_module ctxt
|
||||||
|
|
||||||
|
refute d.ignored?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_get_class_or_module_ignore_constants
|
||||||
|
ctxt = RDoc::Context.new
|
||||||
|
ctxt.store = @store
|
||||||
|
|
||||||
|
util_parser('A') .get_class_or_module ctxt, true
|
||||||
|
util_parser('A::B').get_class_or_module ctxt, true
|
||||||
|
|
||||||
|
assert_empty ctxt.constants
|
||||||
|
assert_empty @store.modules_hash.keys
|
||||||
|
assert_empty @store.classes_hash.keys
|
||||||
|
end
|
||||||
|
|
||||||
def test_get_class_specification
|
def test_get_class_specification
|
||||||
assert_equal 'A', util_parser('A') .get_class_specification
|
assert_equal 'A', util_parser('A') .get_class_specification
|
||||||
assert_equal 'A::B', util_parser('A::B').get_class_specification
|
assert_equal 'A::B', util_parser('A::B').get_class_specification
|
||||||
|
@ -1108,6 +1138,37 @@ EOF
|
||||||
assert_equal 'A', bar.find_module_named('A').full_name
|
assert_equal 'A', bar.find_module_named('A').full_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parse_constant_in_method
|
||||||
|
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
||||||
|
|
||||||
|
util_parser 'A::B = v'
|
||||||
|
|
||||||
|
tk = @parser.get_tk
|
||||||
|
|
||||||
|
@parser.parse_constant klass, tk, @comment, true
|
||||||
|
|
||||||
|
assert_empty klass.constants
|
||||||
|
|
||||||
|
assert_empty @store.modules_hash.keys
|
||||||
|
assert_equal %w[Foo], @store.classes_hash.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parse_constant_rescue
|
||||||
|
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
||||||
|
|
||||||
|
util_parser "A => e"
|
||||||
|
|
||||||
|
tk = @parser.get_tk
|
||||||
|
|
||||||
|
@parser.parse_constant klass, tk, @comment
|
||||||
|
|
||||||
|
assert_empty klass.constants
|
||||||
|
assert_empty klass.modules
|
||||||
|
|
||||||
|
assert_empty @store.modules_hash.keys
|
||||||
|
assert_equal %w[Foo], @store.classes_hash.keys
|
||||||
|
end
|
||||||
|
|
||||||
def test_parse_constant_stopdoc
|
def test_parse_constant_stopdoc
|
||||||
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
||||||
klass.stop_doc
|
klass.stop_doc
|
||||||
|
@ -1121,6 +1182,27 @@ EOF
|
||||||
assert_empty klass.constants
|
assert_empty klass.constants
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parse_comment_nested
|
||||||
|
content = <<-CONTENT
|
||||||
|
A::B::C = 1
|
||||||
|
CONTENT
|
||||||
|
|
||||||
|
util_parser content
|
||||||
|
|
||||||
|
tk = @parser.get_tk
|
||||||
|
|
||||||
|
parsed = @parser.parse_constant @top_level, tk, 'comment'
|
||||||
|
|
||||||
|
assert parsed
|
||||||
|
|
||||||
|
a = @top_level.find_module_named 'A'
|
||||||
|
b = a.find_module_named 'B'
|
||||||
|
c = b.constants.first
|
||||||
|
|
||||||
|
assert_equal 'A::B::C', c.full_name
|
||||||
|
assert_equal 'comment', c.comment
|
||||||
|
end
|
||||||
|
|
||||||
def test_parse_include
|
def test_parse_include
|
||||||
klass = RDoc::NormalClass.new 'C'
|
klass = RDoc::NormalClass.new 'C'
|
||||||
klass.parent = @top_level
|
klass.parent = @top_level
|
||||||
|
@ -2585,6 +2667,61 @@ end
|
||||||
assert_equal 'A nice girl', m.comment.text
|
assert_equal 'A nice girl', m.comment.text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_scan_constant_in_method
|
||||||
|
content = <<-CONTENT # newline is after M is important
|
||||||
|
module M
|
||||||
|
def m
|
||||||
|
A
|
||||||
|
B::C
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CONTENT
|
||||||
|
|
||||||
|
util_parser content
|
||||||
|
|
||||||
|
@parser.scan
|
||||||
|
|
||||||
|
m = @top_level.modules.first
|
||||||
|
|
||||||
|
assert_empty m.constants
|
||||||
|
|
||||||
|
assert_empty @store.classes_hash.keys
|
||||||
|
assert_equal %w[M], @store.modules_hash.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_scan_constant_in_rescue
|
||||||
|
content = <<-CONTENT # newline is after M is important
|
||||||
|
module M
|
||||||
|
def m
|
||||||
|
rescue A::B
|
||||||
|
rescue A::C => e
|
||||||
|
rescue A::D, A::E
|
||||||
|
rescue A::F,
|
||||||
|
A::G
|
||||||
|
rescue H
|
||||||
|
rescue I => e
|
||||||
|
rescue J, K
|
||||||
|
rescue L =>
|
||||||
|
e
|
||||||
|
rescue M;
|
||||||
|
rescue N,
|
||||||
|
O => e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CONTENT
|
||||||
|
|
||||||
|
util_parser content
|
||||||
|
|
||||||
|
@parser.scan
|
||||||
|
|
||||||
|
m = @top_level.modules.first
|
||||||
|
|
||||||
|
assert_empty m.constants
|
||||||
|
|
||||||
|
assert_empty @store.classes_hash.keys
|
||||||
|
assert_equal %w[M], @store.modules_hash.keys
|
||||||
|
end
|
||||||
|
|
||||||
def test_scan_constant_nodoc
|
def test_scan_constant_nodoc
|
||||||
content = <<-CONTENT # newline is after M is important
|
content = <<-CONTENT # newline is after M is important
|
||||||
module M
|
module M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue