Class: RDocF95::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc-f95/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generators = {}) ⇒ Options

:nodoc:



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/rdoc-f95/options.rb', line 166

def initialize(generators = {}) # :nodoc:
  @op_dir = "doc"
  @op_name = nil
  @show_all = false
  @main_page = nil
  @merge = false
  @exclude = []
  @generators = generators
  @generator_name = 'html'
  @generator = @generators[@generator_name]
  @rdoc_include = []
  @title = nil
  @template = nil
  @template_class = nil
  @diagram = false
  @fileboxes = false
  @show_hash = false
  @image_format = 'png'
  @inline_source = false
  @all_one_file = false
  @tab_width = 8
  @include_line_numbers = false
  @extra_accessor_flags = {}
  @promiscuous = false
  @force_update = false
  @verbosity = 1

  @mathml = false
  @ignore_case = false

  @css = nil
  @webcvs = nil

  @charset = 'utf-8'
end

Instance Attribute Details

#all_one_fileObject (readonly)

Should the output be placed into a single file



13
14
15
# File 'lib/rdoc-f95/options.rb', line 13

def all_one_file
  @all_one_file
end

#charsetObject (readonly)

Character-set



18
19
20
# File 'lib/rdoc-f95/options.rb', line 18

def charset
  @charset
end

#cssObject (readonly)

URL of stylesheet



23
24
25
# File 'lib/rdoc-f95/options.rb', line 23

def css
  @css
end

#diagramObject (readonly)

Should diagrams be drawn



28
29
30
# File 'lib/rdoc-f95/options.rb', line 28

def diagram
  @diagram
end

#excludeObject

Files matching this pattern will be excluded



33
34
35
# File 'lib/rdoc-f95/options.rb', line 33

def exclude
  @exclude
end

#extra_accessor_flagsObject (readonly)

Additional attr_… style method flags



38
39
40
# File 'lib/rdoc-f95/options.rb', line 38

def extra_accessor_flags
  @extra_accessor_flags
end

#extra_accessorsObject

Pattern for additional attr_… style methods



43
44
45
# File 'lib/rdoc-f95/options.rb', line 43

def extra_accessors
  @extra_accessors
end

#fileboxesObject (readonly)

Should we draw fileboxes in diagrams



48
49
50
# File 'lib/rdoc-f95/options.rb', line 48

def fileboxes
  @fileboxes
end

#filesObject

The list of files to be processed



53
54
55
# File 'lib/rdoc-f95/options.rb', line 53

def files
  @files
end

#force_updateObject (readonly)

Scan newer sources than the flag file if true.



58
59
60
# File 'lib/rdoc-f95/options.rb', line 58

def force_update
  @force_update
end

#formatterObject

Formatter to mark up text with



72
73
74
# File 'lib/rdoc-f95/options.rb', line 72

def formatter
  @formatter
end

#generatorObject

Description of the output generator (set with the -fmt option)



63
64
65
# File 'lib/rdoc-f95/options.rb', line 63

def generator
  @generator
end

#ignore_caseObject (readonly)

The case of names of classes or modules or methods are ignored



67
68
69
# File 'lib/rdoc-f95/options.rb', line 67

def ignore_case
  @ignore_case
end

#image_formatObject (readonly)

image format for diagrams



77
78
79
# File 'lib/rdoc-f95/options.rb', line 77

def image_format
  @image_format
end

#include_line_numbersObject (readonly)

Include line numbers in the source listings



82
83
84
# File 'lib/rdoc-f95/options.rb', line 82

def include_line_numbers
  @include_line_numbers
end

#inline_sourceObject

Should source code be included inline, or displayed in a popup



87
88
89
# File 'lib/rdoc-f95/options.rb', line 87

def inline_source
  @inline_source
end

#main_pageObject

Name of the file, class or module to display in the initial index page (if not specified the first file we encounter is used)



93
94
95
# File 'lib/rdoc-f95/options.rb', line 93

def main_page
  @main_page
end

#mathmlObject (readonly)

