Class: RDoc::Context::Section

Inherits:
Object
  • Object
show all
Includes:
Generator::Markup, Text
Defined in:
lib/rdoc/context.rb,
lib/rdoc/generator/markup.rb

Overview

A section of documentation like:

# :section: The title
# The body

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

Constant Summary

@@sequence =
"SEC00000"

Constants included from Text

Text::TO_HTML_CHARACTERS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Generator::Markup

#aref_to, #as_href, #cvs_url, #description, #formatter

Methods included from Text

encode_fallback, #expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #strip_hashes, #strip_newlines, #strip_stars, #to_html, #wrap

Constructor Details

- (Section) initialize(parent, title, comment)

Creates a new section with title and comment



123
124
125
126
127
128
129
130
131
# File 'lib/rdoc/context.rb', line 123

def initialize parent, title, comment
  @parent = parent
  @title = title ? title.strip : title

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

  @comment = extract_comment comment
end

Instance Attribute Details

- (Object) comment

Section comment



106
107
108
# File 'lib/rdoc/context.rb', line 106

def comment
  @comment
end

- (Object) parent (readonly)

Context this Section lives in



111
112
113
# File 'lib/rdoc/context.rb', line 111

def parent
  @parent
end

- (Object) title (readonly)

Section title



116
117
118
# File 'lib/rdoc/context.rb', line 116

def title
  @title
end

Instance Method Details

- (Object) ==(other)

Sections are equal when they have the same #title



136
137
138
# File 'lib/rdoc/context.rb', line 136

def == other
  self.class === other and @title == other.title
end

- (Object) aref

Anchor reference for linking to this section



143
144
145
146
147
# File 'lib/rdoc/context.rb', line 143

def aref
  title = @title || '[untitled]'

  CGI.escape(title).gsub('%', '-').sub(/^-/, '')
end

- (Object) extract_comment(comment)

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


173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/rdoc/context.rb', line 173

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

- (Object) inspect

:nodoc:



188
189
190
191
192
193
# File 'lib/rdoc/context.rb', line 188

def inspect # :nodoc:
  "#<%s:0x%x %s %p>" % [
    self.class, object_id,
    @sequence, title
  ]
end

- (Object) sequence

Section sequence number (deprecated)



198
199
200
201
# File 'lib/rdoc/context.rb', line 198

def sequence
  warn "RDoc::Context::Section#sequence is deprecated, use #aref"
  @sequence
end