rdoc 6.17.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. data/lib/rdoc/servlet.rb +0 -452
@@ -1,186 +1,223 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # A constant
2
+ module RDoc
3
+ ##
4
+ # A constant
4
5
 
5
- class RDoc::Constant < RDoc::CodeObject
6
+ class Constant < CodeObject
6
7
 
7
- MARSHAL_VERSION = 0 # :nodoc:
8
+ MARSHAL_VERSION = 0 # :nodoc:
8
9
 
9
- ##
10
- # Sets the module or class this is constant is an alias for.
10
+ ##
11
+ # Sets the module or class this is constant is an alias for.
11
12
 
12
- attr_writer :is_alias_for
13
+ attr_writer :is_alias_for
13
14
 
14
- ##
15
- # The constant's name
15
+ ##
16
+ # The constant's name
16
17
 
17
- attr_accessor :name
18
+ attr_accessor :name
18
19
 
19
- ##
20
- # The constant's value
20
+ ##
21
+ # The constant's value
21
22
 
22
- attr_accessor :value
23
+ attr_accessor :value
23
24
 
24
- ##
25
- # The constant's visibility
25
+ ##
26
+ # The constant's visibility
26
27
 
27
- attr_accessor :visibility
28
+ attr_accessor :visibility
28
29
 
29
- ##
30
- # Creates a new constant with +name+, +value+ and +comment+
30
+ ##
31
+ # The constant path on the RHS when the RHS is a bare constant reference
32
+ # (+Foo = Bar+ or +Foo = Bar::Baz+). Captured at parse time so
33
+ # #resolved_alias_target doesn't have to re-derive it from the textual
34
+ # #value. nil for other RHS shapes.
31
35
 
32
- def initialize(name, value, comment)
33
- super()
36
+ attr_accessor :is_alias_for_path
34
37
 
35
- @name = name
36
- @value = value
38
+ ##
39
+ # Creates a new constant with +name+, +value+ and +comment+
37
40
 
38
- @is_alias_for = nil
39
- @visibility = :public
41
+ def initialize(name, value, comment)
42
+ super()
40
43
 
41
- self.comment = comment
42
- end
44
+ @name = name
45
+ @value = value
43
46
 
44
- ##
45
- # Constants are ordered by name
47
+ @is_alias_for = nil
48
+ @is_alias_for_path = nil
49
+ @visibility = :public
46
50
 
47
- def <=>(other)
48
- return unless self.class === other
51
+ self.comment = comment
52
+ end
49
53
 
50
- [parent_name, name] <=> [other.parent_name, other.name]
51
- end
54
+ ##
55
+ # Constants are ordered by name
52
56
 
53
- ##
54
- # Constants are equal when their #parent and #name is the same
57
+ def <=>(other)
58
+ return unless self.class === other
55
59
 
56
- def ==(other)
57
- self.class == other.class and
58
- @parent == other.parent and
59
- @name == other.name
60
- end
60
+ [parent_name, name] <=> [other.parent_name, other.name]
61
+ end
61
62
 
62
- ##
63
- # A constant is documented if it has a comment, or is an alias
64
- # for a documented class or module.
65
-
66
- def documented?
67
- return true if super
68
- return false unless @is_alias_for
69
- case @is_alias_for
70
- when String then
71
- found = @store.find_class_or_module @is_alias_for
72
- return false unless found
73
- @is_alias_for = found
63
+ ##
64
+ # Constants are equal when their #parent and #name is the same
65
+
66
+ def ==(other)
67
+ self.class == other.class and
68
+ @parent == other.parent and
69
+ @name == other.name
74
70
  end
75
- @is_alias_for.documented?
76
- end
77
71
 
78
- ##
79
- # Full constant name including namespace
72
+ ##
73
+ # A constant is documented if it has a comment, or is an alias
74
+ # for a documented class or module.
75
+
76
+ def documented?
77
+ return true if super
78
+ return false unless @is_alias_for
79
+ case @is_alias_for
80
+ when String
81
+ found = @store.find_class_or_module @is_alias_for
82
+ return false unless found
83
+ @is_alias_for = found
84
+ end
85
+ @is_alias_for.documented?
86
+ end
80
87
 