TeX formatted formula is converted to MathML



97
98
99
# File 'lib/rdoc-f95/options.rb', line 97

def mathml
  @mathml
end

#mergeObject (readonly)

Merge into classes of the same name when generating ri



102
103
104
# File 'lib/rdoc-f95/options.rb', line 102

def merge
  @merge
end

#op_dirObject

The name of the output directory



107
108
109
# File 'lib/rdoc-f95/options.rb', line 107

def op_dir
  @op_dir
end

#op_nameObject

The name to use for the output



112
113
114
# File 'lib/rdoc-f95/options.rb', line 112

def op_name
  @op_name
end

#promiscuousObject (readonly)

Are we promiscuous about showing module contents across multiple files



117
118
119
# File 'lib/rdoc-f95/options.rb', line 117

def promiscuous
  @promiscuous
end

#rdoc_includeObject (readonly)

Array of directories to search for files to satisfy an :include:



122
123
124
# File 'lib/rdoc-f95/options.rb', line 122

def rdoc_include
  @rdoc_include
end

#show_allObject

Include private and protected methods in the output



127
128
129
# File 'lib/rdoc-f95/options.rb', line 127

def show_all
  @show_all
end

#show_hashObject (readonly)

Include the ‘#’ at the front of hyperlinked instance method names



132
133
134
# File 'lib/rdoc-f95/options.rb', line 132

def show_hash
  @show_hash
end

#tab_widthObject (readonly)

The number of columns in a tab



137
138
139
# File 'lib/rdoc-f95/options.rb', line 137

def tab_width
  @tab_width
end

#templateObject (readonly)

template to be used when generating output



142
143
144
# File 'lib/rdoc-f95/options.rb', line 142

def template
  @template
end

#template_classObject

Template class for file generation – HACK around dependencies in lib/rdoc-f95/generator/html.rb



149
150
151
# File 'lib/rdoc-f95/options.rb', line 149

def template_class
  @template_class
end

#titleObject

Documentation title



154
155
156
# File 'lib/rdoc-f95/options.rb', line 154

def title
  @title
end

#verbosityObject

Verbosity, zero means quiet



159
160
161
# File 'lib/rdoc-f95/options.rb', line 159

def verbosity
  @verbosity
end

#webcvsObject (readonly)

URL of web cvs frontend



164
165
166
# File 'lib/rdoc-f95/options.rb', line 164

def webcvs
  @webcvs
end

Instance Method Details

#parse(argv) ⇒ Object

Parse command line options.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/rdoc-f95/options.rb', line 205

def parse(argv)
  accessors = []

  opts = OptionParser.new do |opt|
    opt.program_name = File.basename $0
    opt.version = RDocF95::VERSION
    opt.release = nil
    opt.summary_indent = ' ' * 4
    opt.banner = <<-EOF
Usage: #{opt.program_name} [options] [names...]

Files are parsed, and the information they contain collected, before any
output is produced. This allows cross references between all files to be
resolved. If a name is a directory, it is traversed. If no names are
specified, all Ruby files in the current directory (and subdirectories) are
processed.

How RDoc generates output depends on the output formatter being used, and on
the options you give.

- HTML output is normally produced into a number of separate files
  (one per class, module, and file, along with various indices).
  These files will appear in the directory given by the --op
  option (doc/ by default).

- XHTML output is the same as HTML. 

- XML output by default is written to standard output. If a
  --opname option is given, the output will instead be written
  to a file with that name in the output directory.

- .chm files (Windows help files) are written in the --op directory.
  If an --opname parameter is present, that name is used, otherwise
  the file will be called rdoc.chm.
    EOF

#      opt.separator nil  # 1.8.2 doesn't work
    opt.separator "Options:"
