Skip to content

Deprecate main and title directives #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions doc/rdoc/markup_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,6 @@
# parameter +type+ is one of: +rdoc+ (the default), +markdown+, +rd+, +tomdoc+.
# See {Markup Formats}[rdoc-ref:RDoc::Markup@Markup+Formats].
#
# ===== Directives for HTML Output
#
# - <tt># :title: _text_</tt>:
#
# - Appears on a line by itself.
# - Specifies the title for the HTML output.
#
# - <tt># :main: _filename_</tt>:
# - Appears on a line by itself.
# - Specifies the HTML file to be displayed first.
#
# ===== Directives for Method Documentation
#
# - <tt># :call-seq:</tt>:
Expand Down
2 changes: 0 additions & 2 deletions lib/rdoc.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true
$DEBUG_RDOC = nil

# :main: README.rdoc

##
# RDoc produces documentation for Ruby source files by parsing the source and
# extracting the definition for classes, modules, methods, includes and
Expand Down
17 changes: 17 additions & 0 deletions lib/rdoc/markup/pre_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ def handle_directive prefix, directive, param, code_object = nil,
include_file filename, prefix, encoding
when 'main' then
@options.main_page = param if @options.respond_to? :main_page
warn <<~MSG
The :main: directive is deprecated and will be removed in RDoc 7.

You can use these options to specify the initial page displayed instead:
- `--main=#{param}` via the command line
- `rdoc.main = "#{param}"` if you use `RDoc::Task`
- `main_page: #{param}` in your `.rdoc_options` file
MSG

blankline
when 'nodoc' then
Expand Down Expand Up @@ -217,6 +225,15 @@ def handle_directive prefix, directive, param, code_object = nil,
when 'title' then
@options.default_title = param if @options.respond_to? :default_title=

warn <<~MSG
The :title: directive is deprecated and will be removed in RDoc 7.

You can use these options to specify the title displayed instead:
- `--title=#{param}` via the command line
- `rdoc.title = "#{param}"` if you use `RDoc::Task`
- `title: #{param}` in your `.rdoc_options` file
MSG

blankline
when 'yield', 'yields' then
return blankline unless code_object
Expand Down
19 changes: 19 additions & 0 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1097,15 +1097,34 @@ def load_variable_map map_name
# */
#
# This method modifies the +comment+
# Both :main: and :title: directives are deprecated and will be removed in RDoc 7.

def look_for_directives_in context, comment
@preprocess.handle comment, context do |directive, param|
case directive
when 'main' then
@options.main_page = param

warn <<~MSG
The :main: directive is deprecated and will be removed in RDoc 7.

You can use these options to specify the initial page displayed instead:
- `--main=#{param}` via the command line
- `rdoc.main = "#{param}"` if you use `RDoc::Task`
- `main_page: #{param}` in your `.rdoc_options` file
MSG
''
when 'title' then
@options.default_title = param if @options.respond_to? :default_title=

warn <<~MSG
The :title: directive is deprecated and will be removed in RDoc 7.

You can use these options to specify the title displayed instead:
- `--title=#{param}` via the command line
- `rdoc.title = "#{param}"` if you use `RDoc::Task`
- `title: #{param}` in your `.rdoc_options` file
MSG
''
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def parse_files files

return [] if file_list.empty?

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

Expand Down
28 changes: 21 additions & 7 deletions test/rdoc/test_rdoc_markup_pre_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_relative 'helper'

class TestRDocMarkupPreProcess < RDoc::TestCase
class RDoc::Markup::PreProcessTest < RDoc::TestCase

def setup
super
Expand Down Expand Up @@ -85,18 +85,26 @@ def test_include_file_in_other_directory

def test_handle
text = "# :main: M\n"
out = @pp.handle text
output = nil
_, err = capture_output do
output = @pp.handle text
end

assert_equal "#\n", out
assert_include err, "The :main: directive is deprecated and will be removed in RDoc 7."
assert_equal "#\n", output
end

def test_handle_comment
text = "# :main: M\n"
c = comment text

out = @pp.handle c
output = nil
_, err = capture_output do
output = @pp.handle c
end

assert_equal "#\n", out
assert_include err, "The :main: directive is deprecated and will be removed in RDoc 7."
assert_equal "#\n", output
end

def test_handle_markup
Expand Down Expand Up @@ -245,8 +253,11 @@ def test_handle_directive_include
def test_handle_directive_main
@pp.options = RDoc::Options.new

@pp.handle_directive '', 'main', 'M'
_, err = capture_output do
@pp.handle_directive '', 'main', 'M'
end

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

Expand Down Expand Up @@ -385,8 +396,11 @@ def test_handle_directive_stopdoc
def test_handle_directive_title
@pp.options = RDoc::Options.new

@pp.handle_directive '', 'title', 'T'
_, err = capture_output do
@pp.handle_directive '', 'title', 'T'
end

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

Expand Down