yard 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (121) hide show
  1. data/ChangeLog +585 -1
  2. data/README.md +10 -2
  3. data/benchmarks/yri_cache.rb +19 -0
  4. data/bin/yri +1 -26
  5. data/docs/WhatsNew.md +99 -0
  6. data/lib/rubygems_plugin.rb +2 -0
  7. data/lib/yard.rb +2 -2
  8. data/lib/yard/autoload.rb +9 -4
  9. data/lib/yard/cli/base.rb +26 -0
  10. data/lib/yard/cli/yard_graph.rb +2 -9
  11. data/lib/yard/cli/yardoc.rb +93 -33
  12. data/lib/yard/cli/yri.rb +128 -0
  13. data/lib/yard/code_objects/base.rb +16 -5
  14. data/lib/yard/code_objects/class_object.rb +11 -4
  15. data/lib/yard/code_objects/method_object.rb +11 -1
  16. data/lib/yard/code_objects/proxy.rb +5 -2
  17. data/lib/yard/code_objects/root_object.rb +1 -0
  18. data/lib/yard/core_ext/file.rb +1 -1
  19. data/lib/yard/core_ext/hash.rb +15 -0
  20. data/lib/yard/core_ext/module.rb +2 -2
  21. data/lib/yard/core_ext/string.rb +66 -0
  22. data/lib/yard/core_ext/symbol_hash.rb +1 -1
  23. data/lib/yard/docstring.rb +5 -5
  24. data/lib/yard/handlers/base.rb +10 -4
  25. data/lib/yard/handlers/processor.rb +3 -4
  26. data/lib/yard/handlers/ruby/attribute_handler.rb +3 -2
  27. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -2
  28. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -1
  29. data/lib/yard/handlers/ruby/method_handler.rb +7 -1
  30. data/lib/yard/logging.rb +11 -1
  31. data/lib/yard/parser/c_parser.rb +407 -0
  32. data/lib/yard/parser/ruby/ast_node.rb +2 -2
  33. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +3 -4
  34. data/lib/yard/parser/source_parser.rb +18 -7
  35. data/lib/yard/rake/yardoc_task.rb +1 -1
  36. data/lib/yard/registry.rb +83 -29
  37. data/lib/yard/registry_store.rb +213 -0
  38. data/lib/yard/serializers/base.rb +1 -1
  39. data/lib/yard/serializers/yardoc_serializer.rb +113 -0
  40. data/lib/yard/tags/library.rb +4 -0
  41. data/lib/yard/tags/overload_tag.rb +16 -5
  42. data/lib/yard/tags/tag.rb +1 -2
  43. data/lib/yard/templates/engine.rb +3 -3
  44. data/lib/yard/templates/helpers/html_helper.rb +50 -16
  45. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +1 -3
  46. data/lib/yard/templates/helpers/html_syntax_highlight_helper18.rb +1 -3
  47. data/lib/yard/templates/helpers/method_helper.rb +11 -4
  48. data/lib/yard/templates/helpers/text_helper.rb +24 -2
  49. data/lib/yard/verifier.rb +3 -3
  50. data/spec/cli/yardoc_spec.rb +33 -6
  51. data/spec/cli/yri_spec.rb +30 -0
  52. data/spec/code_objects/base_spec.rb +7 -0
  53. data/spec/code_objects/class_object_spec.rb +6 -1
  54. data/spec/code_objects/method_object_spec.rb +25 -0
  55. data/spec/core_ext/hash_spec.rb +10 -0
  56. data/spec/core_ext/module_spec.rb +1 -1
  57. data/spec/core_ext/string_spec.rb +50 -12
  58. data/spec/handlers/attribute_handler_spec.rb +4 -0
  59. data/spec/handlers/examples/method_handler_001.rb.txt +9 -0
  60. data/spec/handlers/method_handler_spec.rb +22 -4
  61. data/spec/parser/c_parser_spec.rb +22 -0
  62. data/spec/parser/examples/array.c.txt +3887 -0
  63. data/spec/parser/source_parser_spec.rb +29 -7
  64. data/spec/registry_spec.rb +93 -72
  65. data/spec/registry_store_spec.rb +184 -0
  66. data/spec/serializers/file_system_serializer_spec.rb +96 -75
  67. data/spec/spec_helper.rb +2 -2
  68. data/spec/tags/overload_tag_spec.rb +18 -0
  69. data/spec/templates/examples/class001.html +32 -30
  70. data/spec/templates/examples/method001.html +4 -1
  71. data/spec/templates/examples/method002.html +7 -2
  72. data/spec/templates/examples/method002.txt +1 -1
  73. data/spec/templates/examples/method003.html +30 -8
  74. data/spec/templates/examples/method003.txt +4 -4
  75. data/spec/templates/examples/method004.html +44 -0
  76. data/spec/templates/examples/method004.txt +10 -0
  77. data/spec/templates/examples/method005.html +99 -0
  78. data/spec/templates/examples/method005.txt +33 -0
  79. data/spec/templates/examples/module001.dot +1 -1
  80. data/spec/templates/examples/module001.html +391 -37
  81. data/spec/templates/examples/module001.txt +1 -1
  82. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  83. data/spec/templates/helpers/html_helper_spec.rb +83 -0
  84. data/spec/templates/helpers/method_helper_spec.rb +47 -0
  85. data/spec/templates/helpers/shared_signature_examples.rb +102 -0
  86. data/spec/templates/helpers/text_helper_spec.rb +31 -0
  87. data/spec/templates/method_spec.rb +43 -18
  88. data/spec/templates/module_spec.rb +22 -1
  89. data/spec/templates/spec_helper.rb +10 -1
  90. data/spec/yard_spec.rb +4 -3
  91. data/templates/default/class/html/constructor_details.erb +1 -1
  92. data/templates/default/docstring/html/returns_void.erb +1 -0
  93. data/templates/default/docstring/setup.rb +9 -4
  94. data/templates/default/docstring/text/returns_void.erb +1 -0
  95. data/templates/default/fulldoc/html/css/style.css +4 -2
  96. data/templates/default/fulldoc/html/full_list.erb +2 -2
  97. data/templates/default/fulldoc/html/js/app.js +1 -1
  98. data/templates/default/fulldoc/html/setup.rb +14 -6
  99. data/templates/default/layout/dot/setup.rb +1 -1
  100. data/templates/default/layout/html/breadcrumb.erb +2 -2
  101. data/templates/default/layout/html/index.erb +2 -2
  102. data/templates/default/layout/html/setup.rb +5 -5
  103. data/templates/default/method/html/header.erb +6 -4
  104. data/templates/default/method_details/html/method_signature.erb +2 -1
  105. data/templates/default/method_details/html/source.erb +1 -1
  106. data/templates/default/method_details/setup.rb +2 -1
  107. data/templates/default/method_details/text/setup.rb +1 -1
  108. data/templates/default/module/html/attribute_details.erb +4 -4
  109. data/templates/default/module/html/attribute_summary.erb +3 -3
  110. data/templates/default/module/html/box_info.erb +2 -2
  111. data/templates/default/module/html/defines.erb +1 -1
  112. data/templates/default/module/html/inherited_constants.erb +1 -1
  113. data/templates/default/module/html/inherited_methods.erb +1 -1
  114. data/templates/default/module/html/item_summary.erb +13 -4
  115. data/templates/default/module/html/method_details_list.erb +5 -4
  116. data/templates/default/module/html/method_summary.erb +5 -4
  117. data/templates/default/module/html/methodmissing.erb +1 -1
  118. data/templates/default/module/setup.rb +14 -5
  119. data/templates/default/tags/html/overload.erb +3 -2
  120. data/templates/default/tags/setup.rb +4 -0
  121. metadata +23 -2
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- YARD Release 0.4.0 "The Whole Nine" (Nov 15th 2009)
1
+ YARD Release 0.5.0 "The Longest" (Dec 14th 2009)
2
2
  ===================================================