81
- def full_name
82
- @full_name ||= "#{parent_name}::#{@name}"
83
- end
88
+ ##
89
+ # Full constant name including namespace
84
90
 
85
- ##
86
- # The module or class this constant is an alias for
87
-
88
- def is_alias_for
89
- case @is_alias_for
90
- when String then
91
- found = @store.find_class_or_module @is_alias_for
92
- @is_alias_for = found if found
93
- @is_alias_for
94
- else
95
- @is_alias_for
91
+ def full_name
92
+ @full_name ||= "#{parent_name}::#{@name}"
96
93
  end
97
- end
98
94
 
99
- def inspect # :nodoc:
100
- "#<%s:0x%x %s::%s>" % [
101
- self.class, object_id,
102
- parent_name, @name,
103
- ]
104
- end
95
+ ##
96
+ # The module or class this constant is an alias for, when one was recorded
97
+ # explicitly (by RDoc::Context#add_module_alias, RDoc::ClassModule#update_aliases,
98
+ # or ri marshal load). Pure accessor; see #resolved_alias_target for the
99
+ # opportunistic lookup path.
100
+
101
+ def is_alias_for
102
+ case @is_alias_for
103
+ when String
104
+ found = @store.find_class_or_module @is_alias_for
105
+ @is_alias_for = found if found
106
+ @is_alias_for
107
+ else
108
+ @is_alias_for
109
+ end
110
+ end
105
111
 
106
- ##
107
- # Dumps this Constant for use by ri. See also #marshal_load
108
-
109
- def marshal_dump
110
- alias_name = case found = is_alias_for
111
- when RDoc::CodeObject then found.full_name
112
- else found
113
- end
114
-
115
- [ MARSHAL_VERSION,
116
- @name,
117
- full_name,
118
- @visibility,
119
- alias_name,
120
- parse(@comment),
121
- @file.relative_name,
122
- parent.name,
123
- parent.class,
124
- section.title,
125
- ]
126
- end
112
+ ##
113
+ # Returns the class/module this constant *would* alias if #is_alias_for_path
114
+ # was set by the parser and that path resolves to a known class/module, or
115
+ # nil. Used to support `Const = RHS` parsed before `class RHS;end` is defined
116
+ # in another file. Pure lookup; does not mutate state. Honors :nodoc:
117
+ # (returns nil if document_self is false). Note that module nesting
118
+ # information is lost, so constant lookup is inaccurate.
119
+
120
+ def resolved_alias_target
121
+ return nil unless document_self
122
+ return nil unless @is_alias_for_path
123
+ parent.find_module_named(@is_alias_for_path)
124
+ end
127
125
 
128
- ##
129
- # Loads this Constant from +array+. For a loaded Constant the following
130
- # methods will return cached values:
131
- #
132
- # * #full_name
133
- # * #parent_name
134
-
135
- def marshal_load(array)
136
- initialize array[1], nil, RDoc::Comment.from_document(array[5])
137
-
138
- @full_name = array[2]
139
- @visibility = array[3] || :public
140
- @is_alias_for = array[4]
141
- # 5 handled above
142
- # 6 handled below
143
- @parent_name = array[7]
144
- @parent_class = array[8]
145
- @section_title = array[9]
146
-
147
- @file = RDoc::TopLevel.new array[6]
148
- end
126
+ def inspect # :nodoc:
127
+ "#<%s:0x%x %s::%s>" % [
128
+ self.class, object_id,
129
+ parent_name, @name,
130
+ ]
131
+ end
149
132
 
150
- ##
151
- # Path to this constant for use with HTML generator output.
133
+ ##
134
+ # Dumps this Constant for use by ri. See also #marshal_load
135
+
136
+ def marshal_dump
137
+ alias_name = case found = is_alias_for
138
+ when CodeObject then found.full_name
139
+ else found
140
+ end
141
+
142
+ [ MARSHAL_VERSION,
143
+ @name,
144
+ full_name,
145
+ @visibility,
146
+ alias_name,
147
+ parse(@comment),
148
+ @file.relative_name,
149
+ parent.name,
150
+ parent.class,
151
+ section.title,
152
+ ]
153
+ end
152
154
 
