Skip to content

Commit e2d4ac9

Browse files
authored
Deprecate main and title directives (#1218)
* Deprecate :main: directive * Deprecate :title: direcive * Update documentation * Remove :main: directive's usage * Update test cases * Add '.rdoc_options' to suggested alternatives
1 parent 09d7f35 commit e2d4ac9

File tree

6 files changed

+58
-20
lines changed

6 files changed

+58
-20
lines changed

doc/rdoc/markup_reference.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,6 @@
535535
# parameter +type+ is one of: +rdoc+ (the default), +markdown+, +rd+, +tomdoc+.
536536
# See {Markup Formats}[rdoc-ref:RDoc::Markup@Markup+Formats].
537537
#
538-
# ===== Directives for HTML Output
539-
#
540-
# - <tt># :title: _text_</tt>:
541-
#
542-
# - Appears on a line by itself.
543-
# - Specifies the title for the HTML output.
544-
#
545-
# - <tt># :main: _filename_</tt>:
546-
# - Appears on a line by itself.
547-
# - Specifies the HTML file to be displayed first.
548-
#
549538
# ===== Directives for Method Documentation
550539
#
551540
# - <tt># :call-seq:</tt>:

lib/rdoc.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22
$DEBUG_RDOC = nil
33

4-
# :main: README.rdoc
5-
64
##
75
# RDoc produces documentation for Ruby source files by parsing the source and
86
# extracting the definition for classes, modules, methods, includes and

lib/rdoc/markup/pre_process.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ def handle_directive prefix, directive, param, code_object = nil,
187187
include_file filename, prefix, encoding
188188
when 'main' then
189189
@options.main_page = param if @options.respond_to? :main_page
190+
warn <<~MSG
191+
The :main: directive is deprecated and will be removed in RDoc 7.
192+
193+
You can use these options to specify the initial page displayed instead:
194+
- `--main=#{param}` via the command line
195+
- `rdoc.main = "#{param}"` if you use `RDoc::Task`
196+
- `main_page: #{param}` in your `.rdoc_options` file
197+
MSG
190198

191199
blankline
192200
when 'nodoc' then
@@ -217,6 +225,15 @@ def handle_directive prefix, directive, param, code_object = nil,
217225
when 'title' then
218226
@options.default_title = param if @options.respond_to? :default_title=
219227

228+
warn <<~MSG
229+
The :title: directive is deprecated and will be removed in RDoc 7.
230+
231+
You can use these options to specify the title displayed instead:
232+
- `--title=#{param}` via the command line
233+
- `rdoc.title = "#{param}"` if you use `RDoc::Task`
234+
- `title: #{param}` in your `.rdoc_options` file
235+
MSG
236+
220237
blankline
221238
when 'yield', 'yields' then
222239
return blankline unless code_object

lib/rdoc/parser/c.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,15 +1097,34 @@ def load_variable_map map_name
10971097
# */
10981098
#
10991099
# This method modifies the +comment+
1100+
# Both :main: and :title: directives are deprecated and will be removed in RDoc 7.
11001101

11011102
def look_for_directives_in context, comment
11021103
@preprocess.handle comment, context do |directive, param|
11031104
case directive
11041105
when 'main' then
11051106
@options.main_page = param
1107+
1108+
warn <<~MSG
1109+
The :main: directive is deprecated and will be removed in RDoc 7.
1110+
1111+
You can use these options to specify the initial page displayed instead:
1112+
- `--main=#{param}` via the command line
1113+
- `rdoc.main = "#{param}"` if you use `RDoc::Task`
1114+
- `main_page: #{param}` in your `.rdoc_options` file
1115+
MSG
11061116
''
11071117
when 'title' then
11081118
@options.default_title = param if @options.respond_to? :default_title=
1119+
1120+
warn <<~MSG
1121+
The :title: directive is deprecated and will be removed in RDoc 7.
1122+
1123+
You can use these options to specify the title displayed instead:
1124+
- `--title=#{param}` via the command line
1125+
- `rdoc.title = "#{param}"` if you use `RDoc::Task`
1126+
- `title: #{param}` in your `.rdoc_options` file
1127+
MSG
11091128
''
11101129
end
11111130
end

lib/rdoc/rdoc.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ def parse_files files
407407

408408
return [] if file_list.empty?
409409

410+
# This workaround can be removed after the :main: directive is removed
410411
original_options = @options.dup
411412
@stats.begin_adding
412413

test/rdoc/test_rdoc_markup_pre_process.rb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require_relative 'helper'
44

5-
class TestRDocMarkupPreProcess < RDoc::TestCase
5+
class RDoc::Markup::PreProcessTest < RDoc::TestCase
66

77
def setup
88
super
@@ -85,18 +85,26 @@ def test_include_file_in_other_directory
8585

8686
def test_handle
8787
text = "# :main: M\n"
88-
out = @pp.handle text
88+
output = nil
89+
_, err = capture_output do
90+
output = @pp.handle text
91+
end
8992

90-
assert_equal "#\n", out
93+
assert_include err, "The :main: directive is deprecated and will be removed in RDoc 7."
94+
assert_equal "#\n", output
9195
end
9296

9397
def test_handle_comment
9498
text = "# :main: M\n"
9599
c = comment text
96100

97-
out = @pp.handle c
101+
output = nil
102+
_, err = capture_output do
103+
output = @pp.handle c
104+
end
98105

99-
assert_equal "#\n", out
106+
assert_include err, "The :main: directive is deprecated and will be removed in RDoc 7."
107+
assert_equal "#\n", output
100108
end
101109

102110
def test_handle_markup
@@ -245,8 +253,11 @@ def test_handle_directive_include
245253
def test_handle_directive_main
246254
@pp.options = RDoc::Options.new
247255

248-
@pp.handle_directive '', 'main', 'M'
256+
_, err = capture_output do
257+
@pp.handle_directive '', 'main', 'M'
258+
end
249259

260+
assert_include err, "The :main: directive is deprecated and will be removed in RDoc 7."
250261
assert_equal 'M', @pp.options.main_page
251262
end
252263

@@ -385,8 +396,11 @@ def test_handle_directive_stopdoc
385396
def test_handle_directive_title
386397
@pp.options = RDoc::Options.new
387398

388-
@pp.handle_directive '', 'title', 'T'
399+
_, err = capture_output do
400+
@pp.handle_directive '', 'title', 'T'
401+
end
389402

403+
assert_include err, "The :title: directive is deprecated and will be removed in RDoc 7."
390404
assert_equal 'T', @pp.options.title
391405
end
392406

0 commit comments

Comments
 (0)