In Files

  • rdoc/context.rb
  • rdoc/generator/markup.rb

Class/Module Index [+]

Quicksearch

RDoc::Context::Section

A section of documentation like:

# :section: The title
# The body

Sections can be referenced multiple times and will be collapsed into a single section.

Attributes

comment[R]

Section comment

parent[R]

Context this Section lives in

title[R]

Section title

Public Class Methods

new(parent, title, comment) click to toggle source

Creates a new section with title and comment

 
               # File rdoc/context.rb, line 128
def initialize parent, title, comment
  @parent = parent
  @title = title ? title.strip : title

  @@sequence.succ!
  @sequence = @@sequence.dup

  @comment = extract_comment comment
end
            

Public Instance Methods

==(other) click to toggle source

Sections are equal when they have the same title

 
               # File rdoc/context.rb, line 141
def == other
  self.class === other and @title == other.title
end
            
aref() click to toggle source

Anchor reference for linking to this section

 
               # File rdoc/context.rb, line 148
def aref
  title = @title || '[untitled]'

  CGI.escape(title).gsub('%', '-').sub(/^-/, '')
end
            
comment=(comment) click to toggle source

Appends comment to the current comment separated by a rule.

 
               # File rdoc/context.rb, line 157
def comment= comment
  comment = extract_comment comment

  return if comment.empty?

  if @comment then
    @comment += "\n# ---\n#{comment}"
  else
    @comment = comment
  end
end
            
extract_comment(comment) click to toggle source

Extracts the comment for this section from the original comment block. If the first line contains :section:, strip it and use the rest. Otherwise remove lines up to the line containing :section:, and look for those lines again at the end and remove them. This lets us write

# :section: The title
# The body
 
               # File rdoc/context.rb, line 178
def extract_comment comment
  if comment =~ /^#[ \t]*:section:.*\n/ then
    start = $`
    rest = $'

    if start.empty? then
      rest
    else
      rest.sub(/#{start.chomp}\Z/, '')
    end
  else
    comment
  end
end
            
sequence() click to toggle source

Section sequence number (deprecated)

 
               # File rdoc/context.rb, line 200
def sequence
  warn "RDoc::Context::Section#sequence is deprecated, use #aref"
  @sequence
end