Skip to content

Commit 722abfd

Browse files
committed
Added --markup command line option to set default format.
Fixed parsing of ClassModule comment_location RDoc::RDoc.current is set for the entire run.
1 parent 8b3c861 commit 722abfd

File tree

11 files changed

+120
-14
lines changed

11 files changed

+120
-14
lines changed

History.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* TomDoc 1.0.0-pre
1313
* RD format
1414

15+
The default format can be set via the <tt>--markup</tt> option.
16+
1517
The format of documentation in a particular file can be specified by the
1618
+:markup:+ directive. If the :markup: directive is in the first comment
1719
it is used as the default for the entire file. For other comments it
@@ -43,6 +45,7 @@
4345
* Added RDoc::Comment which encapsulates comment-handling functionality.
4446
* Added RDoc::Markup::PreProcess::post_process to allow arbitrary comment
4547
munging.
48+
* RDoc::RDoc::current is set for the entire RDoc run.
4649

4750
* Bug fixes
4851
* Markup defined by RDoc::Markup#add_special inside a <tt><tt></tt> is no

lib/rdoc/class_module.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def parse comment_location
451451

452452
RDoc::Markup::Document.new(*docs)
453453
when RDoc::Comment then
454-
doc = super comment_location.text
454+
doc = super comment_location.text, comment_location.format
455455
doc.file = comment_location.location.absolute_name
456456
doc
457457
when RDoc::Markup::Document then

lib/rdoc/generator/markup.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ def markup_code
159159

160160
end
161161

162+
class RDoc::ClassModule
163+
164+
##
165+
# Handy wrapper for marking up this class or module's comment
166+
167+
def description
168+
markup @comment_location
169+
end
170+
171+
end
172+
162173
class RDoc::Context::Section
163174

164175
include RDoc::Generator::Markup

lib/rdoc/options.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class RDoc::Options
9696

9797
attr_accessor :main_page
9898

99+
##
100+
# The default markup format. The default is 'rdoc'. 'tomdoc' and 'rd' are
101+
# also built-in.
102+
103+
attr_accessor :markup
104+
99105
##
100106
# If true, only report on undocumented files
101107

@@ -180,6 +186,7 @@ def initialize # :nodoc:
180186
@hyperlink_all = false
181187
@line_numbers = false
182188
@main_page = nil
189+
@markup = 'rdoc'
183190
@coverage_report = false
184191
@op_dir = nil
185192
@pipe = false
@@ -448,6 +455,17 @@ def parse(argv)
448455
@visibility = value
449456
end
450457

458+
opt.separator nil
459+
460+
markup_formats = RDoc::Text::MARKUP_FORMAT.keys.sort
461+
462+
opt.on("--markup=MARKUP", markup_formats,
463+
"The markup format for the named files.",
464+
"The default is rdoc. Valid values are:",
465+
markup_formats.join(', ')) do |value|
466+
@markup = value
467+
end
468+
451469
opt.separator nil
452470
opt.separator "Common generator options:"
453471
opt.separator nil

lib/rdoc/parser/ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def initialize(top_level, file_name, content, options, stats)
164164
@scanner = RDoc::RubyLex.new content, @options
165165
@scanner.exception_on_syntax_error = false
166166
@prev_seek = nil
167-
@markup = 'rdoc'
167+
@markup = @options.markup
168168

169169
@encoding = nil
170170
@encoding = @options.encoding if Object.const_defined? :Encoding

lib/rdoc/rdoc.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def self.current
8585
##
8686
# Sets the active RDoc::RDoc instance
8787

88-
def self.current=(rdoc)
88+
def self.current= rdoc
8989
@current = rdoc
9090
end
9191

@@ -95,6 +95,7 @@ def self.current=(rdoc)
9595
def self.reset
9696
RDoc::TopLevel.reset
9797
RDoc::Parser::C.reset
98+
RDoc::RDoc.current = nil
9899
end
99100

100101
##
@@ -398,6 +399,7 @@ def remove_unparseable files
398399

399400
def document options
400401
RDoc::RDoc.reset
402+
RDoc::RDoc.current = self
401403

402404
if RDoc::Options === options then
403405
@options = options
@@ -457,18 +459,12 @@ def document options
457459

458460
def generate file_info
459461
Dir.chdir @options.op_dir do
460-
begin
461-
self.class.current = self
462-
463-
unless @options.quiet then
464-
$stderr.puts "\nGenerating #{@generator.class.name.sub(/^.*::/, '')} format into #{Dir.pwd}..."
465-
end
466-
467-
@generator.generate file_info
468-
update_output_dir '.', @start_time, @last_modified
469-
ensure
470-
self.class.current = nil
462+
unless @options.quiet then
463+
$stderr.puts "\nGenerating #{@generator.class.name.sub(/^.*::/, '')} format into #{Dir.pwd}..."
471464
end
465+
466+
@generator.generate file_info
467+
update_output_dir '.', @start_time, @last_modified
472468
end
473469
end
474470

