Permalink
Browse files

Added RDoc::Servlet which serves HTML from ri data

Use `rdoc --server` to launch the HTML server.  By default it runs on
port 8214, but this can be overridden by providing a port.  Support for
pages and live search are currently missing.

Added missing data to marshaled RDoc objects required for HTML
rendering.

Replaced RDoc::CodeObject#parent attribute with method for lookup from
loaded code objects.

RDoc::Context::Section now has multiple comments to allow merging and
updating with an ri data store.

RDoc::Markup::Document is now Enumerable.  This allows duck-typing when
merging comments in sections.

RDoc::Generator::Darkfish can now generate output directly to a String.

RDoc::Generator::Darkfish has been refactored to allow on-the-fly HTML
construction for classes.

Added RDoc::ERBPartial which allows ERB context reuse.
  • Loading branch information...
drbrain committed Oct 25, 2012
1 parent 6e3679d commit 4b50423ec36298d9dd75f05b6df31463db264508
View
@@ -135,10 +135,12 @@ def self.load_yaml
autoload :CrossReference, 'rdoc/cross_reference'
autoload :ERBIO, 'rdoc/erbio'
+ autoload :ERBPartial, 'rdoc/erb_partial'
autoload :Encoding, 'rdoc/encoding'
autoload :Generator, 'rdoc/generator'
autoload :Options, 'rdoc/options'
autoload :Parser, 'rdoc/parser'
+ autoload :Servlet, 'rdoc/servlet'
autoload :RI, 'rdoc/ri'
autoload :Stats, 'rdoc/stats'
autoload :Store, 'rdoc/store'
View
@@ -7,6 +7,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
# 2::
# RDoc 4
# Added calls_super
+ # Added parent name and class
+ # Added section title
MARSHAL_VERSION = 2 # :nodoc:
@@ -107,6 +109,9 @@ def marshal_dump
@params,
@file.absolute_name,
@calls_super,
+ @parent.name,
+ @parent.class,
+ @section.title,
]
end
@@ -117,36 +122,44 @@ def marshal_dump
# * #full_name
# * #parent_name
- def marshal_load(array)
+ def marshal_load array
@dont_rename_initialize = nil
@is_alias_for = nil
@token_stream = nil
@aliases = []
-
- version = array[0]
- @name = array[1]
- @full_name = array[2]
- @singleton = array[3]
- @visibility = array[4]
- @comment = array[5]
- @call_seq = array[6]
- @block_params = array[7]
- # 8 handled below
- @params = array[9]
- # 10 handled below
- @calls_super = array[11]
+ @parent = nil
+ @parent_name = nil
+ @parent_class = nil
+ @section = nil
+ @file = nil
+
+ version = array[0]
+ @name = array[1]
+ @full_name = array[2]
+ @singleton = array[3]
+ @visibility = array[4]
+ @comment = array[5]
+ @call_seq = array[6]
+ @block_params = array[7]
+ # 8 handled below
+ @params = array[9]
+ # 10 handled below
+ @calls_super = array[11]
+ @parent_name = array[12]
+ @parent_title = array[13]
+ @section_title = array[14]
array[8].each do |new_name, comment|
add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton)
end
- @parent_name = if @full_name =~ /#/ then
- $`
- else
- name = @full_name.split('::')
- name.pop
- name.join '::'
- end
+ @parent_name ||= if @full_name =~ /#/ then
+ $`
+ else
+ name = @full_name.split('::')
+ name.pop
+ name.join '::'
+ end
@file = RDoc::TopLevel.new array[10] if version > 0
end
@@ -219,6 +232,12 @@ def param_seq
params
end
+ def section # :nodoc:
+ return @section if @section
+
+ @section = parent.add_section @section_title if parent
+ end
+
##
# Sets the store for this method and its referenced code objects.
View
@@ -14,8 +14,13 @@ class RDoc::ClassModule < RDoc::Context
# 2::
# RDoc 3.13
# * Added extends
+ # 3::
+ # RDoc 4.0
+ # * Added sections
+ # * Added in_files
+ # * Added parent name
- MARSHAL_VERSION = 2 # :nodoc:
+ MARSHAL_VERSION = 3 # :nodoc:
##
# Constants that are aliases for this class or module
@@ -133,6 +138,17 @@ def add_comment comment, location
self.comment = original
end
+ def add_things my_things, other_things # :nodoc:
+ other_things.each do |group, things|
+ my_things[group].each { |thing| yield false, thing } if
+ my_things.include? group
+
+ things.each do |thing|
+ yield true, thing
+ end
+ end
+ end
+
##
# Ancestors list for this ClassModule: the list of included modules
# (classes will add their superclass if any).
@@ -241,8 +257,8 @@ def find_class_named name
# Return the fully qualified name of this class or module
def full_name
- @full_name ||= if RDoc::ClassModule === @parent then
- "#{@parent.full_name}::#{@name}"
+ @full_name ||= if RDoc::ClassModule === parent then
+ "#{parent.full_name}::#{@name}"
else
@name
end
@@ -285,7 +301,13 @@ def marshal_dump # :nodoc:
method_types,
extends.map do |ext|
[ext.name, parse(ext.comment), ext.file_name]
- end
+ end,
+ @sections.values,
+ @in_files.map do |tl|
+ tl.absolute_name
+ end,
+ parent.full_name,
+ parent.class,
]
end
@@ -297,6 +319,8 @@ def marshal_load array # :nodoc:
@parent = nil
@temporary_section = nil
@visibility = nil
+ @classes = {}
+ @modules = {}
@name = array[1]
@full_name = array[2]
@@ -347,6 +371,23 @@ def marshal_load array # :nodoc:
ext = add_extend RDoc::Extend.new(name, comment)
ext.record_location RDoc::TopLevel.new file
end if array[9] # Support Marshal version 1
+
+ sections = (array[10] || []).map do |section|
+ [section.title, section]
+ end
+
+ @sections = Hash[*sections.flatten]
+
+ add_section nil
+
+ @in_files = []
+
+ (array[11] || []).each do |filename|
+ record_location RDoc::TopLevel.new filename
+ end
+
+ @parent_name = array[12]
+ @parent_class = array[13]
end
##
@@ -415,6 +456,8 @@ def merge class_module
end
end
+ merge_sections cm
+
self
end
@@ -437,22 +480,46 @@ def merge_collections mine, other, other_files, &block # :nodoc:
my_things = mine. group_by { |thing| thing.file }
other_things = other.group_by { |thing| thing.file }
- my_things.delete_if do |file, things|
- next false unless other_files.include? file
+ remove_things my_things, other_files, &block
+ add_things my_things, other_things, &block
+ end
- things.each do |thing|
- yield false, thing
- end
+ ##
+ # Merges the comments in this ClassModule with the comments in the other
+ # ClassModule +cm+.
- true
+ def merge_sections cm # :nodoc:
+ my_sections = sections.group_by { |section| section.title }
+ other_sections = cm.sections.group_by { |section| section.title }
+
+ other_files = cm.in_files
+
+ remove_things my_sections, other_files do |_, section|
+ @sections.delete section.title
end
- other_things.each do |file, things|
- my_things[file].each { |thing| yield false, thing } if
- my_things.include?(file)
+ other_sections.each do |group, sections|
+ if my_sections.include? group
+ my_sections[group].each do |my_section|
+ other_section = cm.sections_hash[group]
- things.each do |thing|
- yield true, thing
+ my_comments = my_section.comments
+ other_comments = other_section.comments
+
+ other_files = other_section.in_files
+
+ merge_collections my_comments, other_comments, other_files do |add, comment|
+ if add then
+ my_section.add_comment comment
+ else
+ my_section.remove_comment comment
+ end
+ end
+ end
+ else
+ sections.each do |section|
+ add_section group, section.comments
+ end
end
end
end
@@ -547,6 +614,18 @@ def remove_nodoc_children
end
end
+ def remove_things my_things, other_files # :nodoc:
+ my_things.delete_if do |file, things|
+ next false unless other_files.include? file
+
+ things.each do |thing|
+ yield false, thing
+ end
+
+ true
+ end
+ end
+
##
# Search record used by RDoc::Generator::JsonIndex
View
@@ -75,9 +75,9 @@ class RDoc::CodeObject
attr_accessor :offset
##
- # Our parent CodeObject
+ # Sets the parent CodeObject
- attr_accessor :parent
+ attr_writer :parent
##
# Did we ever receive a +:nodoc:+ directive?
@@ -105,12 +105,16 @@ class RDoc::CodeObject
# Creates a new CodeObject that will document itself and its children
def initialize
- @metadata = {}
- @comment = ''
- @parent = nil
- @file = nil
- @full_name = nil
- @store = nil
+ @metadata = {}
+ @comment = ''
+ @parent = nil
+ @parent_name = nil # for loading
+ @parent_class = nil # for loading
+ @section = nil
+ @section_title = nil # for loading
+ @file = nil
+ @full_name = nil
+ @store = nil
@document_children = true
@document_self = true
@@ -132,7 +136,6 @@ def comment=(comment)
if comment and not comment.empty? then
normalize_comment comment
else
- # TODO is this sufficient?
# HACK correct fix is to have #initialize create @comment
# with the correct encoding
if String === @comment and
@@ -265,6 +268,28 @@ def ignored?
@ignored
end
+ ##
+ # Our parent CodeObject
+
+ def parent
+ return @parent if @parent
+ return nil unless @parent_name
+
+ if @parent_class == RDoc::TopLevel then
+ @parent = @store.add_file @parent_name
+ else
+ @parent = @store.find_class_or_module @parent_name
+
+ return @parent if @parent
+
+ begin
+ @parent = @store.load_class @parent_name
+ rescue RDoc::Store::MissingFileError
+ nil
+ end
+ end
+ end
+
##
# File name of our parent
View
@@ -22,6 +22,11 @@ class RDoc::Comment
attr_accessor :location
+ ##
+ # For duck-typing when merging classes at load time
+
+ alias file location # :nodoc:
+
##
# The text for this comment
@@ -143,7 +148,9 @@ def format= format
end
def inspect # :nodoc:
- "#<%s:%x %s %p>" % [self.class, object_id, @location.absolute_name, @text]
+ location = @location ? @location.absolute_name : '(unknown)'
+
+ "#<%s:%x %s %p>" % [self.class, object_id, location, @text]
end
##
Oops, something went wrong.

0 comments on commit 4b50423

Please sign in to comment.