153
- def path
154
- "#{@parent.path}##{@name}"
155
- end
155
+ ##
156
+ # Loads this Constant from +array+. For a loaded Constant the following
157
+ # methods will return cached values:
158
+ #
159
+ # * #full_name
160
+ # * #parent_name
161
+
162
+ def marshal_load(array)
163
+ initialize array[1], nil, Comment.from_document(array[5])
164
+
165
+ @full_name = array[2]
166
+ @visibility = array[3] || :public
167
+ @is_alias_for = array[4]
168
+ # 5 handled above
169
+ # 6 handled below
170
+ @parent_name = array[7]
171
+ @parent_class = array[8]
172
+ @section_title = array[9]
173
+
174
+ @file = TopLevel.new array[6]
175
+ end
176
+
177
+ ##
178
+ # Path to this constant for use with HTML generator output.
179
+
180
+ def path
181
+ "#{@parent.path}##{@name}"
182
+ end
183
+
184
+ ##
185
+ # Returns an HTML snippet of the comment for search results.
186
+
187
+ def search_snippet
188
+ return '' if comment.empty?
156
189
 
157
- def pretty_print(q) # :nodoc:
158
- q.group 2, "[#{self.class.name} #{full_name}", "]" do
159
- unless comment.empty? then
160
- q.breakable
161
- q.text "comment:"
162
- q.breakable
163
- q.pp @comment
190
+ snippet(comment)
191
+ end
192
+
193
+ def pretty_print(q) # :nodoc:
194
+ q.group 2, "[#{self.class.name} #{full_name}", "]" do
195
+ unless comment.empty?
196
+ q.breakable
197
+ q.text "comment:"
198
+ q.breakable
199
+ q.pp @comment
200
+ end
164
201
  end
165
202
  end
166
- end
167
203
 
168
- ##
169
- # Sets the store for this class or module and its contained code objects.
204
+ ##
205
+ # Sets the store for this class or module and its contained code objects.
170
206
 
171
- def store=(store)
172
- super
207
+ def store=(store)
208
+ super
173
209
 
174
- @file = @store.add_file @file.full_name if @file
175
- end
210
+ @file = @store.add_file @file.full_name if @file
211
+ end
176
212
 
177
- def to_s # :nodoc:
178
- parent_name = parent ? parent.full_name : '(unknown)'
179
- if is_alias_for
180
- "constant #{parent_name}::#@name -> #{is_alias_for}"
181
- else
182
- "constant #{parent_name}::#@name"
213
+ def to_s # :nodoc:
214
+ parent_name = parent ? parent.full_name : '(unknown)'
215
+ if is_alias_for
216
+ "constant #{parent_name}::#@name -> #{is_alias_for}"
217
+ else
218
+ "constant #{parent_name}::#@name"
219
+ end
183
220
  end
184
- end
185
221
 
222
+ end
186
223
  end
@@ -2,175 +2,185 @@
2
2
  require 'cgi/escape'
3
3
  require 'cgi/util' unless defined?(CGI::EscapeExt)
4
4
 
5
- ##
6
- # A section of documentation like:
7
- #
8
- # # :section: The title
9
- # # The body
10
- #
11
- # Sections can be referenced multiple times and will be collapsed into a
12
- # single section.
5
+ module RDoc
6
+ class Context
7
+ ##
8
+ # A section of documentation like:
9
+ #
10
+ # # :section: The title
11
+ # # The body
12
+ #
13
+ # Sections can be referenced multiple times and will be collapsed into a
14
+ # single section.
13
15
 
14
- class RDoc::Context::Section
16
+ class Section
15
17
 
16
- include RDoc::Text
18
+ include Text
17
19
 
18
- MARSHAL_VERSION = 0 # :nodoc:
20
+ MARSHAL_VERSION = 0 # :nodoc:
19
21
 
20
- ##
21
- # Section comment
22
+ ##
23
+ # Section comments
22
24
 