test/test_rdoc_class_module.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,19 @@ def test_parse_comment
580580
assert_equal doc, cm.parse(cm.comment)
581581
end
582582

583+
def test_parse_comment_format
584+
tl1 = RDoc::TopLevel.new 'one.rb'
585+
586+
cm = RDoc::ClassModule.new 'Klass'
587+
cm.comment = comment 'comment ((*1*))', tl1
588+
cm.comment.format = 'rd'
589+
590+
doc = @RM::Document.new @RM::Paragraph.new 'comment <em>1</em>'
591+
doc.file = tl1.absolute_name
592+
593+
assert_equal doc, cm.parse(cm.comment)
594+
end
595+
583596
def test_parse_comment_location
584597
tl1 = RDoc::TopLevel.new 'one.rb'
585598
tl2 = RDoc::TopLevel.new 'two.rb'

test/test_rdoc_options.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ def test_parse_main
285285
assert_equal 'MAIN', @options.main_page
286286
end
287287

288+
def test_parse_markup
289+
out, err = capture_io do
290+
@options.parse %w[--markup tomdoc]
291+
end
292+
293+
assert_empty out
294+
assert_empty err
295+
296+
assert_equal 'tomdoc', @options.markup
297+
end
298+
288299
def test_parse_template
289300
out, err = capture_io do
290301
@options.parse %w[--template darkfish]

test/test_rdoc_rdoc.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def setup
1313
end
1414

1515
def test_class_reset
16+
RDoc::RDoc.current = :junk
17+
1618
tl = RDoc::TopLevel.new 'file.rb'
1719
tl.add_class RDoc::NormalClass, 'C'
1820
tl.add_class RDoc::NormalModule, 'M'
@@ -25,6 +27,8 @@ def test_class_reset
2527

2628
RDoc::RDoc.reset
2729

30+
assert_nil RDoc::RDoc.current
31+
2832
assert_empty RDoc::TopLevel.all_classes_hash
2933
assert_empty RDoc::TopLevel.all_files_hash
3034
assert_empty RDoc::TopLevel.all_modules_hash

test/test_rdoc_tom_doc.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,32 @@ def test_parse_arguments_multiline
9292
assert_equal expected, @TD.parse(text)
9393
end
9494

95+
def test_parse_arguments_nested
96+
text = <<-TEXT
97+
Do some stuff
98+
99+
foo - A comment goes here
100+
:bar - bar documentation
101+
TEXT
102+
103+
expected =
104+
@RM::Document.new(
105+
@RM::Paragraph.new('Do some stuff'),
106+
@RM::BlankLine.new,
107+
@RM::List.new(
108+
:LABEL,
109+
@RM::ListItem.new(
110+
'foo',
111+
@RM::Paragraph.new('A comment goes here'),
112+
@RM::List.new(
113+
:LABEL,
114+
@RM::ListItem.new(
115+
':bar',
116+
@RM::Paragraph.new('bar documentation'))))))
117+
118+
assert_equal expected, @TD.parse(text)
119+
end
120+
95121
def test_parse_examples
96122
text = <<-TEXT
97123
Do some stuff
@@ -201,6 +227,29 @@ def test_tokenize_arguments_multiline
201227
assert_equal expected, @td.tokens
202228
end
203229

230+
def test_tokenize_arguments_nested
231+
@td.tokenize <<-TEXT
232+
Do some stuff
233+
234+
foo - A comment goes here
235+
:bar - bar documentation
236+
TEXT
237+
238+
expected = [
239+
[:TEXT, "Do some stuff", 0, 0],
240+
[:NEWLINE, "\n", 13, 0],
241+
[:NEWLINE, "\n", 0, 1],
242+
[:LABEL, "foo", 0, 2],
243+
[:TEXT, "A comment goes here", 6, 2],
244+
[:NEWLINE, "\n", 25, 2],
245+
[:LABEL, ":bar", 6, 3],
246+
[:TEXT, "bar documentation", 13, 3],
247+
[:NEWLINE, "\n", 30, 3],
248+
]
249+
250+
assert_equal expected, @td.tokens
251+
end
252+
204253
def test_tokenize_examples
205254
@td.tokenize <<-TEXT
206255
Do some stuff

0 commit comments

Comments
 (0)