Class: RDoc::Context::Section
- Inherits:
-
Object
- Object
- RDoc::Context::Section
- Includes:
- Generator::Markup, Text
- Defined in:
- lib/rdoc/code_object/context/section.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 collapse
- MARSHAL_VERSION =
:nodoc:
0
Constants included from Text
Text::MARKUP_FORMAT, Text::SPACE_SEPARATED_LETTER_CLASS
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Section comments.
-
#parent ⇒ Object
readonly
Context this Section lives in.
-
#store ⇒ Object
readonly
The RDoc::Store for this object.
-
#title ⇒ Object
readonly
Section title.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Sections are equal when they have the same #title.
-
#add_comment(comment) ⇒ Object
Adds
commentto this section. -
#aref ⇒ Object
Anchor reference for linking to this section using GitHub-style format.
-
#comment ⇒ Object
Section comment.
- #description ⇒ Object
-
#hash ⇒ Object
:nodoc:.
-
#in_files ⇒ Object
The files comments in this section come from.
-
#initialize(parent, title, comment, store = nil) ⇒ Section
constructor
Creates a new section with
titleandcomment. -
#inspect ⇒ Object
:nodoc:.
- #language ⇒ Object
-
#legacy_aref ⇒ Object
Legacy anchor reference for backward compatibility.
-
#marshal_dump ⇒ Object
Serializes this Section.
-
#marshal_load(array) ⇒ Object
De-serializes this Section.
-
#plain_html ⇒ Object
The section's title, or 'Top Section' if the title is nil.
-
#remove_comment(target_comment) ⇒ Object
Removes a comment from this section if it is from the same file as
comment. -
#to_document ⇒ Object
Parses
comment_locationinto an RDoc::Markup::Document composed of multiple RDoc::Markup::Documents with their file set.
Methods included from Text
decode_legacy_label, expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #snippet, #strip_hashes, #strip_newlines, #strip_stars, to_anchor, #wrap
Methods included from Generator::Markup
#aref_to, #as_href, #canonical_url, #cvs_url, #formatter
Constructor Details
#initialize(parent, title, comment, store = nil) ⇒ Section
Creates a new section with title and comment
45 46 47 48 49 50 51 52 53 |
# File 'lib/rdoc/code_object/context/section.rb', line 45 def initialize(parent, title, comment, store = nil) @parent = parent @title = title ? title.strip : title @store = store @comments = [] add_comment comment end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Section comments
25 26 27 |
# File 'lib/rdoc/code_object/context/section.rb', line 25 def comments @comments end |
#parent ⇒ Object (readonly)
Context this Section lives in
30 31 32 |
# File 'lib/rdoc/code_object/context/section.rb', line 30 def parent @parent end |
#store ⇒ Object (readonly)
The RDoc::Store for this object.
40 41 42 |
# File 'lib/rdoc/code_object/context/section.rb', line 40 def store @store end |
#title ⇒ Object (readonly)
Section title
35 36 37 |
# File 'lib/rdoc/code_object/context/section.rb', line 35 def title @title end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Sections are equal when they have the same #title
58 59 60 |
# File 'lib/rdoc/code_object/context/section.rb', line 58 def ==(other) self.class === other and @title == other.title end |
#add_comment(comment) ⇒ Object
Adds comment to this section
67 68 69 70 71 72 73 |
# File 'lib/rdoc/code_object/context/section.rb', line 67 def add_comment(comment) Array(comment).each do |c| next if c.nil? raise TypeError, "unknown comment #{c.inspect}" unless Comment === c @comments << c unless c.empty? end end |
#aref ⇒ Object
Anchor reference for linking to this section using GitHub-style format.
Examples:
"Section" -> "section"
"One Two" -> "one-two"
"[untitled]" -> "untitled"
83 84 85 86 87 |
# File 'lib/rdoc/code_object/context/section.rb', line 83 def aref title = @title || '[untitled]' Text.to_anchor(title) end |
#comment ⇒ Object
Section comment
160 161 162 163 |
# File 'lib/rdoc/code_object/context/section.rb', line 160 def comment return nil if @comments.empty? Comment.from_document(to_document) end |
#description ⇒ Object
165 166 167 168 |
# File 'lib/rdoc/code_object/context/section.rb', line 165 def description return '' if @comments.empty? markup comment end |
#hash ⇒ Object
:nodoc:
107 108 109 |
# File 'lib/rdoc/code_object/context/section.rb', line 107 def hash # :nodoc: @title.hash end |
#in_files ⇒ Object
The files comments in this section come from
114 115 116 |
# File 'lib/rdoc/code_object/context/section.rb', line 114 def in_files @comments.map(&:file) end |
#inspect ⇒ Object
:nodoc:
103 104 105 |
# File 'lib/rdoc/code_object/context/section.rb', line 103 def inspect # :nodoc: "#<%s:0x%x %p>" % [self.class, object_id, title] end |
#language ⇒ Object
170 171 172 |
# File 'lib/rdoc/code_object/context/section.rb', line 170 def language @comments.first&.language end |
#legacy_aref ⇒ Object
Legacy anchor reference for backward compatibility.
Examples:
"Section" -> "section"
"One Two" -> "one+two"
"[untitled]" -> "5Buntitled-5D"
97 98 99 100 101 |
# File 'lib/rdoc/code_object/context/section.rb', line 97 def legacy_aref title = @title || '[untitled]' CGI.escape(title).gsub('%', '-').sub(/^-/, '') end |
#marshal_dump ⇒ Object
Serializes this Section. The title and parsed comment are saved, but not the section parent which must be restored manually.
122 123 124 125 126 127 128 |
# File 'lib/rdoc/code_object/context/section.rb', line 122 def marshal_dump [ MARSHAL_VERSION, @title, to_document, ] end |
#marshal_load(array) ⇒ Object
De-serializes this Section. The section parent must be restored manually.
133 134 135 136 137 138 |
# File 'lib/rdoc/code_object/context/section.rb', line 133 def marshal_load(array) @parent = nil @title = array[1] @comments = array[2].parts.map { |doc| Comment.from_document(doc) } end |
#plain_html ⇒ Object
The section's title, or 'Top Section' if the title is nil.
This is used by the table of contents template so the name is silly.
153 154 155 |
# File 'lib/rdoc/code_object/context/section.rb', line 153 def plain_html @title || 'Top Section' end |
#remove_comment(target_comment) ⇒ Object
Removes a comment from this section if it is from the same file as
comment
178 179 180 181 182 |
# File 'lib/rdoc/code_object/context/section.rb', line 178 def remove_comment(target_comment) @comments.delete_if do |stored_comment| stored_comment.file == target_comment.file end end |