#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--accessor=ACCESSORS", "-A", Array,
           "A comma separated list of additional class",
           "methods that should be treated like",
           "'attr_reader' and friends.",
           " ",
           "Option may be repeated.",
           " ",
           "Each accessorname may have '=text'",
           "appended, in which case that text appears",
           "where the r/w/rw appears for normal.",
           "accessors") do |value|
      value.each do |accessor|
        if accessor =~ /^(\w+)(=(.*))?$/
          accessors << $1
          @extra_accessor_flags[$1] = $3
        end
      end
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--all", "-a",
           "Include all methods (not just public) in",
           "the output.") do |value|
      @show_all = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--charset=CHARSET", "-c",
           "Specifies the output HTML character-set.") do |value|
      @charset = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--debug", "-D",
           "Displays lots on internal stuff.") do |value|
      $DEBUG_RDOC = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--diagram", "-d",
           "Generate diagrams showing modules and",
           "classes. You need dot V1.8.6 or later to",
           "use the --diagram option correctly. Dot is",
           "available from http://graphviz.org") do |value|
      check_diagram
      @diagram = true
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--exclude=PATTERN", "-x", Regexp,
           "Do not process files or directories",
           "matching PATTERN.") do |value|
      @exclude << value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--extension=NEW=OLD", "-E",
           "Treat files ending with .new as if they",
           "ended with .old. Using '-E cgi=rb' will",
           "cause xxx.cgi to be parsed as a Ruby file.") do |value|
      new, old = value.split(/=/, 2)

      unless new and old then
        raise OptionParser::InvalidArgument, "Invalid parameter to '-E'"
      end

      unless RDocF95::ParserFactory.alias_extension old, new then
        raise OptionParser::InvalidArgument, "Unknown extension .#{old} to -E"
      end
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--fileboxes", "-F",
           "Classes are put in boxes which represents",
           "files, where these classes reside. Classes",
           "shared between more than one file are",
           "shown with list of files that are sharing",
           "them. Silently discarded if --diagram is",
           "not given.") do |value|
      @fileboxes = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--force-update", "-U",
           "Forces rdoc to scan all sources even if",
           "newer than the flag file.") do |value|
      @force_update = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--fmt=FORMAT", "--format=FORMAT", "-f", @generators.keys,
           "Set the output formatter.") do |value|
      @generator_name = value.downcase
      setup_generator
    end

#      opt.separator nil  # 1.8.2 doesn't work

    image_formats = %w[gif png jpg jpeg]
    opt.on("--image-format=FORMAT", "-I", image_formats,
           "Sets output image format for diagrams. Can",
           "be #{image_formats.join ', '}. If this option",
           "is omitted, png is used. Requires",
           "diagrams.") do |value|
      @image_format = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--include=DIRECTORIES", "-i", Array,
           "set (or add to) the list of directories to",
           "be searched when satisfying :include:",
           "requests. Can be used more than once.") do |value|
      @rdoc_include.concat value.map { |dir| dir.strip }
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--inline-source", "-S",
           "Show method source code inline, rather than",
           "via a popup link.") do |value|
      @inline_source = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--line-numbers", "-N",
           "Include line numbers in the source code.") do |value|
      @include_line_numbers = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--main=NAME", "-m",
           "NAME will be the initial page displayed.") do |value|
      @main_page = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--merge", "-M",
           "When creating ri output, merge previously",
           "processed classes into previously",
           "documented classes of the same name.") do |value|
      @merge = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--one-file", "-1",
           "Put all the output into a single file.") do |value|
      @all_one_file = value
      @inline_source = value if value
      @template = 'one_page_html'
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--op=DIR", "-o",
           "Set the output directory.") do |value|
      if @css && ! (%r{^(https?:/)?/} =~ @css)
        @css = relative_str(File.join(value, "."),
                            relative_str(File.join(@op_dir.split("/").fill(".."), ".."), @css))
      end
      @op_dir = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--opname=NAME", "-n",
           "Set the NAME of the output. Has no effect",
           "for HTML.") do |value|
      @op_name = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--promiscuous", "-p",
           "When documenting a file that contains a",
           "module or class also defined in other",
           "files, show all stuff for that module or",
           "class in each files page. By default, only",
           "show stuff defined in that particular file.") do |value|
      @promiscuous = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--quiet", "-q",
           "Don't show progress as we parse.") do |value|
      @verbosity = 0
    end

    opt.on("--verbose", "-v",
           "Display extra progress as we parse.") do |value|
      @verbosity = 2
    end


