| 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 |
| force_update | [R] | scan newer sources than the flag file if true. |
| 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 589
589: def check_diagram
590: return if RUBY_PLATFORM =~ /win/
591:
592: ok = false
593: ver = nil
594: IO.popen("dot -V 2>&1") do |io|
595: ver = io.read
596: if ver =~ /dot\s+version(?:\s+gviz)?\s+(\d+)\.(\d+)/
597: ok = ($1.to_i > 1) || ($1.to_i == 1 && $2.to_i >= 8)
598: end
599: end
600: unless ok
601: if ver =~ /^dot version/
602: $stderr.puts "Warning: You may need dot V1.8.6 or later to use\n",
603: "the --diagram option correctly. You have:\n\n ",
604: ver,
605: "\nDiagrams might have strange background colors.\n\n"
606: else
607: $stderr.puts "You need the 'dot' program to produce diagrams.",
608: "(see http://www.research.att.com/sw/tools/graphviz/)\n\n"
609: exit
610: end
611: # exit
612: end
613: end
Check that the files on the command line exist
# File options.rb, line 661
661: def check_files
662: @files.each do |f|
663: stat = File.stat f rescue error("File not found: #{f}")
664: error("File '#{f}' not readable") unless stat.readable?
665: end
666: end
Check that the right version of ‘mathml.rb’ is available.
# File options.rb, line 617
617: def check_mathml
618: not_found = true
619: fpath = ""
620: $LOAD_PATH.each{ |lpath|
621: fpath = File.join(lpath, "mathml.rb")
622: if File.exist?(fpath)
623: not_found = false
624: break
625: end
626: }
627:
628: if not_found
629: $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.6b.tar.gz)\n\n"
630: exit
631: end
632:
633: contents = File.open(fpath, "r") {|f| f.read}
634: num = 1
635: if !(contents =~ /^\s*module\s+MathML/) ||
636: !(contents =~ /^\s*module\s+LaTeX/) ||
637: !(contents =~ /^\s*class\s+Parser/) ||
638: !(contents =~ /^\s*def\s+parse/)
639: $stderr.puts "You need the 'mathml.rb' V0.6b 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.6b.tar.gz)\n\n"
640:
641: exit
642: end
643: end
Parse command line options. We‘re passed a hash containing output generators, keyed by the generator name
# File options.rb, line 368
368: def parse(argv, generators)
369: old_argv = ARGV.dup
370: begin
371: ARGV.replace(argv)
372: @op_dir = "doc"
373: @op_name = nil
374: @show_all = false
375: @main_page = nil
376: @marge = false
377: @exclude = []
378: @quiet = false
379: @generator_name = 'html'
380: @generator = generators[@generator_name]
381: @rdoc_include = []
382: @title = nil
383: @template = nil
384: @diagram = false
385: @mathml = false
386: @fileboxes = false
387: @show_hash = false
388: @image_format = 'png'
389: @inline_source = false
390: @all_one_file = false
391: @tab_width = 8
392: @include_line_numbers = false
393: @extra_accessor_flags = {}
394: @promiscuous = false
395: @force_update = false
396: @ignore_case = false
397:
398: @css = nil
399: @webcvs = nil
400:
401: @charset = case $KCODE
402: when /^S/i
403: 'Shift_JIS'
404: when /^E/i
405: 'EUC-JP'
406: else
407: 'iso-8859-1'
408: end
409:
410: accessors = []
411:
412: go = GetoptLong.new(*OptionList.options)
413: go.quiet = true
414:
415: go.each do |opt, arg|
416: case opt
417: when "--all" then @show_all = true
418: when "--charset" then @charset = arg
419: when "--debug" then $DEBUG = true
420: when "--exclude" then @exclude << Regexp.new(arg)
421: when "--inline-source" then @inline_source = true
422: when "--line-numbers" then @include_line_numbers = true
423: when "--main" then @main_page = arg
424: when "--merge" then @merge = true
425: when "--one-file" then @all_one_file = @inline_source = true
426: when "--opname" then @op_name = arg
427: when "--promiscuous" then @promiscuous = true
428: when "--quiet" then @quiet = true
429: when "--show-hash" then @show_hash = true
430: when "--template" then @template = arg
431: when "--title" then @title = arg
432: when "--webcvs" then @webcvs = arg
433: when "--ignore-case" then @ignore_case = true
434:
435: when "--op"
436: if @css && ! (%r{^(https?:/)?/} =~ @css)
437: @css = relative_str(File.join(arg, "."),
438: relative_str(File.join(@op_dir.split("/").fill(".."), ".."), @css))
439: end
440: @op_dir = arg
441:
442: when "--style"
443: if %r{^(https?:/)?/} =~ arg
444: @css = arg
445: else
446: @css = relative_str(File.join(@op_dir, "."), arg)
447: end
448:
449: when "--accessor"
450: arg.split(/,/).each do |accessor|
451: if accessor =~ /^(\w+)(=(.*))?$/
452: accessors << $1
453: @extra_accessor_flags[$1] = $3
454: end
455: end
456:
457: when "--diagram"
458: check_diagram
459: @diagram = true
460:
461: when "--fileboxes"
462: @fileboxes = true if @diagram
463:
464: when "--mathml"
465: check_mathml
466: @mathml = true
467: @generator_name = 'xhtml'
468: @template = @generator_name
469: setup_generator(generators)
470:
471: when "--fmt"
472: @generator_name = arg.downcase
473: setup_generator(generators)
474:
475: when "--help"
476: OptionList.usage(generators.keys)
477:
478: when "--help-output"
479: OptionList.help_output
480:
481: when "--image-format"
482: if ['gif', 'png', 'jpeg', 'jpg'].include?(arg)
483: @image_format = arg
484: else
485: raise GetoptLong::InvalidOption.new("unknown image format: #{arg}")
486: end
487:
488: when "--include"
489: @rdoc_include.concat arg.split(/\s*,\s*/)
490:
491: when "--ri", "--ri-site", "--ri-system"
492: @generator_name = "ri"
493: @op_dir = case opt
494: when "--ri" then RI::Paths::HOMEDIR
495: when "--ri-site" then RI::Paths::SITEDIR
496: when "--ri-system" then RI::Paths::SYSDIR
497: else fail opt
498: end
499: setup_generator(generators)
500:
501: when "--tab-width"
502: begin
503: @tab_width = Integer(arg)
504: rescue
505: $stderr.puts "Invalid tab width: '#{arg}'"
506: exit 1
507: end
508:
509: when "--extension"
510: new, old = arg.split(/=/, 2)
511: OptionList.error("Invalid parameter to '-E'") unless new && old
512: unless RDoc::ParserFactory.alias_extension(old, new)
513: OptionList.error("Unknown extension .#{old} to -E")
514: end
515:
516: when "--force-update"
517: @force_update = true
518:
519: when "--version"
520: puts VERSION_STRING
521: exit
522: end
523:
524: end
525:
526: @files = ARGV.dup
527:
528: @rdoc_include << "." if @rdoc_include.empty?
529:
530: if @exclude.empty?
531: @exclude = nil
532: else
533: @exclude = Regexp.new(@exclude.join("|"))
534: end
535:
536: check_files
537:
538: # If no template was specified, use the default
539: # template for the output formatter
540:
541: @template ||= @generator_name
542:
543: # Generate a regexp from the accessors
544: unless accessors.empty?
545: re = '^(' + accessors.map{|a| Regexp.quote(a)}.join('|') + ')$'
546: @extra_accessors = Regexp.new(re)
547: end
548:
549: rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => error
550: OptionList.error(error.message)
551:
552: ensure
553: ARGV.replace(old_argv)
554: end
555: end
# File options.rb, line 673
673: def relative_str(from, target)
674: from_dir = File.dirname(from)
675: target_dir = File.dirname(target)
676: target_base = File.basename(target)
677:
678: from_ab_path = Pathname.new(File.expand_path(from_dir))
679: target_ab_path = Pathname.new(File.expand_path(target_dir))
680:
681: target_re_path = target_ab_path.relative_path_from(from_ab_path)
682:
683: result = target_re_path.to_s + "/" + target_base
684:
685: return result
686: end
Set up an output generator for the format in @generator_name
# File options.rb, line 573
573: def setup_generator(generators)
574: @generator = generators[@generator_name]
575: if !@generator
576: OptionList.error("Invalid output formatter")
577: end
578:
579: if @generator_name == "xml"
580: @all_one_file = true
581: @inline_source = true
582: end
583: end