23
- attr_reader :comment
25
+ attr_reader :comments
24
26
 
25
- ##
26
- # Section comments
27
+ ##
28
+ # Context this Section lives in
27
29
 
28
- attr_reader :comments
30
+ attr_reader :parent
29
31
 
30
- ##
31
- # Context this Section lives in
32
+ ##
33
+ # Section title
32
34
 
33
- attr_reader :parent
35
+ attr_reader :title
34
36
 
35
- ##
36
- # Section title
37
+ ##
38
+ # The RDoc::Store for this object.
37
39
 
38
- attr_reader :title
40
+ attr_reader :store
39
41
 
40
- ##
41
- # Creates a new section with +title+ and +comment+
42
+ ##
43
+ # Creates a new section with +title+ and +comment+
42
44
 
43
- def initialize(parent, title, comment)
44
- @parent = parent
45
- @title = title ? title.strip : title
45
+ def initialize(parent, title, comment, store = nil)
46
+ @parent = parent
47
+ @title = title ? title.strip : title
48
+ @store = store
46
49
 
47
- @comments = []
50
+ @comments = []
48
51
 
49
- add_comment comment
50
- end
52
+ add_comment comment
53
+ end
51
54
 
52
- ##
53
- # Sections are equal when they have the same #title
55
+ ##
56
+ # Sections are equal when they have the same #title
54
57
 
55
- def ==(other)
56
- self.class === other and @title == other.title
57
- end
58
+ def ==(other)
59
+ self.class === other and @title == other.title
60
+ end
58
61
 
59
- alias eql? ==
62
+ alias eql? ==
60
63
 
61
- ##
62
- # Adds +comment+ to this section
64
+ ##
65
+ # Adds +comment+ to this section
63
66
 
64
- def add_comment(comment)
65
- comments = Array(comment)
66
- comments.each do |c|
67
- extracted_comment = extract_comment(c)
68
- @comments << extracted_comment unless extracted_comment.empty?
69
- end
70
- end
67
+ def add_comment(comment)
68
+ Array(comment).each do |c|
69
+ next if c.nil?
70
+ raise TypeError, "unknown comment #{c.inspect}" unless Comment === c
71
+ @comments << c unless c.empty?
72
+ end
73
+ end
71
74
 
72
- ##
73
- # Anchor reference for linking to this section
75
+ ##
76
+ # Anchor reference for linking to this section using GitHub-style format.
77
+ #
78
+ # Examples:
79
+ # "Section" -> "section"
80
+ # "One Two" -> "one-two"
81
+ # "[untitled]" -> "untitled"
74
82
 
75
- def aref
76
- title = @title || '[untitled]'
83
+ def aref
84
+ title = @title || '[untitled]'
77
85
 
78
- CGI.escape(title).gsub('%', '-').sub(/^-/, '')
79
- end
86
+ Text.to_anchor(title)
87
+ end
80
88
 
