diff --git a/doc/rdoc/markup_reference.rb b/doc/rdoc/markup_reference.rb index 5b5cdfc706..ee585b2497 100644 --- a/doc/rdoc/markup_reference.rb +++ b/doc/rdoc/markup_reference.rb @@ -859,6 +859,15 @@ require 'rdoc' # - On-page: DummyClass links to DummyClass. # - Off-page: RDoc::Alias links to RDoc::Alias. # +# Note: For poeple want to mark up code (such as class, module, +# constant, and method) as "+code+" (for interoperability +# with other MarkDown parsers mainly), such word that refers a known +# code object and is marked up entirely and separately as "monofont" +# is also converted to a link. +# +# - +DummyClass+ links to DummyClass +# - +DummyClass-object+ is not a link. +# # [Module] # # - On-page: DummyModule links to DummyModule. @@ -987,8 +996,7 @@ require 'rdoc' # and entire rdoc-ref: square-bracketed clause is removed # from the resulting text. # -# - Nosuch[rdoc-ref:RDoc::Nosuch] generates -# Nosuch[rdoc-ref:RDoc::Nosuch]. +# - Nosuch[rdoc-ref:RDoc::Nosuch] generates Nosuch. # # # [rdoc-label Scheme] diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb index 83997c2580..388863b06c 100644 --- a/lib/rdoc/code_object.rb +++ b/lib/rdoc/code_object.rb @@ -21,9 +21,10 @@ # * RDoc::MetaMethod # * RDoc::Alias # * RDoc::Constant +# * RDoc::Require # * RDoc::Mixin -# * RDoc::Require # * RDoc::Include +# * RDoc::Extend class RDoc::CodeObject @@ -89,13 +90,6 @@ class RDoc::CodeObject attr_reader :store - ## - # We are the model of the code, but we know that at some point we will be - # worked on by viewers. By implementing the Viewable protocol, viewers can - # associated themselves with these objects. - - attr_accessor :viewer - ## # When mixed-in to a class, this points to the Context in which it was originally defined. @@ -141,7 +135,6 @@ class RDoc::CodeObject def comment=(comment) @comment = case comment when NilClass then '' - when RDoc::Markup::Document then comment when RDoc::Comment then comment.normalize else if comment and not comment.empty? then @@ -217,20 +210,6 @@ class RDoc::CodeObject @document_children = @document_self end - ## - # Yields each parent of this CodeObject. See also - # RDoc::ClassModule#each_ancestor - - def each_parent - code_object = self - - while code_object = code_object.parent do - yield code_object - end - - self - end - ## # File name where this CodeObject was found. # @@ -257,7 +236,7 @@ class RDoc::CodeObject # # Set to +nil+ to clear RDoc's cached value - def full_name= full_name + def full_name=(full_name) @full_name = full_name end @@ -301,11 +280,7 @@ class RDoc::CodeObject # This is used by Text#snippet def options - if @store and @store.rdoc then - @store.rdoc.options - else - RDoc::Options.new - end + @store&.options || RDoc::Options.new end ## @@ -331,13 +306,6 @@ class RDoc::CodeObject end end - ## - # File name of our parent - - def parent_file_name - @parent ? @parent.base_name : '(unknown)' - end - ## # Name of our parent @@ -348,7 +316,7 @@ class RDoc::CodeObject ## # Records the RDoc::TopLevel (file) where this code object was defined - def record_location top_level + def record_location(top_level) @ignored = false @suppressed = false @file = top_level @@ -390,7 +358,7 @@ class RDoc::CodeObject ## # Sets the +store+ that contains this CodeObject - def store= store + def store=(store) @store = store return unless @track_visibility diff --git a/lib/rdoc/code_object/alias.rb b/lib/rdoc/code_object/alias.rb index 92df7e448f..bd5b3ec6b5 100644 --- a/lib/rdoc/code_object/alias.rb +++ b/lib/rdoc/code_object/alias.rb @@ -23,7 +23,7 @@ class RDoc::Alias < RDoc::CodeObject ## # Is this an alias declared in a singleton context? - attr_accessor :singleton + attr_reader :singleton ## # Source file token stream @@ -34,7 +34,7 @@ class RDoc::Alias < RDoc::CodeObject # Creates a new Alias with a token stream of +text+ that aliases +old_name+ # to +new_name+, has +comment+ and is a +singleton+ context. - def initialize(text, old_name, new_name, comment, singleton = false) + def initialize(text, old_name, new_name, comment, singleton: false) super() @text = text @@ -59,13 +59,6 @@ class RDoc::Alias < RDoc::CodeObject "#alias-#{type}-#{html_name}" end - ## - # Full old name including namespace - - def full_old_name - @full_name || "#{parent.name}#{pretty_old_name}" - end - ## # HTML id-friendly version of +#new_name+. diff --git a/lib/rdoc/code_object/any_method.rb b/lib/rdoc/code_object/any_method.rb index 465c4a4fb2..b319f0d0dd 100644 --- a/lib/rdoc/code_object/any_method.rb +++ b/lib/rdoc/code_object/any_method.rb @@ -29,10 +29,6 @@ class RDoc::AnyMethod < RDoc::MethodAttr # The section title of the method (if defined in a C file via +:category:+) attr_accessor :section_title - # Parameters for this method - - attr_accessor :params - ## # If true this method uses +super+ to call a superclass version @@ -43,8 +39,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr ## # Creates a new AnyMethod with a token stream +text+ and +name+ - def initialize text, name - super + def initialize(text, name, singleton: false) + super(text, name, singleton: singleton) @c_function = nil @dont_rename_initialize = false @@ -56,11 +52,10 @@ class RDoc::AnyMethod < RDoc::MethodAttr ## # Adds +an_alias+ as an alias for this method in +context+. - def add_alias an_alias, context = nil - method = self.class.new an_alias.text, an_alias.new_name + def add_alias(an_alias, context = nil) + method = self.class.new an_alias.text, an_alias.new_name, singleton: singleton method.record_location an_alias.file - method.singleton = self.singleton method.params = self.params method.visibility = self.visibility method.comment = an_alias.comment @@ -109,8 +104,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr # # See also #param_seq - def call_seq= call_seq - return if call_seq.empty? + def call_seq=(call_seq) + return if call_seq.nil? || call_seq.empty? @call_seq = call_seq end @@ -181,7 +176,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr # * #full_name # * #parent_name - def marshal_load array + def marshal_load(array) initialize_visibility @dont_rename_initialize = nil @@ -198,7 +193,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr @full_name = array[2] @singleton = array[3] @visibility = array[4] - @comment = array[5] + @comment = RDoc::Comment.from_document array[5] @call_seq = array[6] @block_params = array[7] # 8 handled below @@ -210,8 +205,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr @section_title = array[14] @is_alias_for = array[15] - array[8].each do |new_name, comment| - add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton) + array[8].each do |new_name, document| + add_alias RDoc::Alias.new(nil, @name, new_name, RDoc::Comment.from_document(document), singleton: @singleton) end @parent_name ||= if @full_name =~ /#/ then @@ -314,7 +309,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr ## # Sets the store for this method and its referenced code objects. - def store= store + def store=(store) super @file = @store.add_file @file.full_name if @file diff --git a/lib/rdoc/code_object/attr.rb b/lib/rdoc/code_object/attr.rb index a403235933..969b18346d 100644 --- a/lib/rdoc/code_object/attr.rb +++ b/lib/rdoc/code_object/attr.rb @@ -22,18 +22,17 @@ class RDoc::Attr < RDoc::MethodAttr # Creates a new Attr with body +text+, +name+, read/write status +rw+ and # +comment+. +singleton+ marks this as a class attribute. - def initialize(text, name, rw, comment, singleton = false) - super text, name + def initialize(text, name, rw, comment, singleton: false) + super(text, name, singleton: singleton) @rw = rw - @singleton = singleton self.comment = comment end ## # Attributes are equal when their names, singleton and rw are identical - def == other + def ==(other) self.class == other.class and self.name == other.name and self.rw == other.rw and @@ -44,9 +43,7 @@ class RDoc::Attr < RDoc::MethodAttr # Add +an_alias+ as an attribute in +context+. def add_alias(an_alias, context) - new_attr = self.class.new(self.text, an_alias.new_name, self.rw, - self.comment, self.singleton) - + new_attr = self.class.new(text, an_alias.new_name, rw, comment, singleton: singleton) new_attr.record_location an_alias.file new_attr.visibility = self.visibility new_attr.is_alias_for = self @@ -121,7 +118,7 @@ class RDoc::Attr < RDoc::MethodAttr # * #full_name # * #parent_name - def marshal_load array + def marshal_load(array) initialize_visibility @aliases = [] @@ -136,7 +133,7 @@ class RDoc::Attr < RDoc::MethodAttr @full_name = array[2] @rw = array[3] @visibility = array[4] - @comment = array[5] + @comment = RDoc::Comment.from_document array[5] @singleton = array[6] || false # MARSHAL_VERSION == 0 # 7 handled below @parent_name = array[8] @@ -148,7 +145,7 @@ class RDoc::Attr < RDoc::MethodAttr @parent_name ||= @full_name.split('#', 2).first end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, "[#{self.class.name} #{full_name} #{rw} #{visibility}", "]" do unless comment.empty? then q.breakable diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index 33e71ab3f3..f6b0abb2f5 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -34,8 +34,6 @@ class RDoc::ClassModule < RDoc::Context attr_accessor :comment_location - attr_accessor :diagram # :nodoc: - ## # Class or module this constant is an alias for @@ -47,7 +45,7 @@ class RDoc::ClassModule < RDoc::Context #-- # TODO move to RDoc::NormalClass (I think) - def self.from_module class_type, mod + def self.from_module(class_type, mod) klass = class_type.new mod.name mod.comment_location.each do |comment, location| @@ -56,7 +54,6 @@ class RDoc::ClassModule < RDoc::Context klass.parent = mod.parent klass.section = mod.section - klass.viewer = mod.viewer klass.attributes.concat mod.attributes klass.method_list.concat mod.method_list @@ -110,7 +107,6 @@ class RDoc::ClassModule < RDoc::Context def initialize(name, superclass = nil) @constant_aliases = [] - @diagram = nil @is_alias_for = nil @name = name @superclass = superclass @@ -124,7 +120,7 @@ class RDoc::ClassModule < RDoc::Context # method is preferred over #comment= since it allows ri data to be updated # across multiple runs. - def add_comment comment, location + def add_comment(comment, location) return unless document_self original = comment @@ -145,7 +141,7 @@ class RDoc::ClassModule < RDoc::Context self.comment = original end - def add_things my_things, other_things # :nodoc: + 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 @@ -202,7 +198,7 @@ class RDoc::ClassModule < RDoc::Context # Appends +comment+ to the current comment, but separated by a rule. Works # more like +=. - def comment= comment # :nodoc: + def comment=(comment) # :nodoc: comment = case comment when RDoc::Comment then comment.normalize @@ -220,11 +216,12 @@ class RDoc::ClassModule < RDoc::Context # # See RDoc::Store#complete - def complete min_visibility + def complete(min_visibility) update_aliases remove_nodoc_children embed_mixins update_includes + update_extends remove_invisible min_visibility end @@ -262,7 +259,7 @@ class RDoc::ClassModule < RDoc::Context ## # Looks for a symbol in the #ancestors. See Context#find_local_symbol. - def find_ancestor_local_symbol symbol + def find_ancestor_local_symbol(symbol) each_ancestor do |m| res = m.find_local_symbol(symbol) return res if res @@ -274,7 +271,7 @@ class RDoc::ClassModule < RDoc::Context ## # Finds a class or module with +name+ in this namespace or its descendants - def find_class_named name + def find_class_named(name) return self if full_name == name return self if @name == name @@ -295,6 +292,25 @@ class RDoc::ClassModule < RDoc::Context end end + ## + # Return array of full_name splitted by +::+. + + def nesting_namespaces + @namespaces ||= full_name.split("::").reject(&:empty?) + end + + ## + # Return array of fully qualified nesting namespaces. + # + # For example, if full_name is +A::B::C+, this method returns ["A", "A::B", "A::B::C"] + + def fully_qualified_nesting_namespaces + return nesting_namespaces if nesting_namespaces.length < 2 + @fqns ||= nesting_namespaces.inject([]) do |list, n| + list << (list.empty? ? n : "#{list.last}::#{n}") + end + end + ## # TODO: filter included items by #display? @@ -344,7 +360,7 @@ class RDoc::ClassModule < RDoc::Context ] end - def marshal_load array # :nodoc: + def marshal_load(array) # :nodoc: initialize_visibility initialize_methods_etc @current_section = nil @@ -359,37 +375,39 @@ class RDoc::ClassModule < RDoc::Context @name = array[1] @full_name = array[2] @superclass = array[3] - @comment = array[4] + document = array[4] - @comment_location = if RDoc::Markup::Document === @comment.parts.first then - @comment + @comment = RDoc::Comment.from_document document + + @comment_location = if RDoc::Markup::Document === document.parts.first then + document else - RDoc::Markup::Document.new @comment + RDoc::Markup::Document.new document end array[5].each do |name, rw, visibility, singleton, file| singleton ||= false visibility ||= :public - attr = RDoc::Attr.new nil, name, rw, nil, singleton + attr = RDoc::Attr.new nil, name, rw, nil, singleton: singleton add_attribute attr attr.visibility = visibility attr.record_location RDoc::TopLevel.new file end - array[6].each do |constant, comment, file| + array[6].each do |constant, document, file| case constant when RDoc::Constant then add_constant constant else - constant = add_constant RDoc::Constant.new(constant, nil, comment) + constant = add_constant RDoc::Constant.new(constant, nil, RDoc::Comment.from_document(document)) constant.record_location RDoc::TopLevel.new file end end - array[7].each do |name, comment, file| - incl = add_include RDoc::Include.new(name, comment) + array[7].each do |name, document, file| + incl = add_include RDoc::Include.new(name, RDoc::Comment.from_document(document)) incl.record_location RDoc::TopLevel.new file end @@ -398,16 +416,15 @@ class RDoc::ClassModule < RDoc::Context @visibility = visibility methods.each do |name, file| - method = RDoc::AnyMethod.new nil, name - method.singleton = true if type == 'class' + method = RDoc::AnyMethod.new nil, name, singleton: type == 'class' method.record_location RDoc::TopLevel.new file add_method method end end end - array[9].each do |name, comment, file| - ext = add_extend RDoc::Extend.new(name, comment) + array[9].each do |name, document, file| + ext = add_extend RDoc::Extend.new(name, RDoc::Comment.from_document(document)) ext.record_location RDoc::TopLevel.new file end if array[9] # Support Marshal version 1 @@ -433,7 +450,7 @@ class RDoc::ClassModule < RDoc::Context # # The data in +class_module+ is preferred over the receiver. - def merge class_module + def merge(class_module) @parent = class_module.parent @parent_name = class_module.parent_name @@ -444,7 +461,8 @@ class RDoc::ClassModule < RDoc::Context document = document.merge other_document - @comment = @comment_location = document + @comment = RDoc::Comment.from_document(document) + @comment_location = document end cm = class_module @@ -517,7 +535,7 @@ class RDoc::ClassModule < RDoc::Context # end # end - def merge_collections mine, other, other_files, &block # :nodoc: + 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 } @@ -529,7 +547,7 @@ class RDoc::ClassModule < RDoc::Context # Merges the comments in this ClassModule with the comments in the other # ClassModule +cm+. - def merge_sections cm # :nodoc: + def merge_sections(cm) # :nodoc: my_sections = sections.group_by { |section| section.title } other_sections = cm.sections.group_by { |section| section.title } @@ -577,7 +595,7 @@ class RDoc::ClassModule < RDoc::Context # # Used for modules and classes that are constant aliases. - def name= new_name + def name=(new_name) @name = new_name end @@ -585,7 +603,7 @@ class RDoc::ClassModule < RDoc::Context # Parses +comment_location+ into an RDoc::Markup::Document composed of # multiple RDoc::Markup::Documents with their file set. - def parse comment_location + def parse(comment_location) case comment_location when String then super @@ -612,7 +630,9 @@ class RDoc::ClassModule < RDoc::Context # Path to this class or module for use with HTML generator output. def path - http_url @store.rdoc.generator.class_dir + prefix = options.class_module_path_prefix + return http_url unless prefix + File.join(prefix, http_url) end ## @@ -655,7 +675,7 @@ class RDoc::ClassModule < RDoc::Context end end - def remove_things my_things, other_files # :nodoc: + def remove_things(my_things, other_files) # :nodoc: my_things.delete_if do |file, things| next false unless other_files.include? file @@ -685,7 +705,7 @@ class RDoc::ClassModule < RDoc::Context ## # Sets the store for this class or module and its contained code objects. - def store= store + def store=(store) super @attributes .each do |attr| attr.store = store end diff --git a/lib/rdoc/code_object/constant.rb b/lib/rdoc/code_object/constant.rb index 12b8be775c..d5f54edb67 100644 --- a/lib/rdoc/code_object/constant.rb +++ b/lib/rdoc/code_object/constant.rb @@ -44,7 +44,7 @@ class RDoc::Constant < RDoc::CodeObject ## # Constants are ordered by name - def <=> other + def <=>(other) return unless self.class === other [parent_name, name] <=> [other.parent_name, other.name] @@ -53,7 +53,7 @@ class RDoc::Constant < RDoc::CodeObject ## # Constants are equal when their #parent and #name is the same - def == other + def ==(other) self.class == other.class and @parent == other.parent and @name == other.name @@ -132,8 +132,8 @@ class RDoc::Constant < RDoc::CodeObject # * #full_name # * #parent_name - def marshal_load array - initialize array[1], nil, array[5] + def marshal_load(array) + initialize array[1], nil, RDoc::Comment.from_document(array[5]) @full_name = array[2] @visibility = array[3] || :public @@ -154,7 +154,7 @@ class RDoc::Constant < RDoc::CodeObject "#{@parent.path}##{@name}" end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, "[#{self.class.name} #{full_name}", "]" do unless comment.empty? then q.breakable @@ -168,7 +168,7 @@ class RDoc::Constant < RDoc::CodeObject ## # Sets the store for this class or module and its contained code objects. - def store= store + def store=(store) super @file = @store.add_file @file.full_name if @file diff --git a/lib/rdoc/code_object/context.rb b/lib/rdoc/code_object/context.rb index c688d562c3..3a4dd0ec68 100644 --- a/lib/rdoc/code_object/context.rb +++ b/lib/rdoc/code_object/context.rb @@ -180,7 +180,7 @@ class RDoc::Context < RDoc::CodeObject # # Currently only RDoc::Extend and RDoc::Include are supported. - def add klass, name, comment + def add(klass, name, comment) if RDoc::Extend == klass then ext = RDoc::Extend.new name, comment add_extend ext @@ -195,7 +195,7 @@ class RDoc::Context < RDoc::CodeObject ## # Adds +an_alias+ that is automatically resolved - def add_alias an_alias + def add_alias(an_alias) return an_alias unless @document_self method_attr = find_method(an_alias.old_name, an_alias.singleton) || @@ -222,7 +222,7 @@ class RDoc::Context < RDoc::CodeObject # if method +foo+ exists, but attr_accessor :foo will be registered # if method +foo+ exists, but foo= does not. - def add_attribute attribute + def add_attribute(attribute) return attribute unless @document_self # mainly to check for redefinition of an attribute as a method @@ -285,7 +285,7 @@ class RDoc::Context < RDoc::CodeObject # unless it later sees class Container. +add_class+ automatically # upgrades +given_name+ to a class in this case. - def add_class class_type, given_name, superclass = '::Object' + def add_class(class_type, given_name, superclass = '::Object') # superclass +nil+ is passed by the C parser in the following cases: # - registering Object in 1.8 (correct) # - registering BasicObject in 1.9 (correct) @@ -401,7 +401,7 @@ class RDoc::Context < RDoc::CodeObject # unless #done_documenting is +true+. Sets the #parent of +mod+ # to +self+, and its #section to #current_section. Returns +mod+. - def add_class_or_module mod, self_hash, all_hash + def add_class_or_module(mod, self_hash, all_hash) mod.section = current_section # TODO declaring context? something is # wrong here... mod.parent = self @@ -426,7 +426,7 @@ class RDoc::Context < RDoc::CodeObject # Adds +constant+ if not already there. If it is, updates the comment, # value and/or is_alias_for of the known constant if they were empty/nil. - def add_constant constant + def add_constant(constant) return constant unless @document_self # HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code) @@ -451,7 +451,7 @@ class RDoc::Context < RDoc::CodeObject ## # Adds included module +include+ which should be an RDoc::Include - def add_include include + def add_include(include) add_to @includes, include include @@ -460,7 +460,7 @@ class RDoc::Context < RDoc::CodeObject ## # Adds extension module +ext+ which should be an RDoc::Extend - def add_extend ext + def add_extend(ext) add_to @extends, ext ext @@ -470,7 +470,7 @@ class RDoc::Context < RDoc::CodeObject # Adds +method+ if not already there. If it is (as method or attribute), # updates the comment if it was empty. - def add_method method + def add_method(method) return method unless @document_self # HACK: avoid duplicate 'new' in io.c & struct.c (1.8.7 source code) @@ -482,7 +482,7 @@ class RDoc::Context < RDoc::CodeObject known.comment = method.comment if known.comment.empty? previously = ", previously in #{known.file}" unless method.file == known.file - @store.rdoc.options.warn \ + @store.options.warn \ "Duplicate method #{known.full_name} in #{method.file}#{previously}" end else @@ -524,7 +524,7 @@ class RDoc::Context < RDoc::CodeObject # Adds an alias from +from+ (a class or module) to +name+ which was defined # in +file+. - def add_module_alias from, from_name, to, file + def add_module_alias(from, from_name, to, file) return from if @done_documenting to_full_name = child_name to.name @@ -583,7 +583,7 @@ class RDoc::Context < RDoc::CodeObject # # See also RDoc::Context::Section - def add_section title, comment = nil + def add_section(title, comment = nil) if section = @sections[title] then section.add_comment comment if comment else @@ -597,7 +597,7 @@ class RDoc::Context < RDoc::CodeObject ## # Adds +thing+ to the collection +array+ - def add_to array, thing + def add_to(array, thing) array << thing if @document_self thing.parent = self @@ -629,7 +629,7 @@ class RDoc::Context < RDoc::CodeObject ## # Creates the full name for a child with +name+ - def child_name name + def child_name(name) if name =~ /^:+/ $' #' elsif RDoc::TopLevel === self then @@ -688,13 +688,6 @@ class RDoc::Context < RDoc::CodeObject section end - ## - # Is part of this thing was defined in +file+? - - def defined_in?(file) - @in_files.include?(file) - end - def display(method_attr) # :nodoc: if method_attr.is_a? RDoc::Attr "#{method_attr.definition} #{method_attr.pretty_name}" @@ -713,13 +706,6 @@ class RDoc::Context < RDoc::CodeObject def each_ancestor(&_) # :nodoc: end - ## - # Iterator for attributes - - def each_attribute # :yields: attribute - @attributes.each { |a| yield a } - end - ## # Iterator for classes and modules @@ -727,27 +713,6 @@ class RDoc::Context < RDoc::CodeObject classes_and_modules.sort.each(&block) end - ## - # Iterator for constants - - def each_constant # :yields: constant - @constants.each {|c| yield c} - end - - ## - # Iterator for included modules - - def each_include # :yields: include - @includes.each do |i| yield i end - end - - ## - # Iterator for extension modules - - def each_extend # :yields: extend - @extends.each do |e| yield e end - end - ## # Iterator for methods @@ -847,13 +812,6 @@ class RDoc::Context < RDoc::CodeObject end end - ## - # Finds a file with +name+ in this context - - def find_file_named name - @store.find_file_named name - end - ## # Finds an instance method with +name+ in this context @@ -871,7 +829,7 @@ class RDoc::Context < RDoc::CodeObject find_attribute_named(symbol) or find_external_alias_named(symbol) or find_module_named(symbol) or - find_file_named(symbol) + @store.find_file_named(symbol) end ## @@ -973,10 +931,10 @@ class RDoc::Context < RDoc::CodeObject ## # URL for this with a +prefix+ - def http_url(prefix) + def http_url path = name_for_path path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /< other + def <=>(other) return unless self.class === other name <=> other.name end - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and @name == other.name end @@ -107,7 +107,7 @@ class RDoc::Mixin < RDoc::CodeObject ## # Sets the store for this class or module and its contained code objects. - def store= store + def store=(store) super @file = @store.add_file @file.full_name if @file diff --git a/lib/rdoc/code_object/normal_class.rb b/lib/rdoc/code_object/normal_class.rb index aa340b5d15..6b68d6db56 100644 --- a/lib/rdoc/code_object/normal_class.rb +++ b/lib/rdoc/code_object/normal_class.rb @@ -53,7 +53,7 @@ class RDoc::NormalClass < RDoc::ClassModule display end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: superclass = @superclass ? " < #{@superclass}" : nil q.group 2, "[class #{full_name}#{superclass}", "]" do diff --git a/lib/rdoc/code_object/normal_module.rb b/lib/rdoc/code_object/normal_module.rb index 498ec4dde2..677a9dc3bd 100644 --- a/lib/rdoc/code_object/normal_module.rb +++ b/lib/rdoc/code_object/normal_module.rb @@ -29,7 +29,7 @@ class RDoc::NormalModule < RDoc::ClassModule true end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, "[module #{full_name}:", "]" do q.breakable q.text "includes:" diff --git a/lib/rdoc/code_object/require.rb b/lib/rdoc/code_object/require.rb index 05e26b84b0..f47e3b1534 100644 --- a/lib/rdoc/code_object/require.rb +++ b/lib/rdoc/code_object/require.rb @@ -24,7 +24,7 @@ class RDoc::Require < RDoc::CodeObject self.class, object_id, @name, - parent_file_name, + @parent ? @parent.base_name : '(unknown)' ] end diff --git a/lib/rdoc/code_object/single_class.rb b/lib/rdoc/code_object/single_class.rb index dd16529648..88a93a0c5f 100644 --- a/lib/rdoc/code_object/single_class.rb +++ b/lib/rdoc/code_object/single_class.rb @@ -22,7 +22,7 @@ class RDoc::SingleClass < RDoc::ClassModule "class << #{full_name}" end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, "[class << #{full_name}", "]" do next end diff --git a/lib/rdoc/code_object/top_level.rb b/lib/rdoc/code_object/top_level.rb index b93e3802fc..eeeff026a1 100644 --- a/lib/rdoc/code_object/top_level.rb +++ b/lib/rdoc/code_object/top_level.rb @@ -6,11 +6,6 @@ class RDoc::TopLevel < RDoc::Context MARSHAL_VERSION = 0 # :nodoc: - ## - # This TopLevel's File::Stat struct - - attr_accessor :file_stat - ## # Relative name of this file @@ -28,8 +23,6 @@ class RDoc::TopLevel < RDoc::Context attr_reader :classes_or_modules - attr_accessor :diagram # :nodoc: - ## # The parser class that processed this file @@ -40,13 +33,11 @@ class RDoc::TopLevel < RDoc::Context # is being generated outside the source dir +relative_name+ is relative to # the source directory. - def initialize absolute_name, relative_name = absolute_name + def initialize(absolute_name, relative_name = absolute_name) super() @name = nil @absolute_name = absolute_name @relative_name = relative_name - @file_stat = File.stat(absolute_name) rescue nil # HACK for testing - @diagram = nil @parser = nil @classes_or_modules = [] @@ -64,7 +55,7 @@ class RDoc::TopLevel < RDoc::Context ## # An RDoc::TopLevel is equal to another with the same relative_name - def == other + def ==(other) self.class === other and @relative_name == other.relative_name end @@ -82,7 +73,7 @@ class RDoc::TopLevel < RDoc::Context ## # Adds +constant+ to +Object+ instead of +self+. - def add_constant constant + def add_constant(constant) object_class.record_location self return constant unless @document_self object_class.add_constant constant @@ -110,7 +101,7 @@ class RDoc::TopLevel < RDoc::Context # Adds class or module +mod+. Used in the building phase # by the Ruby parser. - def add_to_classes_or_modules mod + def add_to_classes_or_modules(mod) @classes_or_modules << mod end @@ -137,7 +128,7 @@ class RDoc::TopLevel < RDoc::Context # TODO Why do we search through all classes/modules found, not just the # ones of this instance? - def find_class_or_module name + def find_class_or_module(name) @store.find_class_or_module name end @@ -173,10 +164,8 @@ class RDoc::TopLevel < RDoc::Context ## # URL for this with a +prefix+ - def http_url(prefix) - path = [prefix, @relative_name.tr('.', '_')] - - File.join(*path.compact) + '.html' + def http_url + @relative_name.tr('.', '_') + '.html' end def inspect # :nodoc: @@ -188,13 +177,6 @@ class RDoc::TopLevel < RDoc::Context ] end - ## - # Time this file was last modified, if known - - def last_modified - @file_stat ? file_stat.mtime : nil - end - ## # Dumps this TopLevel for use by ri. See also #marshal_load @@ -210,13 +192,11 @@ class RDoc::TopLevel < RDoc::Context ## # Loads this TopLevel from +array+. - def marshal_load array # :nodoc: + def marshal_load(array) # :nodoc: initialize array[1] @parser = array[2] - @comment = array[3] - - @file_stat = nil + @comment = RDoc::Comment.from_document array[3] end ## @@ -246,10 +226,12 @@ class RDoc::TopLevel < RDoc::Context # Path to this file for use with HTML generator output. def path - http_url @store.rdoc.generator.file_dir + prefix = options.file_path_prefix + return http_url unless prefix + File.join(prefix, http_url) end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, "[#{self.class}: ", "]" do q.text "base name: #{base_name.inspect}" q.breakable diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb index 04ec226436..b269ec4845 100644 --- a/lib/rdoc/comment.rb +++ b/lib/rdoc/comment.rb @@ -53,7 +53,7 @@ class RDoc::Comment # Creates a new comment with +text+ that is found in the RDoc::TopLevel # +location+. - def initialize text = nil, location = nil, language = nil + def initialize(text = nil, location = nil, language = nil) @location = location @text = text.nil? ? nil : text.dup @language = language @@ -67,11 +67,11 @@ class RDoc::Comment #-- # TODO deep copy @document - def initialize_copy copy # :nodoc: + def initialize_copy(copy) # :nodoc: @text = copy.text.dup end - def == other # :nodoc: + def ==(other) # :nodoc: self.class === other and other.text == @text and other.location == @location end @@ -92,7 +92,7 @@ class RDoc::Comment # # ARGF.to_a(limit) -> array # # ARGF.to_a(sep, limit) -> array - def extract_call_seq method + def extract_call_seq # we must handle situations like the above followed by an unindented first # comment. The difficulty is to make sure not to match lines starting # with ARGF at the same indent, but that are after the first description @@ -116,23 +116,20 @@ class RDoc::Comment @text.slice! all_start...all_stop seq.gsub!(/^\s*/, '') - method.call_seq = seq end - - method end ## # A comment is empty if its text String is empty. def empty? - @text.empty? + @text.empty? && (@document.nil? || @document.empty?) end ## # HACK dubious - def encode! encoding + def encode!(encoding) @text = String.new @text, encoding: encoding self end @@ -140,7 +137,7 @@ class RDoc::Comment ## # Sets the format of this comment and resets any parsed document - def format= format + def format=(format) @format = format @document = nil end @@ -211,7 +208,7 @@ class RDoc::Comment # # An error is raised if the comment contains a document but no text. - def text= text + def text=(text) raise RDoc::Error, 'replacing document-only comment is not allowed' if @text.nil? and @document @@ -226,4 +223,14 @@ class RDoc::Comment @format == 'tomdoc' end + ## + # Create a new parsed comment from a document + + def self.from_document(document) # :nodoc: + comment = RDoc::Comment.new('') + comment.document = document + comment.location = RDoc::TopLevel.new(document.file) if document.file + comment + end + end diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb index 4e011219e8..a942d33c96 100644 --- a/lib/rdoc/cross_reference.rb +++ b/lib/rdoc/cross_reference.rb @@ -124,7 +124,7 @@ class RDoc::CrossReference # Allows cross-references to be created based on the given +context+ # (RDoc::Context). - def initialize context + def initialize(context) @context = context @store = context.store @@ -134,7 +134,7 @@ class RDoc::CrossReference ## # Returns a method reference to +name+. - def resolve_method name + def resolve_method(name) ref = nil if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then @@ -187,7 +187,7 @@ class RDoc::CrossReference # returned. If +name+ is escaped +name+ is returned. If +name+ is not # found +text+ is returned. - def resolve name, text + def resolve(name, text) return @seen[name] if @seen.include? name ref = case name diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb index 67e190f782..78dbe87d0c 100644 --- a/lib/rdoc/encoding.rb +++ b/lib/rdoc/encoding.rb @@ -29,7 +29,7 @@ module RDoc::Encoding # If +force_transcode+ is true the document will be transcoded and any # unknown character in the target encoding will be replaced with '?' - def self.read_file filename, encoding, force_transcode = false + def self.read_file(filename, encoding, force_transcode = false) content = File.open filename, "rb" do |f| f.read end content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/ @@ -89,7 +89,7 @@ module RDoc::Encoding ## # Detects the encoding of +string+ based on the magic comment - def self.detect_encoding string + def self.detect_encoding(string) result = HEADER_REGEXP.match string name = result && result[:name] @@ -99,7 +99,7 @@ module RDoc::Encoding ## # Removes magic comments and shebang - def self.remove_magic_comment string + def self.remove_magic_comment(string) string.sub HEADER_REGEXP do |s| s.gsub(/[^\n]/, '') end @@ -109,7 +109,7 @@ module RDoc::Encoding # Changes encoding based on +encoding+ without converting and returns new # string - def self.change_encoding text, encoding + def self.change_encoding(text, encoding) if text.kind_of? RDoc::Comment text.encode! encoding else diff --git a/lib/rdoc/erb_partial.rb b/lib/rdoc/erb_partial.rb index 043d763db1..bad02ea706 100644 --- a/lib/rdoc/erb_partial.rb +++ b/lib/rdoc/erb_partial.rb @@ -9,7 +9,7 @@ class RDoc::ERBPartial < ERB # Overrides +compiler+ startup to set the +eoutvar+ to an empty string only # if it isn't already set. - def set_eoutvar compiler, eoutvar = '_erbout' + def set_eoutvar(compiler, eoutvar = '_erbout') super compiler.pre_cmd = ["#{eoutvar} ||= +''"] diff --git a/lib/rdoc/erbio.rb b/lib/rdoc/erbio.rb index 0f98eaedee..e955eed811 100644 --- a/lib/rdoc/erbio.rb +++ b/lib/rdoc/erbio.rb @@ -20,14 +20,14 @@ class RDoc::ERBIO < ERB ## # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize - def initialize str, trim_mode: nil, eoutvar: 'io' + def initialize(str, trim_mode: nil, eoutvar: 'io') super(str, trim_mode: trim_mode, eoutvar: eoutvar) end ## # Instructs +compiler+ how to write to +io_variable+ - def set_eoutvar compiler, io_variable + def set_eoutvar(compiler, io_variable) compiler.put_cmd = "#{io_variable}.write" compiler.insert_cmd = "#{io_variable}.write" compiler.pre_cmd = [] diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 08f2b85e3b..7fec36500f 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -73,12 +73,6 @@ class RDoc::Generator::Darkfish css/rdoc.css ] - ## - # Path to this file's parent directory. Used to find templates and other - # resources. - - GENERATOR_DIR = File.join 'rdoc', 'generator' - ## # Release Version @@ -156,7 +150,7 @@ class RDoc::Generator::Darkfish ## # Initialize a few instance variables before we start - def initialize store, options + def initialize(store, options) @store = store @options = options @@ -184,22 +178,6 @@ class RDoc::Generator::Darkfish $stderr.puts(*msg) end - ## - # Directory where generated class HTML files live relative to the output - # dir. - - def class_dir - nil - end - - ## - # Directory where generated class HTML files live relative to the output - # dir. - - def file_dir - nil - end - ## # Create the directories the generated docs will live in if they don't # already exist. @@ -291,7 +269,7 @@ class RDoc::Generator::Darkfish # Return a list of the documented modules sorted by salience first, then # by name. - def get_sorted_module_list classes + def get_sorted_module_list(classes) classes.select do |klass| klass.display? end.sort @@ -301,8 +279,6 @@ class RDoc::Generator::Darkfish # Generate an index page which lists all the classes which are documented. def generate_index - setup - template_file = @template_dir + 'index.rhtml' return unless template_file.exist? @@ -316,11 +292,14 @@ class RDoc::Generator::Darkfish asset_rel_prefix = rel_prefix + @asset_rel_path @title = @options.title + @main_page = @files.find { |f| f.full_name == @options.main_page } render_template template_file, out_file do |io| here = binding # suppress 1.9.3 warning here.local_variable_set(:asset_rel_prefix, asset_rel_prefix) + # some partials rely on the presence of current variable to render + here.local_variable_set(:current, @main_page) if @main_page here end rescue => e @@ -334,9 +313,7 @@ class RDoc::Generator::Darkfish ## # Generates a class file for +klass+ - def generate_class klass, template_file = nil - setup - + def generate_class(klass, template_file = nil) current = klass template_file ||= @template_dir + 'class.rhtml' @@ -348,7 +325,9 @@ class RDoc::Generator::Darkfish search_index_rel_prefix += @asset_rel_path if @file_output asset_rel_prefix = rel_prefix + @asset_rel_path - svninfo = get_svninfo(current) + + breadcrumb = # used in templates + breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix) @title = "#{klass.type} #{klass.full_name} - #{@options.title}" @@ -357,7 +336,6 @@ class RDoc::Generator::Darkfish here = binding # suppress 1.9.3 warning here.local_variable_set(:asset_rel_prefix, asset_rel_prefix) - here.local_variable_set(:svninfo, svninfo) here end end @@ -366,8 +344,6 @@ class RDoc::Generator::Darkfish # Generate a documentation file for each class and module def generate_class_files - setup - template_file = @template_dir + 'class.rhtml' template_file = @template_dir + 'classpage.rhtml' unless template_file.exist? @@ -393,8 +369,6 @@ class RDoc::Generator::Darkfish # Generate a documentation file for each file def generate_file_files - setup - page_file = @template_dir + 'page.rhtml' fileinfo_file = @template_dir + 'fileinfo.rhtml' @@ -461,9 +435,7 @@ class RDoc::Generator::Darkfish ## # Generate a page file for +file+ - def generate_page file - setup - + def generate_page(file) template_file = @template_dir + 'page.rhtml' out_file = @outputdir + file.path @@ -490,9 +462,7 @@ class RDoc::Generator::Darkfish ## # Generates the 404 page for the RDoc servlet - def generate_servlet_not_found message - setup - + def generate_servlet_not_found(message) template_file = @template_dir + 'servlet_not_found.rhtml' return unless template_file.exist? @@ -523,9 +493,7 @@ class RDoc::Generator::Darkfish ## # Generates the servlet root page for the RDoc servlet - def generate_servlet_root installed - setup - + def generate_servlet_root(installed) template_file = @template_dir + 'servlet_root.rhtml' return unless template_file.exist? @@ -551,8 +519,6 @@ class RDoc::Generator::Darkfish # Generate an index page which lists all the classes which are documented. def generate_table_of_contents - setup - template_file = @template_dir + 'table_of_contents.rhtml' return unless template_file.exist? @@ -581,7 +547,7 @@ class RDoc::Generator::Darkfish raise error end - def install_rdoc_static_file source, destination, options # :nodoc: + def install_rdoc_static_file(source, destination, options) # :nodoc: return unless source.exist? begin @@ -614,65 +580,13 @@ class RDoc::Generator::Darkfish @modsort = get_sorted_module_list @classes end - ## - # Return a string describing the amount of time in the given number of - # seconds in terms a human can understand easily. - - def time_delta_string seconds - return 'less than a minute' if seconds < 60 - return "#{seconds / 60} minute#{seconds / 60 == 1 ? '' : 's'}" if - seconds < 3000 # 50 minutes - return 'about one hour' if seconds < 5400 # 90 minutes - return "#{seconds / 3600} hours" if seconds < 64800 # 18 hours - return 'one day' if seconds < 86400 # 1 day - return 'about one day' if seconds < 172800 # 2 days - return "#{seconds / 86400} days" if seconds < 604800 # 1 week - return 'about one week' if seconds < 1209600 # 2 week - return "#{seconds / 604800} weeks" if seconds < 7257600 # 3 months - return "#{seconds / 2419200} months" if seconds < 31536000 # 1 year - return "#{seconds / 31536000} years" - end - - # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $" - SVNID_PATTERN = / - \$Id:\s - (\S+)\s # filename - (\d+)\s # rev - (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD) - (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ) - (\w+)\s # committer - \$$ - /x - - ## - # Try to extract Subversion information out of the first constant whose - # value looks like a subversion Id tag. If no matching constant is found, - # and empty hash is returned. - - def get_svninfo klass - constants = klass.constants or return {} - - constants.find { |c| c.value =~ SVNID_PATTERN } or return {} - - filename, rev, date, time, committer = $~.captures - commitdate = Time.parse "#{date} #{time}" - - return { - :filename => filename, - :rev => Integer(rev), - :commitdate => commitdate, - :commitdelta => time_delta_string(Time.now - commitdate), - :committer => committer, - } - end - ## # Creates a template from its components and the +body_file+. # # For backwards compatibility, if +body_file+ contains " - + #{head_file.read} @@ -693,7 +607,7 @@ class RDoc::Generator::Darkfish # Renders the ERb contained in +file_name+ relative to the template # directory and returns the result based on the current context. - def render file_name + def render(file_name) template_file = @template_dir + file_name template = template_for template_file, false, RDoc::ERBPartial @@ -711,7 +625,7 @@ class RDoc::Generator::Darkfish # # An io will be yielded which must be captured by binding in the caller. - def render_template template_file, out_file = nil # :yield: io + def render_template(template_file, out_file = nil) # :yield: io io_output = out_file && !@dry_run && @file_output erb_klass = io_output ? RDoc::ERBIO : ERB @@ -745,7 +659,7 @@ class RDoc::Generator::Darkfish # Creates the result for +template+ with +context+. If an error is raised a # Pathname +template_file+ will indicate the file where the error occurred. - def template_result template, context, template_file + def template_result(template, context, template_file) template.filename = template_file.to_s template.result context rescue NoMethodError => e @@ -758,7 +672,7 @@ class RDoc::Generator::Darkfish ## # Retrieves a cache template for +file+, if present, or fills the cache. - def template_for file, page = true, klass = ERB + def template_for(file, page = true, klass = ERB) template = @template_cache[file] return template if template @@ -780,32 +694,39 @@ class RDoc::Generator::Darkfish template end - # Returns an excerpt of the content for usage in meta description tags - def excerpt(content) - text = case content + # :stopdoc: + ParagraphExcerptRegexpOther = %r[\b\w[^./:]++\.] + # use \p/\P{letter} instead of \w/\W in Unicode + ParagraphExcerptRegexpUnicode = %r[\b\p{letter}[^./:]++\.] + # :startdoc: + + # Returns an excerpt of the comment for usage in meta description tags + def excerpt(comment) + text = case comment when RDoc::Comment - content.text - when RDoc::Markup::Document - # This case is for page files that are not markdown nor rdoc - # We convert them to markdown for now as it's easier to extract the text - formatter = RDoc::Markup::ToMarkdown.new - formatter.start_accepting - formatter.accept_document(content) - formatter.end_accepting + comment.text else - content + comment end # Match from a capital letter to the first period, discarding any links, so # that we don't end up matching badges in the README - first_paragraph_match = text.match(/[A-Z][^\.:\/]+\./) - return text[0...150].gsub(/\n/, " ").squeeze(" ") unless first_paragraph_match + pattern = ParagraphExcerptRegexpUnicode + begin + first_paragraph_match = text.match(pattern) + rescue Encoding::CompatibilityError + # The doc is non-ASCII text and encoded in other than Unicode base encodings. + raise if pattern == ParagraphExcerptRegexpOther + pattern = ParagraphExcerptRegexpOther + retry + end + return text[0...150].tr_s("\n", " ").squeeze(" ") unless first_paragraph_match extracted_text = first_paragraph_match[0] - second_paragraph = first_paragraph_match.post_match.match(/[A-Z][^\.:\/]+\./) + second_paragraph = text.match(pattern, first_paragraph_match.end(0)) extracted_text << " " << second_paragraph[0] if second_paragraph - extracted_text[0...150].gsub(/\n/, " ").squeeze(" ") + extracted_text[0...150].tr_s("\n", " ").squeeze(" ") end def generate_ancestor_list(ancestors, klass) @@ -825,4 +746,67 @@ class RDoc::Generator::Darkfish content << '' end + + def generate_class_link(klass, rel_prefix) + if klass.display? + %(#{klass.name}) + else + %(#{klass.name}) + end + end + + def generate_class_index_content(classes, rel_prefix) + grouped_classes = group_classes_by_namespace_for_sidebar(classes) + return '' unless top = grouped_classes[nil] + + solo = top.one? { |klass| klass.display? } + traverse_classes(top, grouped_classes, rel_prefix, solo) + end + + def traverse_classes(klasses, grouped_classes, rel_prefix, solo = false) + content = +'" + end + + def group_classes_by_namespace_for_sidebar(classes) + grouped_classes = classes.group_by do |klass| + klass.full_name[/\A[^:]++(?:::[^:]++(?=::))*+(?=::[^:]*+\z)/] + end.select do |_, klasses| + klasses.any?(&:display?) + end + + grouped_classes.values.each(&:uniq!) + grouped_classes + end + + private + + def nesting_namespaces_to_class_modules(klass) + tree = {} + + klass.nesting_namespaces.zip(klass.fully_qualified_nesting_namespaces) do |ns, fqns| + tree[ns] = @store.classes_hash[fqns] || @store.modules_hash[fqns] + end + + tree + end + + def generate_nesting_namespaces_breadcrumb(klass, rel_prefix) + nesting_namespaces_to_class_modules(klass).map do |namespace, class_module| + path = class_module ? (rel_prefix + class_module.path).to_s : "" + { name: namespace, path: path, self: klass.full_name == class_module&.full_name } + end + end end diff --git a/lib/rdoc/generator/json_index.rb b/lib/rdoc/generator/json_index.rb index c454910d5c..065caa47ea 100644 --- a/lib/rdoc/generator/json_index.rb +++ b/lib/rdoc/generator/json_index.rb @@ -86,12 +86,10 @@ class RDoc::Generator::JsonIndex attr_reader :index # :nodoc: ## - # Creates a new generator. +parent_generator+ is used to determine the - # class_dir and file_dir of links in the output index. - # + # Creates a new generator. # +options+ are the same options passed to the parent generator. - def initialize parent_generator, options + def initialize(parent_generator, options) @parent_generator = parent_generator @store = parent_generator.store @options = options @@ -265,21 +263,7 @@ class RDoc::Generator::JsonIndex end end - ## - # The directory classes are written to - - def class_dir - @parent_generator.class_dir - end - - ## - # The directory files are written to - - def file_dir - @parent_generator.file_dir - end - - def reset files, classes # :nodoc: + def reset(files, classes) # :nodoc: @files = files @classes = classes @@ -293,7 +277,7 @@ class RDoc::Generator::JsonIndex ## # Removes whitespace and downcases +string+ - def search_string string + def search_string(string) string.downcase.gsub(/\s/, '') end diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb index 76b7d458aa..1c39687040 100644 --- a/lib/rdoc/generator/markup.rb +++ b/lib/rdoc/generator/markup.rb @@ -34,7 +34,7 @@ module RDoc::Generator::Markup def formatter return @formatter if defined? @formatter - options = @store.rdoc.options + options = @store.options this = RDoc::Context === self ? self : @parent @formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this @@ -55,6 +55,18 @@ module RDoc::Generator::Markup end end + ## + # The preferred URL for this object. + + def canonical_url + options = @store.options + if path + File.join(options.canonical_root, path.to_s) + else + options.canonical_root + end + end + end class RDoc::CodeObject @@ -147,7 +159,7 @@ class RDoc::TopLevel # command line option to set. def cvs_url - url = @store.rdoc.options.webcvs + url = @store.options.webcvs if /%s/ =~ url then url % @relative_name diff --git a/lib/rdoc/generator/pot.rb b/lib/rdoc/generator/pot.rb index b0b7c07179..a20fde077b 100644 --- a/lib/rdoc/generator/pot.rb +++ b/lib/rdoc/generator/pot.rb @@ -65,7 +65,7 @@ class RDoc::Generator::POT ## # Set up a new .pot generator - def initialize store, options #:not-new: + def initialize(store, options) #:not-new: @options = options @store = store end @@ -81,11 +81,6 @@ class RDoc::Generator::POT end end - # :nodoc: - def class_dir - nil - end - private def extract_messages extractor = MessageExtractor.new(@store) diff --git a/lib/rdoc/generator/pot/message_extractor.rb b/lib/rdoc/generator/pot/message_extractor.rb index 4938858bdc..ee6d847bd6 100644 --- a/lib/rdoc/generator/pot/message_extractor.rb +++ b/lib/rdoc/generator/pot/message_extractor.rb @@ -7,7 +7,7 @@ class RDoc::Generator::POT::MessageExtractor ## # Creates a message extractor for +store+. - def initialize store + def initialize(store) @store = store @po = RDoc::Generator::POT::PO.new end @@ -25,7 +25,7 @@ class RDoc::Generator::POT::MessageExtractor private - def extract_from_klass klass + def extract_from_klass(klass) extract_text(klass.comment_location, klass.full_name) klass.each_section do |section, constants, attributes| @@ -35,11 +35,11 @@ class RDoc::Generator::POT::MessageExtractor end end - klass.each_constant do |constant| + klass.constants.each do |constant| extract_text(constant.comment, constant.full_name) end - klass.each_attribute do |attribute| + klass.attributes.each do |attribute| extract_text(attribute.comment, attribute.full_name) end @@ -48,7 +48,7 @@ class RDoc::Generator::POT::MessageExtractor end end - def extract_text text, comment, location = nil + def extract_text(text, comment, location = nil) return if text.nil? options = { @@ -61,7 +61,7 @@ class RDoc::Generator::POT::MessageExtractor end end - def entry msgid, options + def entry(msgid, options) RDoc::Generator::POT::POEntry.new(msgid, options) end diff --git a/lib/rdoc/generator/pot/po.rb b/lib/rdoc/generator/pot/po.rb index 37d45e5258..447cb60ead 100644 --- a/lib/rdoc/generator/pot/po.rb +++ b/lib/rdoc/generator/pot/po.rb @@ -15,7 +15,7 @@ class RDoc::Generator::POT::PO ## # Adds a PO entry to the PO. - def add entry + def add(entry) existing_entry = @entries[entry.msgid] if existing_entry entry = existing_entry.merge(entry) diff --git a/lib/rdoc/generator/pot/po_entry.rb b/lib/rdoc/generator/pot/po_entry.rb index 7454b29273..8de260eef1 100644 --- a/lib/rdoc/generator/pot/po_entry.rb +++ b/lib/rdoc/generator/pot/po_entry.rb @@ -26,7 +26,7 @@ class RDoc::Generator::POT::POEntry # Creates a PO entry for +msgid+. Other values can be specified by # +options+. - def initialize msgid, options = {} + def initialize(msgid, options = {}) @msgid = msgid @msgstr = options[:msgstr] || "" @translator_comment = options[:translator_comment] @@ -53,7 +53,7 @@ msgstr #{format_message(@msgstr)} ## # Merges the PO entry with +other_entry+. - def merge other_entry + def merge(other_entry) options = { :extracted_comment => merge_string(@extracted_comment, other_entry.extracted_comment), @@ -69,7 +69,7 @@ msgstr #{format_message(@msgstr)} private - def format_comment mark, comment + def format_comment(mark, comment) return '' unless comment return '' if comment.empty? @@ -106,7 +106,7 @@ msgstr #{format_message(@msgstr)} "\#, #{formatted_flags}\n" end - def format_message message + def format_message(message) return "\"#{escape(message)}\"" unless message.include?("\n") formatted_message = '""' @@ -117,7 +117,7 @@ msgstr #{format_message(@msgstr)} formatted_message end - def escape string + def escape(string) string.gsub(/["\\\t\n]/) do |special_character| case special_character when "\t" @@ -130,11 +130,11 @@ msgstr #{format_message(@msgstr)} end end - def merge_string string1, string2 + def merge_string(string1, string2) [string1, string2].compact.join("\n") end - def merge_array array1, array2 + def merge_array(array1, array2) (array1 + array2).uniq end diff --git a/lib/rdoc/generator/ri.rb b/lib/rdoc/generator/ri.rb index 1c2f018f97..32f518ac71 100644 --- a/lib/rdoc/generator/ri.rb +++ b/lib/rdoc/generator/ri.rb @@ -14,7 +14,7 @@ class RDoc::Generator::RI ## # Set up a new ri generator - def initialize store, options #:not-new: + def initialize(store, options) #:not-new: @options = options @store = store @store.path = '.' diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml index 9e6fb4f94c..7376fc390e 100644 --- a/lib/rdoc/generator/template/darkfish/_head.rhtml +++ b/lib/rdoc/generator/template/darkfish/_head.rhtml @@ -25,6 +25,11 @@ <%- end -%> <%- end -%> +<%- if canonical_url = @options.canonical_root -%> +<% canonical_url = current.canonical_url if defined?(current) %> + +<%- end -%> +