| Class | Options |
| In: |
options.rb
|
| Parent: | Object |
| all_one_file | [R] | should the output be placed into a single file |
| charset | [R] | character-set |
| css | [R] | URL of stylesheet |
| diagram | [R] | should diagrams be drawn |
| exclude | [RW] | files matching this pattern will be excluded |
| extra_accessor_flags | [R] | |
| extra_accessors | [R] | pattern for additional attr_... style methods |
| fileboxes | [R] | should we draw fileboxes in diagrams |
| files | [R] | and the list of files to be processed |
| generator | [RW] | description of the output generator (set with the -fmt option |
| ignore_case | [R] | The case of names of classes or modules or methods are ignored |
| image_format | [R] | image format for diagrams |
| include_line_numbers | [R] | include line numbers in the source listings |
| inline_source | [R] | should source code be included inline, or displayed in a popup |
| main_page | [RW] | name of the file, class or module to display in the initial index page (if not specified the first file we encounter is used) |
| mathml | [R] | TeX formatted formula is converted to MathML |
| merge | [R] | merge into classes of the name name when generating ri |
| op_dir | [RW] | the name of the output directory |
| op_name | [R] | the name to use for the output |
| promiscuous | [R] | Are we promiscuous about showing module contents across multiple files |
| quiet | [R] | Don‘t display progress as we process the files |
| rdoc_include | [R] | array of directories to search for files to satisfy an :include: |
| show_all | [RW] | include private and protected methods in the output |
| show_hash | [R] | include the ’#’ at the front of hyperlinked instance method names |
| tab_width | [R] | the number of columns in a tab |
| template | [R] | template to be used when generating output |
| webcvs | [R] | URL of web cvs frontend |
Check that the right version of ‘dot’ is available. Unfortuately this doesn‘t work correctly under Windows NT, so we‘ll bypass the test under Windows
# File options.rb, line 578
578: def check_diagram
579: return if RUBY_PLATFORM =~ /win/
580:
581: ok = false
582: ver = nil
583: IO.popen("dot -V 2>&1") do |io|
584: ver = io.read
585: if ver =~ /dot\s+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
586: ok = ($1.to_i > 1) || ($1.to_i == 1 && $2.to_i >= 8)
587: end
588: end
589: unless ok
590: if ver =~ /^dot version/
591: $stderr.puts "Warning: You may need dot V1.8.6 or later to use\n",
592: "the --diagram option correctly. You have:\n\n ",
593: ver,
594: "\nDiagrams might have strange background colors.\n\n"
595: else
596: $stderr.puts "You need the 'dot' program to produce diagrams.",
597: "(see http://www.research.att.com/sw/tools/graphviz/)\n\n"
598: exit
599: end
600: # exit
601: end
602: end
Check that the files on the command line exist
# File options.rb, line 650
650: def check_files
651: @files.each do |f|
652: stat = File.stat f rescue error("File not found: #{f}")
653: error("File '#{f}' not readable") unless stat.readable?
654: end
655: end
Check that the right version of ‘mathml.rb’ is available.
# File options.rb, line 606
606: def check_mathml
607: not_found = true
608: fpath = ""
609: $LOAD_PATH.each{ |lpath|
610: fpath = File.join(lpath, "mathml.rb")
611: if File.exist?(fpath)
612: not_found = false
613: break
614: end
615: }
616:
617: if not_found
618: $stderr.puts "You need the 'mathml.rb' to convert TeX to MathML.\n(see http://www.hinet.mydns.jp/~hiraku/hiki/, but JAPANESE only.\nYou can download 'mathml.rb' directly from\nhttp://www.hinet.mydns.jp/~hiraku/data/files/mathml-0.5.tar.gz)\n\n"
619: exit
620: end
621:
622: contents = File.open(fpath, "r") {|f| f.read}
623: num = 1
624: if !(contents =~ /^\s*module\s+MathML/) ||
625: !(contents =~ /^\s*module\s+LaTeX/) ||
626: !(contents =~ /^\s*class\s+Parser/) ||
627: !(contents =~ /^\s*def\s+parse/)
628: $stderr.puts "You need the 'mathml.rb' V0.5 or later to use.\n(see http://www.hinet.mydns.jp/~hiraku/hiki/, but JAPANESE only.\nYou can download 'mathml.rb' directly from\nhttp://www.hinet.mydns.jp/~hiraku/data/files/mathml-0.5.tar.gz)\n\n"
629:
630: exit
631: end
632: end
Parse command line options. We‘re passed a hash containing output generators, keyed by the generator name
# File options.rb, line 361
361: def parse(argv, generators)
362: old_argv = ARGV.dup
363: begin
364: ARGV.replace(argv)
365: @op_dir = "doc"
366: @op_name = nil
367: @show_all = false
368: @main_page = nil
369: @marge = false
370: @exclude = []
371: @quiet = false
372: @generator_name = 'html'
373: @generator = generators[@generator_name]
374: @rdoc_include = []
375: @title = nil
376: @template = nil
377: @diagram = false
378: @mathml = false
379: @fileboxes = false
380: @show_hash = false
381: @image_format = 'png'
382: @inline_source = false
383: @all_one_file = false
384: @tab_width = 8
385: @include_line_numbers = false
386: @extra_accessor_flags = {}
387: @promiscuous = false
388: @ignore_case = false
389:
390: @css = nil
391: @webcvs = nil
392:
393: @charset = case $KCODE
394: when /^S/i
395: 'Shift_JIS'
396: when /^E/i
397: 'EUC-JP'
398: else
399: 'iso-8859-1'
400: end
401:
402: accessors = []
403:
404: go = GetoptLong.new(*OptionList.options)
405: go.quiet = true
406:
407: go.each do |opt, arg|
408: case opt
409: when "--all" then @show_all = true
410: when "--charset" then @charset = arg
411: when "--debug" then $DEBUG = true
412: when "--exclude" then @exclude << Regexp.new(arg)
413: when "--inline-source" then @inline_source = true
414: when "--line-numbers" then @include_line_numbers = true
415: when "--main" then @main_page = arg
416: when "--merge" then @merge = true
417: when "--one-file" then @all_one_file = @inline_source = true
418: when "--opname" then @op_name = arg
419: when "--promiscuous" then @promiscuous = true
420: when "--quiet" then @quiet = true
421: when "--show-hash" then @show_hash = true
422: when "--template" then @template = arg
423: when "--title" then @title = arg
424: when "--webcvs" then @webcvs = arg
425: when "--ignore-case" then @ignore_case = true
426:
427: when "--op"
428: if @css && ! (%r{^(https?:/)?/} =~ @css)
429: @css = relative_str(File.join(arg, "."),
430: relative_str(File.join(@op_dir.split("/").fill(".."), ".."), @css))
431: end
432: @op_dir = arg
433:
434: when "--style"
435: if %r{^(https?:/)?/} =~ arg
436: @css = arg
437: else
438: @css = relative_str(File.join(@op_dir, "."), arg)
439: end
440:
441: when "--accessor"
442: arg.split(/,/).each do |accessor|
443: if accessor =~ /^(\w+)(=(.*))?$/
444: accessors << $1
445: @extra_accessor_flags[$1] = $3
446: end
447: end
448:
449: when "--diagram"
450: check_diagram
451: @diagram = true
452:
453: when "--fileboxes"
454: @fileboxes = true if @diagram
455:
456: when "--mathml"
457: check_mathml
458: @mathml = true
459: @generator_name = 'xhtml'
460: @template = @generator_name
461: setup_generator(generators)
462:
463: when "--fmt"
464: @generator_name = arg.downcase
465: setup_generator(generators)
466:
467: when "--help"
468: OptionList.usage(generators.keys)
469:
470: when "--help-output"
471: OptionList.help_output
472:
473: when "--image-format"
474: if ['gif', 'png', 'jpeg', 'jpg'].include?(arg)
475: @image_format = arg
476: else
477: raise GetoptLong::InvalidOption.new("unknown image format: #{arg}")
478: end
479:
480: when "--include"
481: @rdoc_include.concat arg.split(/\s*,\s*/)
482:
483: when "--ri", "--ri-site", "--ri-system"
484: @generator_name = "ri"
485: @op_dir = case opt
486: when "--ri" then RI::Paths::HOMEDIR
487: when "--ri-site" then RI::Paths::SITEDIR
488: when "--ri-system" then RI::Paths::SYSDIR
489: else fail opt
490: end
491: setup_generator(generators)
492:
493: when "--tab-width"
494: begin
495: @tab_width = Integer(arg)
496: rescue
497: $stderr.puts "Invalid tab width: '#{arg}'"
498: exit 1
499: end
500:
501: when "--extension"
502: new, old = arg.split(/=/, 2)
503: OptionList.error("Invalid parameter to '-E'") unless new && old
504: unless RDoc::ParserFactory.alias_extension(old, new)
505: OptionList.error("Unknown extension .#{old} to -E")
506: end
507:
508: when "--version"
509: puts VERSION_STRING
510: exit
511: end
512:
513: end
514:
515: @files = ARGV.dup
516:
517: @rdoc_include << "." if @rdoc_include.empty?
518:
519: if @exclude.empty?
520: @exclude = nil
521: else
522: @exclude = Regexp.new(@exclude.join("|"))
523: end
524:
525: check_files
526:
527: # If no template was specified, use the default
528: # template for the output formatter
529:
530: @template ||= @generator_name
531:
532: # Generate a regexp from the accessors
533: unless accessors.empty?
534: re = '^(' + accessors.map{|a| Regexp.quote(a)}.join('|') + ')$'
535: @extra_accessors = Regexp.new(re)
536: end
537:
538: rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => error
539: OptionList.error(error.message)
540:
541: ensure
542: ARGV.replace(old_argv)
543: end
544: end
# File options.rb, line 662
662: def relative_str(from, target)
663: from_dir = File.dirname(from)
664: target_dir = File.dirname(target)
665: target_base = File.basename(target)
666:
667: from_ab_path = Pathname.new(File.expand_path(from_dir))
668: target_ab_path = Pathname.new(File.expand_path(target_dir))
669:
670: target_re_path = target_ab_path.relative_path_from(from_ab_path)
671:
672: result = target_re_path.to_s + "/" + target_base
673:
674: return result
675: end
Set up an output generator for the format in @generator_name
# File options.rb, line 562
562: def setup_generator(generators)
563: @generator = generators[@generator_name]
564: if !@generator
565: OptionList.error("Invalid output formatter")
566: end
567:
568: if @generator_name == "xml"
569: @all_one_file = true
570: @inline_source = true
571: end
572: end