3
3
 
4
- **Homepage**: [http://yard.rubyforge.org](http://yard.rubyforge.org)
4
+ **Homepage**: [http://yardoc.org](http://yardoc.org)
5
5
  **IRC**: **Join us on IRC in #yard on irc.freenode.net!**
6
6
  **Git**: [http://github.com/lsegal/yard](http://github.com/lsegal/yard)
7
7
  **Author**: Loren Segal
@@ -197,6 +197,14 @@ work with the stdlib or core Ruby libraries, only the active project. Example:
197
197
  Note that class methods must not be referred to with the "::" namespace
198
198
  separator. Only modules, classes and constants should use "::".
199
199
 
200
+ You can also do lookups on any installed gems. Just make sure to build the
201
+ .yardoc databases for installed gems with:
202
+
203
+ $ sudo yardoc --build-gems
204
+
205
+ If you don't have sudo access, it will write these files to your `~/.yard`
206
+ directory. `yri` will also cache lookups there.
207
+
200
208
  **4. `yard-graph` Graphviz Generator**
201
209
 
202
210
  You can use `yard-graph` to generate dot graphs of your code. This, of course,
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + "/../lib/yard"
2
+ require "benchmark"
3
+ include YARD::CLI
4
+
5
+ class YARD::CLI::YRI
6
+ def print_object(object) end
7
+ end
8
+
9
+ def remove_cache
10
+ File.unlink(YRI::CACHE_FILE)
11
+ end
12
+
13
+ TIMES = 10
14
+ NAME = 'YARD'
15
+ remove_cache; YRI.run(NAME)
16
+ Benchmark.bmbm do |x|
17
+ x.report("cache ") { TIMES.times { YRI.run(NAME) } }
18
+ x.report("no-cache") { TIMES.times { remove_cache; YRI.run(NAME) } }
19
+ end
data/bin/yri CHANGED
@@ -1,29 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + '/../lib/yard'
3
3
 
4
- YARD::Registry.load
5
-
6
- if ARGV[0] == '-T' || ARGV[0] == '--no-pager'
7
- output = YARD::Serializers::StdoutSerializer.new
8
- ARGV.shift
9
- else
10
- output = YARD::Serializers::ProcessSerializer.new('less')
11
- end
12
-
13
- if ARGV[0].nil? || ARGV[0].empty?
14
- puts "Missing object argument"
15
- exit(1)
16
- end
17
-
18
- obj = YARD::Registry.at(ARGV[0])
19
- if obj.nil?
20
- puts "No documentation for #{ARGV[0]}"
21
- exit(1)
22
- end
23
-
24
- if obj.type == :method && obj.is_alias?
25
- tmp = P(obj.namespace, (obj.scope == :instance ? "#" : "") +
26
- obj.namespace.aliases[obj].to_s)
27
- obj = tmp unless YARD::CodeObjects::Proxy === tmp
28
- end
29
- obj.format(:serializer => output)
4
+ YARD::CLI::YRI.run(*ARGV)
data/docs/WhatsNew.md CHANGED
@@ -1,3 +1,102 @@
1
+ What's New in 0.5.x?
2
+ ====================
3
+
4
+ 1. **Support for documenting native Ruby C code**
5
+ 2. **Incremental parsing and output generation with `yardoc -c`**
6
+ 2. **Improved `yri` support to perform lookups on installed Gems**
7
+ 3. **Added `yardoc --default-return` and `yardoc --hide-void-return`**
8
+ 4. **Multiple syntax highlighting language support**
9
+ 5. **New .yardoc format**
10
+
11
+ Support for documenting native Ruby C code
12
+ ------------------------------------------
13
+
14
+ It is now possible to document native Ruby extensions with YARD with a new
15
+ C parser mostly borrowed from RDoc. This enables the ability to document
16
+ Ruby's core and stdlibs which will be hosted on http://yardoc.org/docs. In
17
+ addition, the .yardoc dump for the Ruby-core classes will become available
18
+ as an installable gem for yri support (see #3).
19
+
20
+ Incremental parsing and output generation with `yardoc -c`
21
+ ----------------------------------------------------------
22
+
23
+ YARD now compares file checksums before parsing when using `yardoc -c`
24
+ (aka `yardoc --use-cache`) to do incremental parsing of only the files that
25
+ have changed. HTML (or other output format) generation will also only be
26
+ done on the objects that were parsed from changed files. This makes doing
27
+ a documentation development cycle much faster for quick HTML previews. Just
28
+ remember that when using incremental output generation, the index will not
29
+ be rebuilt and inter-file links might not hook up right, so it is best to
30
+ perform a full rebuild at the end of such previews.
31
+
32
+ Improved `yri` support to perform lookups on installed Gems
33
+ -----------------------------------------------------------
34
+
35
+ The `yri` executable can now perform lookups on gems that have been parsed
36
+ by yard. Therefore, to use this command you must first parse all gems with
37
+ YARD. To parse all gems, use the following command:
38
+
39
+ $ sudo yardoc --build-gems
40
+
41
+ The above command builds a .yardoc file for all installed gems in the
42
+ respective gem directory. If you do not have write access to the gem path,
43
+ YARD will write the yardoc file to `~/.yard/gem_index/NAME-VERSION.yardoc`.
44
+
45
+ Note: you can also use `--re-build-gems` to force re-parsing of all gems.
46
+
47
+ You can now do lookups with yri:
48
+
49
+ $ yri JSON
50
+
51
+ All lookups are cached to `~/.yard/yri_cache` for quicker lookups the second
52
+ time onward.
53
+
54
+ Added `yardoc --default-return` and `yardoc --hide-void-return`
55
+ ---------------------------------------------------------------
56
+
57
+ YARD defaults to displaying (Object) as the default return type of any
58
+ method that has not declared a @return tag. To customize the default
59
+ return type, you can specify:
60
+
61
+ $ yardoc --default-return 'MyDefaultType'
62
+
63
+ You can also use the empty string to list no return type.
64
+
65
+ In addition, you can use --hide-void-return to ignore any method that
66
+ defines itself as a void type by: `@return [void]`
67
+
68
+ Multiple syntax highlighting language support
69
+ ---------------------------------------------
70
+
71
+ YARD now supports the ability to specify a language type for code blocks in
72
+ docstrings. Although no actual highlighting support is added for any language
73
+ but Ruby, you can add your own support by writing your own helper method:
74
+
75
+ # Where LANGNAME is the language:
76
+ def html_syntax_highlight_LANGNAME(source)
77
+ # return highlighted HTML
78
+ end
79
+
80
+ To use this language in code blocks, prefix the block with `!!!LANGNAME`:
81
+
82
+ !!!plain
83
+ !!!python
84
+ def python_code(self):
85
+ return self
86
+
87
+ By the same token. you can now use `!!!plain` to ignore highlighting for
88
+ a specific code block.
89
+
90
+ New .yardoc format
91
+ ------------------
92
+
93
+ To make the above yri support possible, the .yardoc format was redesigned
94
+ to be a directory instead of a file. YARD can still load old .yardoc files,
95
+ but they will be automatically upgraded if re-saved. The new .yardoc format
96
+ does have a larger memory footprint, but this will hopefully be optimized
97
+ downward.
98
+
99
+
1
100
  What's New in 0.4.x?
2
101
  ====================
3
102
 
@@ -14,6 +14,7 @@ class Gem::Specification
14
14
  @has_rdoc == 'yard'
15
15
  end
16
16
 
17
+ undef has_rdoc?
17
18
  def has_rdoc?
18
19
  @has_rdoc && @has_rdoc != 'yard'
19
20
  end
@@ -52,6 +53,7 @@ class Gem::DocManager
52
53
  Dir.chdir(old_pwd)
53
54
  end
54
55
 
56
+ undef setup_rdoc
55
57
  def setup_rdoc
56
58
  if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
57
59
  raise Gem::FilePermissionError.new(@doc_dir)
data/lib/yard.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module YARD
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  ROOT = File.dirname(__FILE__)
4
4
  TEMPLATE_ROOT = File.join(File.dirname(__FILE__), '..', 'templates')
5
5
  CONFIG_DIR = File.expand_path('~/.yard')
@@ -31,7 +31,7 @@ module YARD
31
31
  ignored_plugins = []
32
32
  end
33
33
 
34
- Gem.source_index.entries.each do |pkgname, gem|
34
+ Gem.source_index.find_name('').each do |gem|
35
35
  begin
36
36
  if gem.name =~ /^yard[-_]/ && !ignored_plugins.include?(gem.name)
37
37
  log.debug "Loading plugin '#{gem.name}'..."
data/lib/yard/autoload.rb CHANGED
@@ -3,8 +3,10 @@ def __p(*path) File.join(YARD::ROOT, 'yard', *path) end
3
3
 
4
4
  module YARD
5
5
  module CLI # Namespace for command-line interface components
6
+ autoload :Base, __p('cli/base')
6
7
  autoload :YardGraph, __p('cli/yard_graph')
7
8
  autoload :Yardoc, __p('cli/yardoc')
9
+ autoload :YRI, __p('cli/yri')
8
10
  end
9
11
 
10
12
  # A "code object" is defined as any entity in the Ruby language.
@@ -100,6 +102,7 @@ module YARD
100
102
  autoload :RubyParser, __p('parser/ruby/ruby_parser')
101
103
  end
102
104
 
105
+ autoload :CParser, __p('parser/c_parser')
103
106
  autoload :ParserSyntaxError, __p('parser/source_parser')
104
107
  autoload :SourceParser, __p('parser/source_parser')
105
108
  autoload :UndocumentableError, __p('parser/source_parser')
@@ -114,6 +117,7 @@ module YARD
114
117
  autoload :FileSystemSerializer, __p('serializers/file_system_serializer')
115
118
  autoload :ProcessSerializer, __p('serializers/process_serializer')
116
119
  autoload :StdoutSerializer, __p('serializers/stdout_serializer')
120
+ autoload :YardocSerializer, __p('serializers/yardoc_serializer')
117
121
  end
118
122
 
119
123
  module Tags # Namespace for Tag components
@@ -145,10 +149,11 @@ module YARD
145
149
  autoload :Template, __p('templates/template')
146
150
  end
147
151
 
148
- autoload :Docstring, __p('docstring')
149
- autoload :Logger, __p('logging')
150
- autoload :Registry, __p('registry')
151
- autoload :Verifier, __p('verifier')
152
+ autoload :Docstring, __p('docstring')
153
+ autoload :Logger, __p('logging')
154
+ autoload :Registry, __p('registry')
155
+ autoload :RegistryStore, __p('registry_store')
156
+ autoload :Verifier, __p('verifier')
152
157
  end
153
158
 
154
159
  undef __p
@@ -0,0 +1,26 @@
1
+ require 'optparse'
2
+
3
+ module YARD
4
+ module CLI
5
+ # Abstract base class for CLI utilities. Provides some helper methods for
6
+ # the option parser
7
+ #
8
+ # @abstract
9
+ class Base
10
+ # Adds a set of common options to the tail of the OptionParser
11
+ #
12
+ # @param [OptionParser] opts the option parser object
13
+ # @return [void]
14
+ def common_options(opts)
15
+ opts.separator ""
16
+ opts.separator "Other options:"
17
+ opts.on_tail('-q', '--quiet', 'Show no warnings.') { log.level = Logger::ERROR }
18
+ opts.on_tail('--verbose', 'Show more information.') { log.level = Logger::INFO }
19
+ opts.on_tail('--debug', 'Show debugging information.') { log.level = Logger::DEBUG }
20
+ opts.on_tail('--backtrace', 'Show stack traces') { log.show_backtraces = true }
21
+ opts.on_tail('-v', '--version', 'Show version.') { puts "yard #{YARD::VERSION}"; exit }
22
+ opts.on_tail('-h', '--help', 'Show this help.') { puts opts; exit }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,12 +1,10 @@
1
- require 'optparse'
2
-
3
1
  module YARD
4
2
  module CLI
5
3
  # A command-line utility to generate Graphviz graphs from
6
4
  # a set of objects
7
5
  #
8
6
  # @see YardGraph#run
9
- class YardGraph
7
+ class YardGraph < Base
10
8
  # The options parsed out of the commandline.
11
9
  # Default options are:
12
10
  # :format => :dot,
@@ -90,12 +88,7 @@ module YARD
90
88
  @serializer.instance_eval "def serialized_path(object) #{file.inspect} end"
91
89
  end
92
90
 
93
- opts.separator ""
94
- opts.separator "Other options:"
95
- opts.on_tail('-q', '--quiet', 'Show no warnings') { log.level = Logger::ERROR }
96
- opts.on_tail('--verbose', 'Show debugging information') { log.level = Logger::DEBUG }
97
- opts.on_tail('-v', '--version', 'Show version.') { puts "yard #{YARD::VERSION}"; exit }
98
- opts.on_tail('-h', '--help', 'Show this help.') { puts opts; exit }
91
+ common_options(opts)
99
92
 
100
93
  begin
101
94
  opts.parse!(args)
@@ -1,8 +1,9 @@
1
- require 'optparse'
1
+ require 'digest/sha1'
2
+ require 'fileutils'
2
3
 
3
4
  module YARD
4
5
  module CLI
5
- class Yardoc
6
+ class Yardoc < Base
6
7
  # The configuration filename to load extra options from
7
8
  DEFAULT_YARDOPTS_FILE = ".yardopts"
8
9
 
@@ -13,9 +14,10 @@ module YARD
13
14
  # @return [Array<String>] list of Ruby source files to process
14
15
  attr_accessor :files
15
16
 
16
- # @return [Boolean] whether to reparse the source files even if the
17
- # .yardoc already exists.
18
- attr_accessor :reload
17
+ # @return [Boolean] whether to use the existing yardoc db if the
18
+ # .yardoc already exists. Also makes use of file checksums to
19
+ # parse only changed files.
20
+ attr_accessor :use_cache
19
21
 
20
22
  # @return [Boolean] whether to generate output
21
23
  attr_accessor :generate
@@ -30,17 +32,21 @@ module YARD
30
32
 
31
33
  # Creates a new instance of the commandline utility
32
34
  def initialize
33
- @options = SymbolHash[
35
+ @options = SymbolHash.new(false)
36
+ @options.update(
34
37
  :format => :html,
35
38
  :template => :default,
36
39
  :markup => :rdoc,
37
- :serializer => YARD::Serializers::FileSystemSerializer.new,
40
+ :serializer => YARD::Serializers::FileSystemSerializer.new,
41
+ :default_return => "Object",
42
+ :hide_void_return => false,
43
+ :no_highlight => false,
38
44
  :files => [],
39
45
  :visibilities => [:public],
40
46
  :verifier => nil
41
- ]
47
+ )
42
48
  @files = []
43
- @reload = true
49
+ @use_cache = false
44
50
  @generate = true
45
51
  @options_file = DEFAULT_YARDOPTS_FILE
46
52
  end
@@ -49,15 +55,27 @@ module YARD
49
55
  # output if set.
50
56
  #
51
57
  # @param [Array<String>] args the list of arguments
52
- # @return [nil]
58
+ # @return [void]
53
59
  def run(*args)
54
60
  args += support_rdoc_document_file!
55
61
  optparse(*yardopts)
56
62
  optparse(*args)
57
- Registry.load(files, reload)
63
+
64
+ Registry.load if use_cache
65
+ YARD.parse(files)
66
+ Registry.save(use_cache)
58
67
 
59
68
  if generate
60
- Templates::Engine.generate(all_objects, options)
69
+ if use_cache
70
+ objects = all_objects
71
+ Registry.all # load all
72
+ objects.each do |object|
73
+ opts = options.merge(:object => object, :type => :layout)
74
+ Templates::Engine.render(opts)
75
+ end
76
+ else
77
+ Templates::Engine.generate(all_objects, options)
78
+ end
61
79
  end
62
80
 
63
81
  true
@@ -68,13 +86,25 @@ module YARD
68
86
  #
69
87
  # @return [Array<CodeObjects::Base>] a list of code objects to process
70
88
  def all_objects
71
- Registry.all(:root, :module, :class)
89
+ types = [:root, :module, :class]
90
+ if use_cache
91
+ Registry.paths(false).map do |path|
92
+ obj = Registry.at(path)
93
+ if types.include?(obj.type)
94
+ obj
95
+ else
96
+ nil
97
+ end
98
+ end.compact
99
+ else
100
+ Registry.all(*types)
101
+ end
72
102
  end
73
103
 
74
104
  # Parses the .yardopts file for default yard options
75
- # @return [nil]
105
+ # @return [void]
76
106
  def yardopts
77
- IO.read(options_file).split(/\s+/)
107
+ IO.read(options_file).shell_split
78
108
  rescue Errno::ENOENT
79
109
  []
80
110
  end
@@ -82,9 +112,9 @@ module YARD
82
112
  private
83
113
 
84
114
  # Reads a .document file in the directory to get source file globs
85
- # @return [nil]
115
+ # @return [void]
86
116
  def support_rdoc_document_file!
87
- IO.read(".document").split(/\s+/)
117
+ IO.read(".document").gsub(/^[ \t]*#.+/m, '').split(/\s+/)
88
118
  rescue Errno::ENOENT
89
119
  []
90
120
  end
@@ -107,7 +137,7 @@ module YARD
107
137
  # @example Parses a set of Ruby files with a separator and extra files
108
138
  # parse_files %w(file1 file2 - extrafile1 extrafile2)
109
139
  # @param [Array<String>] files the list of files to parse
110
- # @return [nil]
140
+ # @return [void]
111
141
  def parse_files(*files)
112
142
  self.files = []
113
143
  seen_extra_files_marker = false
@@ -126,22 +156,39 @@ module YARD
126
156
  end
127
157
  end
128
158
 
129
- # @param [Array<String>] expressions a list of query expressions to
130
- # turn into a proc
131
- def add_verifier(*expressions)
132
-
159
+ # Builds .yardoc files for all non-existing gems
160
+ # @param [Boolean] rebuild Forces rebuild of all gems
161
+ def build_gems(rebuild = false)
162
+ require 'rubygems'
163
+ Gem.source_index.find_name('').each do |spec|
164
+ reload = true
165
+ dir = Registry.yardoc_file_for_gem(spec.name)
166
+ next unless dir
167
+ if File.directory?(dir) && !rebuild
168
+ log.debug "#{spec.name} index already exists at '#{dir}'"
169
+ else
170
+ Dir.chdir(spec.full_gem_path)
171
+ log.info "Building yardoc index for gem: #{spec.full_name}"
172
+ yfile = Registry.yardoc_file_for_gem(spec.name, ">= 0", true)
173
+ Registry.clear
174
+ Yardoc.run('-n', '-b', yfile)
175
+ reload = false
176
+ end
177
+ end
178
+ exit(0)
133
179
  end
134
180
 
135
181
  # Parses commandline options.
136
182
  # @param [Array<String>] args each tokenized argument
137
183
  def optparse(*args)
138
184
  query_expressions = []
185
+ do_build_gems, do_rebuild_gems = false, false
139
186
  serialopts = SymbolHash.new
140
187
 
141
188
  opts = OptionParser.new
142
189
  opts.banner = "Usage: yardoc [options] [source_files [- extra_files]]"
143
190
 
144
- opts.separator "(if a list of source files is omitted, lib/**/*.rb is used.)"
191
+ opts.separator "(if a list of source files is omitted, lib/**/*.rb ext/**/*.c is used.)"
145
192
  opts.separator ""
146
193
  opts.separator "Example: yardoc -o documentation/ - FAQ LICENSE"
147
194
  opts.separator " The above example outputs documentation for files in"
@@ -155,9 +202,9 @@ module YARD
155
202
  opts.separator "General Options:"
156
203
 
157
204
  opts.on('-c', '--use-cache [FILE]',
158
- 'Use the cached .yardoc db to generate documentation. (defaults to no cache)') do |file|
205
+ "Use the cached .yardoc db to generate documentation. (defaults to no cache)") do |file|
159
206
  YARD::Registry.yardoc_file = file if file
160
- self.reload = false
207
+ self.use_cache = true
161
208
  end
162
209
 
163
210
  opts.on('-b', '--db FILE', 'Use a specified .yardoc db to load from or save to. (defaults to .yardoc)') do |yfile|
@@ -178,6 +225,15 @@ module YARD
178
225
  opts.on('--legacy', 'Use old style parser and handlers. Unavailable under Ruby 1.8.x') do
179
226
  YARD::Parser::SourceParser.parser_type = :ruby18
180
227
  end
228
+
229
+ opts.on('--build-gems', 'Builds .yardoc files for all gems (implies -n)') do
230
+ do_build_gems = true
231
+ end
232
+
233
+ opts.on('--re-build-gems', 'Forces building .yardoc files for all gems (implies -n)') do
234
+ do_build_gems = true
235
+ do_rebuild_gems = true
236
+ end
181
237
 
182
238
  opts.separator ""
183
239
  opts.separator "Output options:"
@@ -202,6 +258,14 @@ module YARD
202
258
  options[:no_highlight] = true
203
259
  end
204
260
 
261
+ opts.on('--default-return TYPE', "Shown if method has no return type. Defaults to 'Object'") do |type|
262
+ options[:default_return] = type
263
+ end
264
+
265
+ opts.on('--hide-void-return', "Hides return types specified as 'void'. Default is shown.") do
266
+ options[:hide_void_return] = true
267
+ end
268
+
205
269
  opts.on('--query QUERY', "Only show objects that match a specific query") do |query|
206
270
  query_expressions << query.taint
207
271
  end
@@ -247,15 +311,10 @@ module YARD
247
311
 
248
312
  opts.on('-f', '--format FORMAT',
249
313
  'The output format for the template. (defaults to html)') do |format|
250
- options[:format] = format
314
+ options[:format] = format.to_sym
251
315
  end
252
316
 
253
- opts.separator ""
254
- opts.separator "Other options:"
255
- opts.on_tail('-q', '--quiet', 'Show no warnings.') { log.level = Logger::ERROR }
256
- opts.on_tail('--verbose', 'Show debugging information.') { log.level = Logger::DEBUG }
257
- opts.on_tail('-v', '--version', 'Show version.') { puts "yard #{YARD::VERSION}"; exit }
258
- opts.on_tail('-h', '--help', 'Show this help.') { puts opts; exit }
317
+ common_options(opts)
259
318
 
260
319
  begin
261
320
  opts.parse!(args)
@@ -266,8 +325,9 @@ module YARD
266
325
  end
267
326
 
268
327
  # Last minute modifications
328
+ build_gems(do_rebuild_gems) if do_build_gems
269
329
  parse_files(*args) unless args.empty?
270
- self.files = ['lib/**/*.rb'] if self.files.empty?
330
+ self.files = ['lib/**/*.rb', 'ext/**/*.c'] if self.files.empty?
271
331
  options[:verifier] = Verifier.new(*query_expressions) unless query_expressions.empty?
272
332
  options[:visibilities].uniq!
273
333
  options[:serializer] ||= Serializers::FileSystemSerializer.new(serialopts)