81
- ##
82
- # Extracts the comment for this section from the original comment block.
83
- # If the first line contains :section:, strip it and use the rest.
84
- # Otherwise remove lines up to the line containing :section:, and look
85
- # for those lines again at the end and remove them. This lets us write
86
- #
87
- # # :section: The title
88
- # # The body
89
-
90
- def extract_comment(comment)
91
- case comment
92
- when nil
93
- RDoc::Comment.new ''
94
- when RDoc::Comment then
95
- if comment.text =~ /^#[ \t]*:section:.*\n/ then
96
- start = $`
97
- rest = $'
98
-
99
- comment.text = if start.empty? then
100
- rest
101
- else
102
- rest.sub(/#{start.chomp}\Z/, '')
103
- end
104
- end
105
-
106
- comment
107
- else
108
- raise TypeError, "unknown comment #{comment.inspect}"
109
- end
110
- end
89
+ ##
90
+ # Legacy anchor reference for backward compatibility.
91
+ #
92
+ # Examples:
93
+ # "Section" -> "section"
94
+ # "One Two" -> "one+two"
95
+ # "[untitled]" -> "5Buntitled-5D"
111
96
 
112
- def inspect # :nodoc:
113
- "#<%s:0x%x %p>" % [self.class, object_id, title]
114
- end
97
+ def legacy_aref
98
+ title = @title || '[untitled]'
115
99
 
116
- def hash # :nodoc:
117
- @title.hash
118
- end
100
+ CGI.escape(title).gsub('%', '-').sub(/^-/, '')
101
+ end
119
102
 
120
- ##
121
- # The files comments in this section come from
103
+ def inspect # :nodoc:
104
+ "#<%s:0x%x %p>" % [self.class, object_id, title]
105
+ end
122
106
 
123
- def in_files
124
- @comments.map(&:file)
125
- end
107
+ def hash # :nodoc:
108
+ @title.hash
109
+ end
126
110
 
127
- ##
128
- # Serializes this Section. The title and parsed comment are saved, but not
129
- # the section parent which must be restored manually.
111
+ ##
112
+ # The files comments in this section come from
130
113
 
131
- def marshal_dump
132
- [
133
- MARSHAL_VERSION,
134
- @title,
135
- parse,
136
- ]
137
- end
114
+ def in_files
115
+ @comments.map(&:file)
116
+ end
138
117
 
139
- ##
140
- # De-serializes this Section. The section parent must be restored manually.
118
+ ##
119
+ # Serializes this Section. The title and parsed comment are saved, but not
120
+ # the section parent which must be restored manually.
141
121
 
142
- def marshal_load(array)
143
- @parent = nil
122
+ def marshal_dump
123
+ [
124
+ MARSHAL_VERSION,
125
+ @title,
126
+ to_document,
127
+ ]
128
+ end
144
129
 
145
- @title = array[1]
146
- @comments = array[2].parts.map { |doc| RDoc::Comment.from_document(doc) }
147
- end
130
+ ##
131
+ # De-serializes this Section. The section parent must be restored manually.
148
132
 
149
- ##
150
- # Parses +comment_location+ into an RDoc::Markup::Document composed of
151
- # multiple RDoc::Markup::Documents with their file set.
133
+ def marshal_load(array)
134
+ @parent = nil
152
135
 
153
- def parse
154
- RDoc::Markup::Document.new(*@comments.map(&:parse))
155
- end
136
+ @title = array[1]
137
+ @comments = array[2].parts.map { |doc| Comment.from_document(doc) }
138
+ end
156
139
 
157
- ##
158
- # The section's title, or 'Top Section' if the title is nil.
159
- #
160
- # This is used by the table of contents template so the name is silly.
140
+ ##
141
+ # Parses +comment_location+ into an RDoc::Markup::Document composed of
142
+ # multiple RDoc::Markup::Documents with their file set.
161
143
 
162
- def plain_html
163
- @title || 'Top Section'
164
- end
144
+ def to_document
145
+ Markup::Document.new(*@comments.map(&:parse))
146
+ end
147
+
148
+ ##
149
+ # The section's title, or 'Top Section' if the title is nil.
150
+ #
151
+ # This is used by the table of contents template so the name is silly.
165
152
 
166
- ##
167
- # Removes a comment from this section if it is from the same file as
168
- # +comment+
153
+ def plain_html
154
+ @title || 'Top Section'
155
+ end
156
+
157
+ ##
158
+ # Section comment
159
+
160
+ def comment
161
+ return nil if @comments.empty?
162
+ Comment.from_document(to_document)
163
+ end
164
+
165
+ def description
166
+ return '' if @comments.empty?
167
+ markup comment
168
+ end
169
+
170
+ def language
171
+ @comments.first&.language
172
+ end
173
+
174
+ ##
175
+ # Removes a comment from this section if it is from the same file as
176
+ # +comment+
177
+
178
+ def remove_comment(target_comment)
179
+ @comments.delete_if do |stored_comment|
180
+ stored_comment.file == target_comment.file
181
+ end
182
+ end
169
183
 
170
- def remove_comment(target_comment)
171
- @comments.delete_if do |stored_comment|
172
- stored_comment.file == target_comment.file
173
184
  end
174
185
  end
175
-
176
186
  end