gitlab-rdoc 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +220 -0
  3. data/CVE-2013-0256.rdoc +49 -0
  4. data/ExampleMarkdown.md +37 -0
  5. data/ExampleRDoc.rdoc +208 -0
  6. data/Gemfile +12 -0
  7. data/History.rdoc +1666 -0
  8. data/LEGAL.rdoc +50 -0
  9. data/LICENSE.rdoc +57 -0
  10. data/README.rdoc +133 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +101 -0
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/exe/rdoc +44 -0
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +112 -0
  19. data/lib/rdoc/anon_class.rb +11 -0
  20. data/lib/rdoc/any_method.rb +361 -0
  21. data/lib/rdoc/attr.rb +176 -0
  22. data/lib/rdoc/class_module.rb +802 -0
  23. data/lib/rdoc/code_object.rb +421 -0
  24. data/lib/rdoc/code_objects.rb +6 -0
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +187 -0
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +1266 -0
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +136 -0
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +42 -0
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +790 -0
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +160 -0
  37. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  38. data/lib/rdoc/generator/pot/po.rb +84 -0
  39. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  40. data/lib/rdoc/generator/pot.rb +98 -0
  41. data/lib/rdoc/generator/ri.rb +31 -0
  42. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  58. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  59. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  72. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  73. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  74. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  75. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  76. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  77. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  78. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  79. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  80. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  81. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  82. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  83. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  84. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  85. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  86. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  87. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  88. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  89. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  90. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  91. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  92. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
  93. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
  94. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  95. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  96. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  97. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  98. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  99. data/lib/rdoc/generator/template/json_index/.document +1 -0
  100. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  101. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  102. data/lib/rdoc/generator.rb +51 -0
  103. data/lib/rdoc/ghost_method.rb +7 -0
  104. data/lib/rdoc/i18n/locale.rb +102 -0
  105. data/lib/rdoc/i18n/text.rb +126 -0
  106. data/lib/rdoc/i18n.rb +10 -0
  107. data/lib/rdoc/include.rb +10 -0
  108. data/lib/rdoc/known_classes.rb +73 -0
  109. data/lib/rdoc/markdown/entities.rb +2132 -0
  110. data/lib/rdoc/markdown/literals.kpeg +23 -0
  111. data/lib/rdoc/markdown/literals.rb +417 -0
  112. data/lib/rdoc/markdown.kpeg +1237 -0
  113. data/lib/rdoc/markdown.rb +16685 -0
  114. data/lib/rdoc/markup/attr_changer.rb +23 -0
  115. data/lib/rdoc/markup/attr_span.rb +36 -0
  116. data/lib/rdoc/markup/attribute_manager.rb +409 -0
  117. data/lib/rdoc/markup/attributes.rb +71 -0
  118. data/lib/rdoc/markup/blank_line.rb +28 -0
  119. data/lib/rdoc/markup/block_quote.rb +15 -0
  120. data/lib/rdoc/markup/document.rb +165 -0
  121. data/lib/rdoc/markup/formatter.rb +266 -0
  122. data/lib/rdoc/markup/hard_break.rb +32 -0
  123. data/lib/rdoc/markup/heading.rb +79 -0
  124. data/lib/rdoc/markup/include.rb +43 -0
  125. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  126. data/lib/rdoc/markup/list.rb +102 -0
  127. data/lib/rdoc/markup/list_item.rb +100 -0
  128. data/lib/rdoc/markup/paragraph.rb +29 -0
  129. data/lib/rdoc/markup/parser.rb +575 -0
  130. data/lib/rdoc/markup/pre_process.rb +296 -0
  131. data/lib/rdoc/markup/raw.rb +70 -0
  132. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  133. data/lib/rdoc/markup/rule.rb +21 -0
  134. data/lib/rdoc/markup/table.rb +47 -0
  135. data/lib/rdoc/markup/to_ansi.rb +94 -0
  136. data/lib/rdoc/markup/to_bs.rb +77 -0
  137. data/lib/rdoc/markup/to_html.rb +444 -0
  138. data/lib/rdoc/markup/to_html_crossref.rb +176 -0
  139. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  140. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  141. data/lib/rdoc/markup/to_label.rb +75 -0
  142. data/lib/rdoc/markup/to_markdown.rb +192 -0
  143. data/lib/rdoc/markup/to_rdoc.rb +362 -0
  144. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  145. data/lib/rdoc/markup/to_test.rb +70 -0
  146. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  147. data/lib/rdoc/markup/verbatim.rb +84 -0
  148. data/lib/rdoc/markup.rb +867 -0
  149. data/lib/rdoc/meta_method.rb +7 -0
  150. data/lib/rdoc/method_attr.rb +419 -0
  151. data/lib/rdoc/mixin.rb +121 -0
  152. data/lib/rdoc/normal_class.rb +93 -0
  153. data/lib/rdoc/normal_module.rb +74 -0
  154. data/lib/rdoc/options.rb +1285 -0
  155. data/lib/rdoc/parser/c.rb +1225 -0
  156. data/lib/rdoc/parser/changelog.rb +335 -0
  157. data/lib/rdoc/parser/markdown.rb +24 -0
  158. data/lib/rdoc/parser/rd.rb +23 -0
  159. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  160. data/lib/rdoc/parser/ruby.rb +2327 -0
  161. data/lib/rdoc/parser/ruby_tools.rb +167 -0
  162. data/lib/rdoc/parser/simple.rb +61 -0
  163. data/lib/rdoc/parser/text.rb +12 -0
  164. data/lib/rdoc/parser.rb +277 -0
  165. data/lib/rdoc/rd/block_parser.rb +1056 -0
  166. data/lib/rdoc/rd/block_parser.ry +639 -0
  167. data/lib/rdoc/rd/inline.rb +72 -0
  168. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  169. data/lib/rdoc/rd/inline_parser.ry +593 -0
  170. data/lib/rdoc/rd.rb +100 -0
  171. data/lib/rdoc/rdoc.rb +579 -0
  172. data/lib/rdoc/require.rb +52 -0
  173. data/lib/rdoc/ri/driver.rb +1572 -0
  174. data/lib/rdoc/ri/formatter.rb +6 -0
  175. data/lib/rdoc/ri/paths.rb +171 -0
  176. data/lib/rdoc/ri/store.rb +7 -0
  177. data/lib/rdoc/ri/task.rb +71 -0
  178. data/lib/rdoc/ri.rb +21 -0
  179. data/lib/rdoc/rubygems_hook.rb +246 -0
  180. data/lib/rdoc/servlet.rb +451 -0
  181. data/lib/rdoc/single_class.rb +26 -0
  182. data/lib/rdoc/stats/normal.rb +58 -0
  183. data/lib/rdoc/stats/quiet.rb +60 -0
  184. data/lib/rdoc/stats/verbose.rb +46 -0
  185. data/lib/rdoc/stats.rb +462 -0
  186. data/lib/rdoc/store.rb +979 -0
  187. data/lib/rdoc/task.rb +329 -0
  188. data/lib/rdoc/text.rb +304 -0
  189. data/lib/rdoc/token_stream.rb +119 -0
  190. data/lib/rdoc/tom_doc.rb +263 -0
  191. data/lib/rdoc/top_level.rb +289 -0
  192. data/lib/rdoc/version.rb +8 -0
  193. data/lib/rdoc.rb +201 -0
  194. data/man/ri.1 +247 -0
  195. data/rdoc.gemspec +249 -0
  196. metadata +279 -0
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # A normal class, neither singleton nor anonymous
4
+
5
+ class RDoc::NormalClass < RDoc::ClassModule
6
+
7
+ ##
8
+ # The ancestors of this class including modules. Unlike Module#ancestors,
9
+ # this class is not included in the result. The result will contain both
10
+ # RDoc::ClassModules and Strings.
11
+
12
+ def ancestors
13
+ if String === superclass then
14
+ super << superclass
15
+ elsif superclass then
16
+ ancestors = super
17
+ ancestors << superclass
18
+ ancestors.concat superclass.ancestors
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ def aref_prefix # :nodoc:
25
+ 'class'
26
+ end
27
+
28
+ ##
29
+ # The definition of this class, <tt>class MyClassName</tt>
30
+
31
+ def definition
32
+ "class #{full_name}"
33
+ end
34
+
35
+ def direct_ancestors
36
+ superclass ? super + [superclass] : super
37
+ end
38
+
39
+ def inspect # :nodoc:
40
+ superclass = @superclass ? " < #{@superclass}" : nil
41
+ "<%s:0x%x class %s%s includes: %p extends: %p attributes: %p methods: %p aliases: %p>" % [
42
+ self.class, object_id,
43
+ full_name, superclass, @includes, @extends, @attributes, @method_list, @aliases
44
+ ]
45
+ end
46
+
47
+ def to_s # :nodoc:
48
+ display = "#{self.class.name} #{self.full_name}"
49
+ if superclass
50
+ display += ' < ' + (superclass.is_a?(String) ? superclass : superclass.full_name)
51
+ end
52
+ display += ' -> ' + is_alias_for.to_s if is_alias_for
53
+ display
54
+ end
55
+
56
+ def pretty_print q # :nodoc:
57
+ superclass = @superclass ? " < #{@superclass}" : nil
58
+
59
+ q.group 2, "[class #{full_name}#{superclass} ", "]" do
60
+ q.breakable
61
+ q.text "includes:"
62
+ q.breakable
63
+ q.seplist @includes do |inc| q.pp inc end
64
+
65
+ q.breakable
66
+ q.text "constants:"
67
+ q.breakable
68
+ q.seplist @constants do |const| q.pp const end
69
+
70
+ q.breakable
71
+ q.text "attributes:"
72
+ q.breakable
73
+ q.seplist @attributes do |attr| q.pp attr end
74
+
75
+ q.breakable
76
+ q.text "methods:"
77
+ q.breakable
78
+ q.seplist @method_list do |meth| q.pp meth end
79
+
80
+ q.breakable
81
+ q.text "aliases:"
82
+ q.breakable
83
+ q.seplist @aliases do |aliaz| q.pp aliaz end
84
+
85
+ q.breakable
86
+ q.text "comment:"
87
+ q.breakable
88
+ q.pp comment
89
+ end
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # A normal module, like NormalClass
4
+
5
+ class RDoc::NormalModule < RDoc::ClassModule
6
+
7
+ def aref_prefix # :nodoc:
8
+ 'module'
9
+ end
10
+
11
+ def inspect # :nodoc:
12
+ "#<%s:0x%x module %s includes: %p extends: %p attributes: %p methods: %p aliases: %p>" % [
13
+ self.class, object_id,
14
+ full_name, @includes, @extends, @attributes, @method_list, @aliases
15
+ ]
16
+ end
17
+
18
+ ##
19
+ # The definition of this module, <tt>module MyModuleName</tt>
20
+
21
+ def definition
22
+ "module #{full_name}"
23
+ end
24
+
25
+ ##
26
+ # This is a module, returns true
27
+
28
+ def module?
29
+ true
30
+ end
31
+
32
+ def pretty_print q # :nodoc:
33
+ q.group 2, "[module #{full_name}: ", "]" do
34
+ q.breakable
35
+ q.text "includes:"
36
+ q.breakable
37
+ q.seplist @includes do |inc| q.pp inc end
38
+ q.breakable
39
+
40
+ q.breakable
41
+ q.text "constants:"
42
+ q.breakable
43
+ q.seplist @constants do |const| q.pp const end
44
+
45
+ q.text "attributes:"
46
+ q.breakable
47
+ q.seplist @attributes do |attr| q.pp attr end
48
+ q.breakable
49
+
50
+ q.text "methods:"
51
+ q.breakable
52
+ q.seplist @method_list do |meth| q.pp meth end
53
+ q.breakable
54
+
55
+ q.text "aliases:"
56
+ q.breakable
57
+ q.seplist @aliases do |aliaz| q.pp aliaz end
58
+ q.breakable
59
+
60
+ q.text "comment:"
61
+ q.breakable
62
+ q.pp comment
63
+ end
64
+ end
65
+
66
+ ##
67
+ # Modules don't have one, raises NoMethodError
68
+
69
+ def superclass
70
+ raise NoMethodError, "#{full_name} is a module"
71
+ end
72
+
73
+ end
74
+
@@ -0,0 +1,1285 @@
1
+ # frozen_string_literal: true
2
+ require 'optparse'
3
+ require 'pathname'
4
+
5
+ ##
6
+ # RDoc::Options handles the parsing and storage of options
7
+ #
8
+ # == Saved Options
9
+ #
10
+ # You can save some options like the markup format in the
11
+ # <tt>.rdoc_options</tt> file in your gem. The easiest way to do this is:
12
+ #
13
+ # rdoc --markup tomdoc --write-options
14
+ #
15
+ # Which will automatically create the file and fill it with the options you
16
+ # specified.
17
+ #
18
+ # The following options will not be saved since they interfere with the user's
19
+ # preferences or with the normal operation of RDoc:
20
+ #
21
+ # * +--coverage-report+
22
+ # * +--dry-run+
23
+ # * +--encoding+
24
+ # * +--force-update+
25
+ # * +--format+
26
+ # * +--pipe+
27
+ # * +--quiet+
28
+ # * +--template+
29
+ # * +--verbose+
30
+ #
31
+ # == Custom Options
32
+ #
33
+ # Generators can hook into RDoc::Options to add generator-specific command
34
+ # line options.
35
+ #
36
+ # When <tt>--format</tt> is encountered in ARGV, RDoc calls ::setup_options on
37
+ # the generator class to add extra options to the option parser. Options for
38
+ # custom generators must occur after <tt>--format</tt>. <tt>rdoc --help</tt>
39
+ # will list options for all installed generators.
40
+ #
41
+ # Example:
42
+ #
43
+ # class RDoc::Generator::Spellcheck
44
+ # RDoc::RDoc.add_generator self
45
+ #
46
+ # def self.setup_options rdoc_options
47
+ # op = rdoc_options.option_parser
48
+ #
49
+ # op.on('--spell-dictionary DICTIONARY',
50
+ # RDoc::Options::Path) do |dictionary|
51
+ # rdoc_options.spell_dictionary = dictionary
52
+ # end
53
+ # end
54
+ # end
55
+ #
56
+ # Of course, RDoc::Options does not respond to +spell_dictionary+ by default
57
+ # so you will need to add it:
58
+ #
59
+ # class RDoc::Options
60
+ #
61
+ # ##
62
+ # # The spell dictionary used by the spell-checking plugin.
63
+ #
64
+ # attr_accessor :spell_dictionary
65
+ #
66
+ # end
67
+ #
68
+ # == Option Validators
69
+ #
70
+ # OptionParser validators will validate and cast user input values. In
71
+ # addition to the validators that ship with OptionParser (String, Integer,
72
+ # Float, TrueClass, FalseClass, Array, Regexp, Date, Time, URI, etc.),
73
+ # RDoc::Options adds Path, PathArray and Template.
74
+
75
+ class RDoc::Options
76
+
77
+ ##
78
+ # The deprecated options.
79
+
80
+ DEPRECATED = {
81
+ '--accessor' => 'support discontinued',
82
+ '--diagram' => 'support discontinued',
83
+ '--help-output' => 'support discontinued',
84
+ '--image-format' => 'was an option for --diagram',
85
+ '--inline-source' => 'source code is now always inlined',
86
+ '--merge' => 'ri now always merges class information',
87
+ '--one-file' => 'support discontinued',
88
+ '--op-name' => 'support discontinued',
89
+ '--opname' => 'support discontinued',
90
+ '--promiscuous' => 'files always only document their content',
91
+ '--ri-system' => 'Ruby installers use other techniques',
92
+ }
93
+
94
+ ##
95
+ # RDoc options ignored (or handled specially) by --write-options
96
+
97
+ SPECIAL = %w[
98
+ coverage_report
99
+ dry_run
100
+ encoding
101
+ files
102
+ force_output
103
+ force_update
104
+ generator
105
+ generator_name
106
+ generator_options
107
+ generators
108
+ op_dir
109
+ option_parser
110
+ pipe
111
+ rdoc_include
112
+ root
113
+ static_path
114
+ stylesheet_url
115
+ template
116
+ template_dir
117
+ update_output_dir
118
+ verbosity
119
+ write_options
120
+ ]
121
+
122
+ ##
123
+ # Option validator for OptionParser that matches a directory that exists on
124
+ # the filesystem.
125
+
126
+ Directory = Object.new
127
+
128
+ ##
129
+ # Option validator for OptionParser that matches a file or directory that
130
+ # exists on the filesystem.
131
+
132
+ Path = Object.new
133
+
134
+ ##
135
+ # Option validator for OptionParser that matches a comma-separated list of
136
+ # files or directories that exist on the filesystem.
137
+
138
+ PathArray = Object.new
139
+
140
+ ##
141
+ # Option validator for OptionParser that matches a template directory for an
142
+ # installed generator that lives in
143
+ # <tt>"rdoc/generator/template/#{template_name}"</tt>
144
+
145
+ Template = Object.new
146
+
147
+ ##
148
+ # Character-set for HTML output. #encoding is preferred over #charset
149
+
150
+ attr_accessor :charset
151
+
152
+ ##
153
+ # If true, RDoc will not write any files.
154
+
155
+ attr_accessor :dry_run
156
+
157
+ ##
158
+ # The output encoding. All input files will be transcoded to this encoding.
159
+ #
160
+ # The default encoding is UTF-8. This is set via --encoding.
161
+
162
+ attr_accessor :encoding
163
+
164
+ ##
165
+ # Files matching this pattern will be excluded
166
+
167
+ attr_writer :exclude
168
+
169
+ ##
170
+ # The list of files to be processed
171
+
172
+ attr_accessor :files
173
+
174
+ ##
175
+ # Create the output even if the output directory does not look
176
+ # like an rdoc output directory
177
+
178
+ attr_accessor :force_output
179
+
180
+ ##
181
+ # Scan newer sources than the flag file if true.
182
+
183
+ attr_accessor :force_update
184
+
185
+ ##
186
+ # Formatter to mark up text with
187
+
188
+ attr_accessor :formatter
189
+
190
+ ##
191
+ # Description of the output generator (set with the <tt>--format</tt> option)
192
+
193
+ attr_accessor :generator
194
+
195
+ ##
196
+ # For #==
197
+
198
+ attr_reader :generator_name # :nodoc:
199
+
200
+ ##
201
+ # Loaded generator options. Used to prevent --help from loading the same
202
+ # options multiple times.
203
+
204
+ attr_accessor :generator_options
205
+
206
+ ##
207
+ # Old rdoc behavior: hyperlink all words that match a method name,
208
+ # even if not preceded by '#' or '::'
209
+
210
+ attr_accessor :hyperlink_all
211
+
212
+ ##
213
+ # Include line numbers in the source code
214
+
215
+ attr_accessor :line_numbers
216
+
217
+ ##
218
+ # The output locale.
219
+
220
+ attr_accessor :locale
221
+
222
+ ##
223
+ # The directory where locale data live.
224
+
225
+ attr_accessor :locale_dir
226
+
227
+ ##
228
+ # Name of the file, class or module to display in the initial index page (if
229
+ # not specified the first file we encounter is used)
230
+
231
+ attr_accessor :main_page
232
+
233
+ ##
234
+ # The default markup format. The default is 'rdoc'. 'markdown', 'tomdoc'
235
+ # and 'rd' are also built-in.
236
+
237
+ attr_accessor :markup
238
+
239
+ ##
240
+ # If true, only report on undocumented files
241
+
242
+ attr_accessor :coverage_report
243
+
244
+ ##
245
+ # The name of the output directory
246
+
247
+ attr_accessor :op_dir
248
+
249
+ ##
250
+ # The OptionParser for this instance
251
+
252
+ attr_accessor :option_parser
253
+
254
+ ##
255
+ # Output heading decorations?
256
+ attr_accessor :output_decoration
257
+
258
+ ##
259
+ # Directory where guides, FAQ, and other pages not associated with a class
260
+ # live. You may leave this unset if these are at the root of your project.
261
+
262
+ attr_accessor :page_dir
263
+
264
+ ##
265
+ # Is RDoc in pipe mode?
266
+
267
+ attr_accessor :pipe
268
+
269
+ ##
270
+ # Array of directories to search for files to satisfy an :include:
271
+
272
+ attr_accessor :rdoc_include
273
+
274
+ ##
275
+ # Root of the source documentation will be generated for. Set this when
276
+ # building documentation outside the source directory. Defaults to the
277
+ # current directory.
278
+
279
+ attr_accessor :root
280
+
281
+ ##
282
+ # Include the '#' at the front of hyperlinked instance method names
283
+
284
+ attr_accessor :show_hash
285
+
286
+ ##
287
+ # Directory to copy static files from
288
+
289
+ attr_accessor :static_path
290
+
291
+ ##
292
+ # The number of columns in a tab
293
+
294
+ attr_accessor :tab_width
295
+
296
+ ##
297
+ # Template to be used when generating output
298
+
299
+ attr_accessor :template
300
+
301
+ ##
302
+ # Directory the template lives in
303
+
304
+ attr_accessor :template_dir
305
+
306
+ ##
307
+ # Additional template stylesheets
308
+
309
+ attr_accessor :template_stylesheets
310
+
311
+ ##
312
+ # Documentation title
313
+
314
+ attr_accessor :title
315
+
316
+ ##
317
+ # Should RDoc update the timestamps in the output dir?
318
+
319
+ attr_accessor :update_output_dir
320
+
321
+ ##
322
+ # Verbosity, zero means quiet
323
+
324
+ attr_accessor :verbosity
325
+
326
+ ##
327
+ # URL of web cvs frontend
328
+
329
+ attr_accessor :webcvs
330
+
331
+ ##
332
+ # Minimum visibility of a documented method. One of +:public+, +:protected+,
333
+ # +:private+ or +:nodoc+.
334
+ #
335
+ # The +:nodoc+ visibility ignores all directives related to visibility. The
336
+ # other visibilities may be overridden on a per-method basis with the :doc:
337
+ # directive.
338
+
339
+ attr_reader :visibility
340
+
341
+ def initialize loaded_options = nil # :nodoc:
342
+ init_ivars
343
+ override loaded_options if loaded_options
344
+ end
345
+
346
+ def init_ivars # :nodoc:
347
+ @dry_run = false
348
+ @exclude = %w[
349
+ ~\z \.orig\z \.rej\z \.bak\z
350
+ \.gemspec\z
351
+ ]
352
+ @files = nil
353
+ @force_output = false
354
+ @force_update = true
355
+ @generator = nil
356
+ @generator_name = nil
357
+ @generator_options = []
358
+ @generators = RDoc::RDoc::GENERATORS
359
+ @hyperlink_all = false
360
+ @line_numbers = false
361
+ @locale = nil
362
+ @locale_name = nil
363
+ @locale_dir = 'locale'
364
+ @main_page = nil
365
+ @markup = 'rdoc'
366
+ @coverage_report = false
367
+ @op_dir = nil
368
+ @page_dir = nil
369
+ @pipe = false
370
+ @output_decoration = true
371
+ @rdoc_include = []
372
+ @root = Pathname(Dir.pwd)
373
+ @show_hash = false
374
+ @static_path = []
375
+ @stylesheet_url = nil # TODO remove in RDoc 4
376
+ @tab_width = 8
377
+ @template = nil
378
+ @template_dir = nil
379
+ @template_stylesheets = []
380
+ @title = nil
381
+ @update_output_dir = true
382
+ @verbosity = 1
383
+ @visibility = :protected
384
+ @webcvs = nil
385
+ @write_options = false
386
+ @encoding = Encoding::UTF_8
387
+ @charset = @encoding.name
388
+ end
389
+
390
+ def init_with map # :nodoc:
391
+ init_ivars
392
+
393
+ encoding = map['encoding']
394
+ @encoding = encoding ? Encoding.find(encoding) : encoding
395
+
396
+ @charset = map['charset']
397
+ @exclude = map['exclude']
398
+ @generator_name = map['generator_name']
399
+ @hyperlink_all = map['hyperlink_all']
400
+ @line_numbers = map['line_numbers']
401
+ @locale_name = map['locale_name']
402
+ @locale_dir = map['locale_dir']
403
+ @main_page = map['main_page']
404
+ @markup = map['markup']
405
+ @op_dir = map['op_dir']
406
+ @show_hash = map['show_hash']
407
+ @tab_width = map['tab_width']
408
+ @template_dir = map['template_dir']
409
+ @title = map['title']
410
+ @visibility = map['visibility']
411
+ @webcvs = map['webcvs']
412
+
413
+ @rdoc_include = sanitize_path map['rdoc_include']
414
+ @static_path = sanitize_path map['static_path']
415
+ end
416
+
417
+ def yaml_initialize tag, map # :nodoc:
418
+ init_with map
419
+ end
420
+
421
+ def override map # :nodoc:
422
+ if map.has_key?('encoding')
423
+ encoding = map['encoding']
424
+ @encoding = encoding ? Encoding.find(encoding) : encoding
425
+ end
426
+
427
+ @charset = map['charset'] if map.has_key?('charset')
428
+ @exclude = map['exclude'] if map.has_key?('exclude')
429
+ @generator_name = map['generator_name'] if map.has_key?('generator_name')
430
+ @hyperlink_all = map['hyperlink_all'] if map.has_key?('hyperlink_all')
431
+ @line_numbers = map['line_numbers'] if map.has_key?('line_numbers')
432
+ @locale_name = map['locale_name'] if map.has_key?('locale_name')
433
+ @locale_dir = map['locale_dir'] if map.has_key?('locale_dir')
434
+ @main_page = map['main_page'] if map.has_key?('main_page')
435
+ @markup = map['markup'] if map.has_key?('markup')
436
+ @op_dir = map['op_dir'] if map.has_key?('op_dir')
437
+ @show_hash = map['show_hash'] if map.has_key?('show_hash')
438
+ @tab_width = map['tab_width'] if map.has_key?('tab_width')
439
+ @template_dir = map['template_dir'] if map.has_key?('template_dir')
440
+ @title = map['title'] if map.has_key?('title')
441
+ @visibility = map['visibility'] if map.has_key?('visibility')
442
+ @webcvs = map['webcvs'] if map.has_key?('webcvs')
443
+
444
+ if map.has_key?('rdoc_include')
445
+ @rdoc_include = sanitize_path map['rdoc_include']
446
+ end
447
+ if map.has_key?('static_path')
448
+ @static_path = sanitize_path map['static_path']
449
+ end
450
+ end
451
+
452
+ def == other # :nodoc:
453
+ self.class === other and
454
+ @encoding == other.encoding and
455
+ @generator_name == other.generator_name and
456
+ @hyperlink_all == other.hyperlink_all and
457
+ @line_numbers == other.line_numbers and
458
+ @locale == other.locale and
459
+ @locale_dir == other.locale_dir and
460
+ @main_page == other.main_page and
461
+ @markup == other.markup and
462
+ @op_dir == other.op_dir and
463
+ @rdoc_include == other.rdoc_include and
464
+ @show_hash == other.show_hash and
465
+ @static_path == other.static_path and
466
+ @tab_width == other.tab_width and
467
+ @template == other.template and
468
+ @title == other.title and
469
+ @visibility == other.visibility and
470
+ @webcvs == other.webcvs
471
+ end
472
+
473
+ ##
474
+ # Check that the files on the command line exist
475
+
476
+ def check_files
477
+ @files.delete_if do |file|
478
+ if File.exist? file then
479
+ if File.readable? file then
480
+ false
481
+ else
482
+ warn "file '#{file}' not readable"
483
+
484
+ true
485
+ end
486
+ else
487
+ warn "file '#{file}' not found"
488
+
489
+ true
490
+ end
491
+ end
492
+ end
493
+
494
+ ##
495
+ # Ensure only one generator is loaded
496
+
497
+ def check_generator
498
+ if @generator then
499
+ raise OptionParser::InvalidOption,
500
+ "generator already set to #{@generator_name}"
501
+ end
502
+ end
503
+
504
+ ##
505
+ # Set the title, but only if not already set. Used to set the title
506
+ # from a source file, so that a title set from the command line
507
+ # will have the priority.
508
+
509
+ def default_title=(string)
510
+ @title ||= string
511
+ end
512
+
513
+ ##
514
+ # For dumping YAML
515
+
516
+ def encode_with coder # :nodoc:
517
+ encoding = @encoding ? @encoding.name : nil
518
+
519
+ coder.add 'encoding', encoding
520
+ coder.add 'static_path', sanitize_path(@static_path)
521
+ coder.add 'rdoc_include', sanitize_path(@rdoc_include)
522
+
523
+ ivars = instance_variables.map { |ivar| ivar.to_s[1..-1] }
524
+ ivars -= SPECIAL
525
+
526
+ ivars.sort.each do |ivar|
527
+ coder.add ivar, instance_variable_get("@#{ivar}")
528
+ end
529
+ end
530
+
531
+ ##
532
+ # Create a regexp for #exclude
533
+
534
+ def exclude
535
+ if @exclude.nil? or Regexp === @exclude then
536
+ # done, #finish is being re-run
537
+ @exclude
538
+ elsif @exclude.empty? then
539
+ nil
540
+ else
541
+ Regexp.new(@exclude.join("|"))
542
+ end
543
+ end
544
+
545
+ ##
546
+ # Completes any unfinished option setup business such as filtering for
547
+ # existent files, creating a regexp for #exclude and setting a default
548
+ # #template.
549
+
550
+ def finish
551
+ @op_dir ||= 'doc'
552
+
553
+ @rdoc_include << "." if @rdoc_include.empty?
554
+ root = @root.to_s
555
+ @rdoc_include << root unless @rdoc_include.include?(root)
556
+
557
+ @exclude = self.exclude
558
+
559
+ finish_page_dir
560
+
561
+ check_files
562
+
563
+ # If no template was specified, use the default template for the output
564
+ # formatter
565
+
566
+ unless @template then
567
+ @template = @generator_name
568
+ @template_dir = template_dir_for @template
569
+ end
570
+
571
+ if @locale_name
572
+ @locale = RDoc::I18n::Locale[@locale_name]
573
+ @locale.load(@locale_dir)
574
+ else
575
+ @locale = nil
576
+ end
577
+
578
+ self
579
+ end
580
+
581
+ ##
582
+ # Fixes the page_dir to be relative to the root_dir and adds the page_dir to
583
+ # the files list.
584
+
585
+ def finish_page_dir
586
+ return unless @page_dir
587
+
588
+ @files << @page_dir.to_s
589
+
590
+ page_dir = nil
591
+ begin
592
+ page_dir = @page_dir.expand_path.relative_path_from @root
593
+ rescue ArgumentError
594
+ # On Windows, sometimes crosses different drive letters.
595
+ page_dir = @page_dir.expand_path
596
+ end
597
+
598
+ @page_dir = page_dir
599
+ end
600
+
601
+ ##
602
+ # Returns a properly-space list of generators and their descriptions.
603
+
604
+ def generator_descriptions
605
+ lengths = []
606
+
607
+ generators = RDoc::RDoc::GENERATORS.map do |name, generator|
608
+ lengths << name.length
609
+
610
+ description = generator::DESCRIPTION if
611
+ generator.const_defined? :DESCRIPTION
612
+
613
+ [name, description]
614
+ end
615
+
616
+ longest = lengths.max
617
+
618
+ generators.sort.map do |name, description|
619
+ if description then
620
+ " %-*s - %s" % [longest, name, description]
621
+ else
622
+ " #{name}"
623
+ end
624
+ end.join "\n"
625
+ end
626
+
627
+ ##
628
+ # Parses command line options.
629
+
630
+ def parse argv
631
+ ignore_invalid = true
632
+
633
+ argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
634
+
635
+ opts = OptionParser.new do |opt|
636
+ @option_parser = opt
637
+ opt.program_name = File.basename $0
638
+ opt.version = RDoc::VERSION
639
+ opt.release = nil
640
+ opt.summary_indent = ' ' * 4
641
+ opt.banner = <<-EOF
642
+ Usage: #{opt.program_name} [options] [names...]
643
+
644
+ Files are parsed, and the information they contain collected, before any
645
+ output is produced. This allows cross references between all files to be
646
+ resolved. If a name is a directory, it is traversed. If no names are
647
+ specified, all Ruby files in the current directory (and subdirectories) are
648
+ processed.
649
+
650
+ How RDoc generates output depends on the output formatter being used, and on
651
+ the options you give.
652
+
653
+ Options can be specified via the RDOCOPT environment variable, which
654
+ functions similar to the RUBYOPT environment variable for ruby.
655
+
656
+ $ export RDOCOPT="--show-hash"
657
+
658
+ will make rdoc show hashes in method links by default. Command-line options
659
+ always will override those in RDOCOPT.
660
+
661
+ Available formatters:
662
+
663
+ #{generator_descriptions}
664
+
665
+ RDoc understands the following file formats:
666
+
667
+ EOF
668
+
669
+ parsers = Hash.new { |h,parser| h[parser] = [] }
670
+
671
+ RDoc::Parser.parsers.each do |regexp, parser|
672
+ parsers[parser.name.sub('RDoc::Parser::', '')] << regexp.source
673
+ end
674
+
675
+ parsers.sort.each do |parser, regexp|
676
+ opt.banner += " - #{parser}: #{regexp.join ', '}\n"
677
+ end
678
+ opt.banner += " - TomDoc: Only in ruby files\n"
679
+
680
+ opt.banner += "\n The following options are deprecated:\n\n"
681
+
682
+ name_length = DEPRECATED.keys.sort_by { |k| k.length }.last.length
683
+
684
+ DEPRECATED.sort_by { |k,| k }.each do |name, reason|
685
+ opt.banner += " %*1$2$s %3$s\n" % [-name_length, name, reason]
686
+ end
687
+
688
+ opt.accept Template do |template|
689
+ template_dir = template_dir_for template
690
+
691
+ unless template_dir then
692
+ $stderr.puts "could not find template #{template}"
693
+ nil
694
+ else
695
+ [template, template_dir]
696
+ end
697
+ end
698
+
699
+ opt.accept Directory do |directory|
700
+ directory = File.expand_path directory
701
+
702
+ raise OptionParser::InvalidArgument unless File.directory? directory
703
+
704
+ directory
705
+ end
706
+
707
+ opt.accept Path do |path|
708
+ path = File.expand_path path
709
+
710
+ raise OptionParser::InvalidArgument unless File.exist? path
711
+
712
+ path
713
+ end
714
+
715
+ opt.accept PathArray do |paths,|
716
+ paths = if paths then
717
+ paths.split(',').map { |d| d unless d.empty? }
718
+ end
719
+
720
+ paths.map do |path|
721
+ path = File.expand_path path
722
+
723
+ raise OptionParser::InvalidArgument unless File.exist? path
724
+
725
+ path
726
+ end
727
+ end
728
+
729
+ opt.separator nil
730
+ opt.separator "Parsing options:"
731
+ opt.separator nil
732
+
733
+ opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name },
734
+ "Specifies the output encoding. All files",
735
+ "read will be converted to this encoding.",
736
+ "The default encoding is UTF-8.",
737
+ "--encoding is preferred over --charset") do |value|
738
+ @encoding = Encoding.find value
739
+ @charset = @encoding.name # may not be valid value
740
+ end
741
+
742
+ opt.separator nil
743
+
744
+ opt.on("--locale=NAME",
745
+ "Specifies the output locale.") do |value|
746
+ @locale_name = value
747
+ end
748
+
749
+ opt.on("--locale-data-dir=DIR",
750
+ "Specifies the directory where locale data live.") do |value|
751
+ @locale_dir = value
752
+ end
753
+
754
+ opt.separator nil
755
+
756
+ opt.on("--all", "-a",
757
+ "Synonym for --visibility=private.") do |value|
758
+ @visibility = :private
759
+ end
760
+
761
+ opt.separator nil
762
+
763
+ opt.on("--exclude=PATTERN", "-x", Regexp,
764
+ "Do not process files or directories",
765
+ "matching PATTERN.") do |value|
766
+ @exclude << value
767
+ end
768
+
769
+ opt.separator nil
770
+
771
+ opt.on("--extension=NEW=OLD", "-E",
772
+ "Treat files ending with .new as if they",
773
+ "ended with .old. Using '-E cgi=rb' will",
774
+ "cause xxx.cgi to be parsed as a Ruby file.") do |value|
775
+ new, old = value.split(/=/, 2)
776
+
777
+ unless new and old then
778
+ raise OptionParser::InvalidArgument, "Invalid parameter to '-E'"
779
+ end
780
+
781
+ unless RDoc::Parser.alias_extension old, new then
782
+ raise OptionParser::InvalidArgument, "Unknown extension .#{old} to -E"
783
+ end
784
+ end
785
+
786
+ opt.separator nil
787
+
788
+ opt.on("--[no-]force-update", "-U",
789
+ "Forces rdoc to scan all sources even if",
790
+ "no files are newer than the flag file.") do |value|
791
+ @force_update = value
792
+ end
793
+
794
+ opt.separator nil
795
+
796
+ opt.on("--pipe", "-p",
797
+ "Convert RDoc on stdin to HTML") do
798
+ @pipe = true
799
+ end
800
+
801
+ opt.separator nil
802
+
803
+ opt.on("--tab-width=WIDTH", "-w", Integer,
804
+ "Set the width of tab characters.") do |value|
805
+ raise OptionParser::InvalidArgument,
806
+ "#{value} is an invalid tab width" if value <= 0
807
+ @tab_width = value
808
+ end
809
+
810
+ opt.separator nil
811
+
812
+ opt.on("--visibility=VISIBILITY", "-V", RDoc::VISIBILITIES + [:nodoc],
813
+ "Minimum visibility to document a method.",
814
+ "One of 'public', 'protected' (the default),",
815
+ "'private' or 'nodoc' (show everything)") do |value|
816
+ @visibility = value
817
+ end
818
+
819
+ opt.separator nil
820
+
821
+ markup_formats = RDoc::Text::MARKUP_FORMAT.keys.sort
822
+
823
+ opt.on("--markup=MARKUP", markup_formats,
824
+ "The markup format for the named files.",
825
+ "The default is rdoc. Valid values are:",
826
+ markup_formats.join(', ')) do |value|
827
+ @markup = value
828
+ end
829
+
830
+ opt.separator nil
831
+
832
+ opt.on("--root=ROOT", Directory,
833
+ "Root of the source tree documentation",
834
+ "will be generated for. Set this when",
835
+ "building documentation outside the",
836
+ "source directory. Default is the",
837
+ "current directory.") do |root|
838
+ @root = Pathname(root)
839
+ end
840
+
841
+ opt.separator nil
842
+
843
+ opt.on("--page-dir=DIR", Directory,
844
+ "Directory where guides, your FAQ or",
845
+ "other pages not associated with a class",
846
+ "live. Set this when you don't store",
847
+ "such files at your project root.",
848
+ "NOTE: Do not use the same file name in",
849
+ "the page dir and the root of your project") do |page_dir|
850
+ @page_dir = Pathname(page_dir)
851
+ end
852
+
853
+ opt.separator nil
854
+ opt.separator "Common generator options:"
855
+ opt.separator nil
856
+
857
+ opt.on("--force-output", "-O",
858
+ "Forces rdoc to write the output files,",
859
+ "even if the output directory exists",
860
+ "and does not seem to have been created",
861
+ "by rdoc.") do |value|
862
+ @force_output = value
863
+ end
864
+
865
+ opt.separator nil
866
+
867
+ generator_text = @generators.keys.map { |name| " #{name}" }.sort
868
+
869
+ opt.on("-f", "--fmt=FORMAT", "--format=FORMAT", @generators.keys,
870
+ "Set the output formatter. One of:", *generator_text) do |value|
871
+ check_generator
872
+
873
+ @generator_name = value.downcase
874
+ setup_generator
875
+ end
876
+
877
+ opt.separator nil
878
+
879
+ opt.on("--include=DIRECTORIES", "-i", PathArray,
880
+ "Set (or add to) the list of directories to",
881
+ "be searched when satisfying :include:",
882
+ "requests. Can be used more than once.") do |value|
883
+ @rdoc_include.concat value.map { |dir| dir.strip }
884
+ end
885
+
886
+ opt.separator nil
887
+
888
+ opt.on("--[no-]coverage-report=[LEVEL]", "--[no-]dcov", "-C", Integer,
889
+ "Prints a report on undocumented items.",
890
+ "Does not generate files.") do |value|
891
+ value = 0 if value.nil? # Integer converts -C to nil
892
+
893
+ @coverage_report = value
894
+ @force_update = true if value
895
+ end
896
+
897
+ opt.separator nil
898
+
899
+ opt.on("--output=DIR", "--op", "-o",
900
+ "Set the output directory.") do |value|
901
+ @op_dir = value
902
+ end
903
+
904
+ opt.separator nil
905
+
906
+ opt.on("-d",
907
+ "Deprecated --diagram option.",
908
+ "Prevents firing debug mode",
909
+ "with legacy invocation.") do |value|
910
+ end
911
+
912
+ opt.separator nil
913
+ opt.separator 'HTML generator options:'
914
+ opt.separator nil
915
+
916
+ opt.on("--charset=CHARSET", "-c",
917
+ "Specifies the output HTML character-set.",
918
+ "Use --encoding instead of --charset if",
919
+ "available.") do |value|
920
+ @charset = value
921
+ end
922
+
923
+ opt.separator nil
924
+
925
+ opt.on("--hyperlink-all", "-A",
926
+ "Generate hyperlinks for all words that",
927
+ "correspond to known methods, even if they",
928
+ "do not start with '#' or '::' (legacy",
929
+ "behavior).") do |value|
930
+ @hyperlink_all = value
931
+ end
932
+
933
+ opt.separator nil
934
+
935
+ opt.on("--main=NAME", "-m",
936
+ "NAME will be the initial page displayed.") do |value|
937
+ @main_page = value
938
+ end
939
+
940
+ opt.separator nil
941
+
942
+ opt.on("--[no-]line-numbers", "-N",
943
+ "Include line numbers in the source code.",
944
+ "By default, only the number of the first",
945
+ "line is displayed, in a leading comment.") do |value|
946
+ @line_numbers = value
947
+ end
948
+
949
+ opt.separator nil
950
+
951
+ opt.on("--show-hash", "-H",
952
+ "A name of the form #name in a comment is a",
953
+ "possible hyperlink to an instance method",
954
+ "name. When displayed, the '#' is removed",
955
+ "unless this option is specified.") do |value|
956
+ @show_hash = value
957
+ end
958
+
959
+ opt.separator nil
960
+
961
+ opt.on("--template=NAME", "-T", Template,
962
+ "Set the template used when generating",
963
+ "output. The default depends on the",
964
+ "formatter used.") do |(template, template_dir)|
965
+ @template = template
966
+ @template_dir = template_dir
967
+ end
968
+
969
+ opt.separator nil
970
+
971
+ opt.on("--template-stylesheets=FILES", PathArray,
972
+ "Set (or add to) the list of files to",
973
+ "include with the html template.") do |value|
974
+ @template_stylesheets << value
975
+ end
976
+
977
+ opt.separator nil
978
+
979
+ opt.on("--title=TITLE", "-t",
980
+ "Set TITLE as the title for HTML output.") do |value|
981
+ @title = value
982
+ end
983
+
984
+ opt.separator nil
985
+
986
+ opt.on("--copy-files=PATH", Path,
987
+ "Specify a file or directory to copy static",
988
+ "files from.",
989
+ "If a file is given it will be copied into",
990
+ "the output dir. If a directory is given the",
991
+ "entire directory will be copied.",
992
+ "You can use this multiple times") do |value|
993
+ @static_path << value
994
+ end
995
+
996
+ opt.separator nil
997
+
998
+ opt.on("--webcvs=URL", "-W",
999
+ "Specify a URL for linking to a web frontend",
1000
+ "to CVS. If the URL contains a '\%s', the",
1001
+ "name of the current file will be",
1002
+ "substituted; if the URL doesn't contain a",
1003
+ "'\%s', the filename will be appended to it.") do |value|
1004
+ @webcvs = value
1005
+ end
1006
+
1007
+ opt.separator nil
1008
+ opt.separator "ri generator options:"
1009
+ opt.separator nil
1010
+
1011
+ opt.on("--ri", "-r",
1012
+ "Generate output for use by `ri`. The files",
1013
+ "are stored in the '.rdoc' directory under",
1014
+ "your home directory unless overridden by a",
1015
+ "subsequent --op parameter, so no special",
1016
+ "privileges are needed.") do |value|
1017
+ check_generator
1018
+
1019
+ @generator_name = "ri"
1020
+ @op_dir ||= RDoc::RI::Paths::HOMEDIR
1021
+ setup_generator
1022
+ end
1023
+
1024
+ opt.separator nil
1025
+
1026
+ opt.on("--ri-site", "-R",
1027
+ "Generate output for use by `ri`. The files",
1028
+ "are stored in a site-wide directory,",
1029
+ "making them accessible to others, so",
1030
+ "special privileges are needed.") do |value|
1031
+ check_generator
1032
+
1033
+ @generator_name = "ri"
1034
+ @op_dir = RDoc::RI::Paths.site_dir
1035
+ setup_generator
1036
+ end
1037
+
1038
+ opt.separator nil
1039
+ opt.separator "Generic options:"
1040
+ opt.separator nil
1041
+
1042
+ opt.on("--write-options",
1043
+ "Write .rdoc_options to the current",
1044
+ "directory with the given options. Not all",
1045
+ "options will be used. See RDoc::Options",
1046
+ "for details.") do |value|
1047
+ @write_options = true
1048
+ end
1049
+
1050
+ opt.separator nil
1051
+
1052
+ opt.on("--[no-]dry-run",
1053
+ "Don't write any files") do |value|
1054
+ @dry_run = value
1055
+ end
1056
+
1057
+ opt.separator nil
1058
+
1059
+ opt.on("-D", "--[no-]debug",
1060
+ "Displays lots on internal stuff.") do |value|
1061
+ $DEBUG_RDOC = value
1062
+ end
1063
+
1064
+ opt.separator nil
1065
+
1066
+ opt.on("--[no-]ignore-invalid",
1067
+ "Ignore invalid options and continue",
1068
+ "(default true).") do |value|
1069
+ ignore_invalid = value
1070
+ end
1071
+
1072
+ opt.separator nil
1073
+
1074
+ opt.on("--quiet", "-q",
1075
+ "Don't show progress as we parse.") do |value|
1076
+ @verbosity = 0
1077
+ end
1078
+
1079
+ opt.separator nil
1080
+
1081
+ opt.on("--verbose", "-V",
1082
+ "Display extra progress as RDoc parses") do |value|
1083
+ @verbosity = 2
1084
+ end
1085
+
1086
+ opt.separator nil
1087
+
1088
+ opt.on("--version", "-v", "print the version") do
1089
+ puts opt.version
1090
+ exit
1091
+ end
1092
+
1093
+ opt.separator nil
1094
+
1095
+ opt.on("--help", "-h", "Display this help") do
1096
+ RDoc::RDoc::GENERATORS.each_key do |generator|
1097
+ setup_generator generator
1098
+ end
1099
+
1100
+ puts opt.help
1101
+ exit
1102
+ end
1103
+
1104
+ opt.separator nil
1105
+ end
1106
+
1107
+ setup_generator 'darkfish' if
1108
+ argv.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty?
1109
+
1110
+ deprecated = []
1111
+ invalid = []
1112
+
1113
+ begin
1114
+ opts.parse! argv
1115
+ rescue OptionParser::ParseError => e
1116
+ if DEPRECATED[e.args.first] then
1117
+ deprecated << e.args.first
1118
+ elsif %w[--format --ri -r --ri-site -R].include? e.args.first then
1119
+ raise
1120
+ else
1121
+ invalid << e.args.join(' ')
1122
+ end
1123
+
1124
+ retry
1125
+ end
1126
+
1127
+ unless @generator then
1128
+ @generator = RDoc::Generator::Darkfish
1129
+ @generator_name = 'darkfish'
1130
+ end
1131
+
1132
+ if @pipe and not argv.empty? then
1133
+ @pipe = false
1134
+ invalid << '-p (with files)'
1135
+ end
1136
+
1137
+ unless quiet then
1138
+ deprecated.each do |opt|
1139
+ $stderr.puts 'option ' + opt + ' is deprecated: ' + DEPRECATED[opt]
1140
+ end
1141
+ end
1142
+
1143
+ unless invalid.empty? then
1144
+ invalid = "invalid options: #{invalid.join ', '}"
1145
+
1146
+ if ignore_invalid then
1147
+ unless quiet then
1148
+ $stderr.puts invalid
1149
+ $stderr.puts '(invalid options are ignored)'
1150
+ end
1151
+ else
1152
+ unless quiet then
1153
+ $stderr.puts opts
1154
+ end
1155
+ $stderr.puts invalid
1156
+ exit 1
1157
+ end
1158
+ end
1159
+
1160
+ @files = argv.dup
1161
+
1162
+ finish
1163
+
1164
+ if @write_options then
1165
+ write_options
1166
+ exit
1167
+ end
1168
+
1169
+ self
1170
+ end
1171
+
1172
+ ##
1173
+ # Don't display progress as we process the files
1174
+
1175
+ def quiet
1176
+ @verbosity.zero?
1177
+ end
1178
+
1179
+ ##
1180
+ # Set quietness to +bool+
1181
+
1182
+ def quiet= bool
1183
+ @verbosity = bool ? 0 : 1
1184
+ end
1185
+
1186
+ ##
1187
+ # Removes directories from +path+ that are outside the current directory
1188
+
1189
+ def sanitize_path path
1190
+ require 'pathname'
1191
+ dot = Pathname.new('.').expand_path
1192
+
1193
+ path.reject do |item|
1194
+ path = Pathname.new(item).expand_path
1195
+ is_reject = nil
1196
+ relative = nil
1197
+ begin
1198
+ relative = path.relative_path_from(dot).to_s
1199
+ rescue ArgumentError
1200
+ # On Windows, sometimes crosses different drive letters.
1201
+ is_reject = true
1202
+ else
1203
+ is_reject = relative.start_with? '..'
1204
+ end
1205
+ is_reject
1206
+ end
1207
+ end
1208
+
1209
+ ##
1210
+ # Set up an output generator for the named +generator_name+.
1211
+ #
1212
+ # If the found generator responds to :setup_options it will be called with
1213
+ # the options instance. This allows generators to add custom options or set
1214
+ # default options.
1215
+
1216
+ def setup_generator generator_name = @generator_name
1217
+ @generator = @generators[generator_name]
1218
+
1219
+ unless @generator then
1220
+ raise OptionParser::InvalidArgument,
1221
+ "Invalid output formatter #{generator_name}"
1222
+ end
1223
+
1224
+ return if @generator_options.include? @generator
1225
+
1226
+ @generator_name = generator_name
1227
+ @generator_options << @generator
1228
+
1229
+ if @generator.respond_to? :setup_options then
1230
+ @option_parser ||= OptionParser.new
1231
+ @generator.setup_options self
1232
+ end
1233
+ end
1234
+
1235
+ ##
1236
+ # Finds the template dir for +template+
1237
+
1238
+ def template_dir_for template
1239
+ template_path = File.join 'rdoc', 'generator', 'template', template
1240
+
1241
+ $LOAD_PATH.map do |path|
1242
+ File.join File.expand_path(path), template_path
1243
+ end.find do |dir|
1244
+ File.directory? dir
1245
+ end
1246
+ end
1247
+
1248
+ # Sets the minimum visibility of a documented method.
1249
+ #
1250
+ # Accepts +:public+, +:protected+, +:private+, +:nodoc+, or +:all+.
1251
+ #
1252
+ # When +:all+ is passed, visibility is set to +:private+, similarly to
1253
+ # RDOCOPT="--all", see #visibility for more information.
1254
+
1255
+ def visibility= visibility
1256
+ case visibility
1257
+ when :all
1258
+ @visibility = :private
1259
+ else
1260
+ @visibility = visibility
1261
+ end
1262
+ end
1263
+
1264
+ ##
1265
+ # Displays a warning using Kernel#warn if we're being verbose
1266
+
1267
+ def warn message
1268
+ super message if @verbosity > 1
1269
+ end
1270
+
1271
+ ##
1272
+ # Writes the YAML file .rdoc_options to the current directory containing the
1273
+ # parsed options.
1274
+
1275
+ def write_options
1276
+ RDoc.load_yaml
1277
+
1278
+ File.open '.rdoc_options', 'w' do |io|
1279
+ io.set_encoding Encoding::UTF_8
1280
+
1281
+ YAML.dump self, io
1282
+ end
1283
+ end
1284
+
1285
+ end