#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--ri", "-r",
           "Generate output for use by `ri`. The files",
           "are stored in the '.rdoc' directory under",
           "your home directory unless overridden by a",
           "subsequent --op parameter, so no special",
           "privileges are needed.") do |value|
      @generator_name = "ri"
      @op_dir = RDocF95::RI::Paths::HOMEDIR
      setup_generator
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--ri-site", "-R",
           "Generate output for use by `ri`. The files",
           "are stored in a site-wide directory,",
           "making them accessible to others, so",
           "special privileges are needed.") do |value|
      @generator_name = "ri"
      @op_dir = RDocF95::RI::Paths::SITEDIR
      setup_generator
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--ri-system", "-Y",
           "Generate output for use by `ri`. The files",
           "are stored in a site-wide directory,",
           "making them accessible to others, so",
           "special privileges are needed.  This",
           "option is intended to be used during Ruby",
           "installation.") do |value|
      @generator_name = "ri"
      @op_dir = RDocF95::RI::Paths::SYSDIR
      setup_generator
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--show-hash", "-H",
           "A name of the form #name in a comment is a",
           "possible hyperlink to an instance method",
           "name. When displayed, the '#' is removed",
           "unless this option is specified.") do |value|
      @show_hash = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--style=URL", "-s",
           "Specifies the URL of a separate stylesheet.") do |value|
      if %r{^(https?:/)?/} =~ value
        @css = value
      else
        @css = relative_str(File.join(@op_dir, "."), value)
      end
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--tab-width=WIDTH", "-w", OptionParser::DecimalInteger,
           "Set the width of tab characters.") do |value|
      @tab_width = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--template=NAME", "-T",
           "Set the template used when generating",
           "output.") do |value|
      @template = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--title=TITLE", "-t",
           "Set TITLE as the title for HTML output.") do |value|
      @title = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--webcvs=URL", "-W",
           "Specify a URL for linking to a web frontend",
           "to CVS. If the URL contains a '\%s', the",
           "name of the current file will be",
           "substituted; if the URL doesn't contain a",
           "'\%s', the filename will be appended to it.") do |value|
      @webcvs = value
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--mathml", "-l",
           "TeX formatted formula is converted to MathML.", 
           "You need mathml.rb V0.8 or later to use the --mathml", 
           "option correctly. mathml.rb V0.8 is available from", 
           "http://www.hinet.mydns.jp/files/math_ml-0.8.0.tar.gz") do |value|
      check_mathml
      @mathml = true
      @generator_name = 'xhtml'
      @template = @generator_name
      setup_generator
    end

#      opt.separator nil  # 1.8.2 doesn't work

    opt.on("--ignore-case", "-C",
           "The case of names of classes or modules", 
           "or methods are ignored.") do |value|
      @ignore_case = true
    end
  end

  argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']

  opts.parse! argv

  @files = argv.dup

  @rdoc_include << "." if @rdoc_include.empty?

  if @exclude.empty? then
    @exclude = nil
  else
    @exclude = Regexp.new(@exclude.join("|"))
  end

  check_files

  # If no template was specified, use the default template for the output
  # formatter

  @template ||= @generator_name

  # Generate a regexp from the accessors
  unless accessors.empty? then
    re = '^(' + accessors.map { |a| Regexp.quote a }.join('|') + ')$'
    @extra_accessors = Regexp.new re
  end

rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
  puts opts
  puts
  puts e
  exit 1
end

#quietObject

Don’t display progress as we process the files



614
615
616
# File 'lib/rdoc-f95/options.rb', line 614

def quiet
  @verbosity.zero?
end

#quiet=(bool) ⇒ Object



618
619
620
# File 'lib/rdoc-f95/options.rb', line 618

def quiet=(bool)
  @verbosity = bool ? 0 : 1
end