yard 0.2.2 → 0.2.3

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 (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.markdown +200 -0
  3. data/Rakefile +6 -1
  4. data/benchmarks/format_args.rb +46 -0
  5. data/benchmarks/parsing.rb +13 -1
  6. data/benchmarks/rdoc_vs_yardoc.rb +10 -0
  7. data/benchmarks/ripper_parser.rb +12 -0
  8. data/docs/CODE_OBJECTS.markdown +121 -0
  9. data/docs/FAQ.markdown +34 -0
  10. data/docs/GENERATORS.markdown +211 -0
  11. data/docs/GETTING_STARTED.markdown +263 -0
  12. data/docs/GLOSSARY.markdown +13 -0
  13. data/docs/HANDLERS.markdown +158 -0
  14. data/docs/OVERVIEW.markdown +64 -0
  15. data/docs/PARSER.markdown +180 -0
  16. data/docs/TAGS.markdown +181 -0
  17. data/docs/WHATSNEW.markdown +96 -0
  18. data/docs/images/code-objects-class-diagram.png +0 -0
  19. data/docs/images/handlers-class-diagram.png +0 -0
  20. data/docs/images/overview-class-diagram.png +0 -0
  21. data/docs/images/parser-class-diagram.png +0 -0
  22. data/docs/images/tags-class-diagram.png +0 -0
  23. data/lib/yard.rb +4 -1
  24. data/lib/yard/autoload.rb +79 -31
  25. data/lib/yard/cli/yard_graph.rb +8 -2
  26. data/lib/yard/cli/yardoc.rb +61 -8
  27. data/lib/yard/code_objects/base.rb +78 -135
  28. data/lib/yard/code_objects/class_object.rb +9 -8
  29. data/lib/yard/code_objects/constant_object.rb +1 -0
  30. data/lib/yard/code_objects/extended_method_object.rb +9 -0
  31. data/lib/yard/code_objects/method_object.rb +18 -5
  32. data/lib/yard/code_objects/module_object.rb +8 -1
  33. data/lib/yard/code_objects/namespace_object.rb +25 -16
  34. data/lib/yard/code_objects/proxy.rb +22 -22
  35. data/lib/yard/core_ext/file.rb +1 -1
  36. data/lib/yard/core_ext/string.rb +0 -4
  37. data/lib/yard/core_ext/symbol_hash.rb +3 -2
  38. data/lib/yard/docstring.rb +180 -0
  39. data/lib/yard/generators/base.rb +33 -13
  40. data/lib/yard/generators/class_generator.rb +4 -2
  41. data/lib/yard/generators/constants_generator.rb +3 -2
  42. data/lib/yard/generators/full_doc_generator.rb +76 -9
  43. data/lib/yard/generators/helpers/base_helper.rb +18 -1
  44. data/lib/yard/generators/helpers/filter_helper.rb +2 -2
  45. data/lib/yard/generators/helpers/html_helper.rb +94 -39
  46. data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +49 -0
  47. data/lib/yard/generators/helpers/markup_helper.rb +86 -0
  48. data/lib/yard/generators/helpers/method_helper.rb +23 -7
  49. data/lib/yard/generators/method_generator.rb +15 -3
  50. data/lib/yard/generators/method_listing_generator.rb +3 -3
  51. data/lib/yard/generators/mixins_generator.rb +8 -2
  52. data/lib/yard/generators/module_generator.rb +3 -2
  53. data/lib/yard/generators/overloads_generator.rb +20 -0
  54. data/lib/yard/generators/quick_doc_generator.rb +3 -9
  55. data/lib/yard/generators/root_generator.rb +32 -0
  56. data/lib/yard/generators/source_generator.rb +2 -17
  57. data/lib/yard/generators/tags_generator.rb +34 -6
  58. data/lib/yard/generators/uml_generator.rb +16 -6
  59. data/lib/yard/handlers/base.rb +88 -253
  60. data/lib/yard/handlers/processor.rb +72 -0
  61. data/lib/yard/handlers/ruby/alias_handler.rb +38 -0
  62. data/lib/yard/handlers/ruby/attribute_handler.rb +69 -0
  63. data/lib/yard/handlers/ruby/base.rb +72 -0
  64. data/lib/yard/handlers/ruby/class_condition_handler.rb +70 -0
  65. data/lib/yard/handlers/ruby/class_handler.rb +74 -0
  66. data/lib/yard/handlers/ruby/class_variable_handler.rb +11 -0
  67. data/lib/yard/handlers/ruby/constant_handler.rb +12 -0
  68. data/lib/yard/handlers/ruby/exception_handler.rb +22 -0
  69. data/lib/yard/handlers/ruby/extend_handler.rb +19 -0
  70. data/lib/yard/handlers/{alias_handler.rb → ruby/legacy/alias_handler.rb} +3 -4
  71. data/lib/yard/handlers/{attribute_handler.rb → ruby/legacy/attribute_handler.rb} +2 -2
  72. data/lib/yard/handlers/ruby/legacy/base.rb +198 -0
  73. data/lib/yard/handlers/{class_handler.rb → ruby/legacy/class_handler.rb} +18 -6
  74. data/lib/yard/handlers/{class_variable_handler.rb → ruby/legacy/class_variable_handler.rb} +1 -1
  75. data/lib/yard/handlers/{constant_handler.rb → ruby/legacy/constant_handler.rb} +2 -2
  76. data/lib/yard/handlers/{exception_handler.rb → ruby/legacy/exception_handler.rb} +3 -3
  77. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +18 -0
  78. data/lib/yard/handlers/ruby/legacy/method_handler.rb +31 -0
  79. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +28 -0
  80. data/lib/yard/handlers/{module_handler.rb → ruby/legacy/module_handler.rb} +1 -1
  81. data/lib/yard/handlers/{visibility_handler.rb → ruby/legacy/visibility_handler.rb} +1 -1
  82. data/lib/yard/handlers/{yield_handler.rb → ruby/legacy/yield_handler.rb} +4 -4
  83. data/lib/yard/handlers/ruby/method_condition_handler.rb +7 -0
  84. data/lib/yard/handlers/ruby/method_handler.rb +48 -0
  85. data/lib/yard/handlers/ruby/mixin_handler.rb +25 -0
  86. data/lib/yard/handlers/ruby/module_handler.rb +9 -0
  87. data/lib/yard/handlers/ruby/visibility_handler.rb +18 -0
  88. data/lib/yard/handlers/ruby/yield_handler.rb +28 -0
  89. data/lib/yard/parser/ruby/ast_node.rb +263 -0
  90. data/lib/yard/parser/{ruby_lex.rb → ruby/legacy/ruby_lex.rb} +258 -259
  91. data/lib/yard/parser/{statement.rb → ruby/legacy/statement.rb} +8 -4
  92. data/lib/yard/parser/ruby/legacy/statement_list.rb +262 -0
  93. data/lib/yard/parser/{token_list.rb → ruby/legacy/token_list.rb} +1 -1
  94. data/lib/yard/parser/ruby/ruby_parser.rb +307 -0
  95. data/lib/yard/parser/source_parser.rb +76 -45
  96. data/lib/yard/rake/yardoc_task.rb +6 -1
  97. data/lib/yard/registry.rb +45 -19
  98. data/lib/yard/serializers/file_system_serializer.rb +8 -3
  99. data/lib/yard/tags/default_factory.rb +70 -10
  100. data/lib/yard/tags/default_tag.rb +12 -0
  101. data/lib/yard/tags/library.rb +65 -26
  102. data/lib/yard/tags/option_tag.rb +12 -0
  103. data/lib/yard/tags/overload_tag.rb +62 -0
  104. data/lib/yard/tags/ref_tag.rb +7 -0
  105. data/lib/yard/tags/ref_tag_list.rb +27 -0
  106. data/lib/yard/tags/tag.rb +1 -0
  107. data/lib/yard/tags/tag_format_error.rb +6 -0
  108. data/spec/cli/yardoc_spec.rb +43 -0
  109. data/spec/code_objects/base_spec.rb +56 -68
  110. data/spec/code_objects/class_object_spec.rb +18 -6
  111. data/spec/code_objects/constants_spec.rb +2 -0
  112. data/spec/code_objects/method_object_spec.rb +33 -5
  113. data/spec/code_objects/module_object_spec.rb +66 -8
  114. data/spec/code_objects/namespace_object_spec.rb +37 -17
  115. data/spec/code_objects/proxy_spec.rb +13 -2
  116. data/spec/core_ext/string_spec.rb +14 -2
  117. data/spec/core_ext/symbol_hash_spec.rb +9 -3
  118. data/spec/docstring_spec.rb +139 -0
  119. data/spec/generators/full_doc_generator_spec.rb +29 -0
  120. data/spec/generators/helpers/html_helper_spec.rb +74 -0
  121. data/spec/generators/helpers/markup_helper_spec.rb +95 -0
  122. data/spec/handlers/alias_handler_spec.rb +16 -3
  123. data/spec/handlers/attribute_handler_spec.rb +1 -1
  124. data/spec/handlers/base_spec.rb +15 -141
  125. data/spec/handlers/class_condition_handler_spec.rb +49 -0
  126. data/spec/handlers/class_handler_spec.rb +44 -3
  127. data/spec/handlers/class_variable_handler_spec.rb +1 -1
  128. data/spec/handlers/constant_handler_spec.rb +1 -1
  129. data/spec/handlers/examples/alias_handler_001.rb.txt +7 -3
  130. data/spec/handlers/examples/class_condition_handler_001.rb.txt +61 -0
  131. data/spec/handlers/examples/class_handler_001.rb.txt +33 -0
  132. data/spec/handlers/examples/exception_handler_001.rb.txt +1 -1
  133. data/spec/handlers/examples/extend_handler_001.rb.txt +8 -0
  134. data/spec/handlers/examples/method_condition_handler_001.rb.txt +10 -0
  135. data/spec/handlers/examples/method_handler_001.rb.txt +16 -4
  136. data/spec/handlers/examples/mixin_handler_001.rb.txt +10 -2
  137. data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
  138. data/spec/handlers/examples/visibility_handler_001.rb.txt +1 -1
  139. data/spec/handlers/exception_handler_spec.rb +2 -2
  140. data/spec/handlers/extend_handler_spec.rb +15 -0
  141. data/spec/handlers/legacy_base_spec.rb +128 -0
  142. data/spec/handlers/method_condition_handler_spec.rb +14 -0
  143. data/spec/handlers/method_handler_spec.rb +38 -5
  144. data/spec/handlers/mixin_handler_spec.rb +15 -7
  145. data/spec/handlers/module_handler_spec.rb +5 -1
  146. data/spec/handlers/processor_spec.rb +19 -0
  147. data/spec/handlers/ruby/base_spec.rb +90 -0
  148. data/spec/handlers/ruby/legacy/base_spec.rb +53 -0
  149. data/spec/handlers/spec_helper.rb +22 -16
  150. data/spec/handlers/visibility_handler_spec.rb +4 -4
  151. data/spec/handlers/yield_handler_spec.rb +1 -1
  152. data/spec/parser/ruby/ast_node_spec.rb +15 -0
  153. data/spec/parser/ruby/legacy/statement_list_spec.rb +145 -0
  154. data/spec/parser/{token_list_spec.rb → ruby/legacy/token_list_spec.rb} +4 -4
  155. data/spec/parser/source_parser_spec.rb +0 -15
  156. data/spec/rake/yardoc_task_spec.rb +48 -0
  157. data/spec/registry_spec.rb +28 -2
  158. data/spec/serializers/file_system_serializer_spec.rb +7 -1
  159. data/spec/spec_helper.rb +1 -1
  160. data/spec/tags/default_factory_spec.rb +135 -0
  161. data/spec/tags/default_tag_spec.rb +11 -0
  162. data/spec/tags/overload_tag_spec.rb +35 -0
  163. data/spec/tags/ref_tag_list_spec.rb +53 -0
  164. data/templates/default/attributes/html/header.erb +17 -5
  165. data/templates/default/attributes/text/header.erb +1 -1
  166. data/templates/default/fulldoc/html/all_files.erb +19 -0
  167. data/templates/default/fulldoc/html/all_methods.erb +8 -7
  168. data/templates/default/fulldoc/html/all_namespaces.erb +4 -1
  169. data/templates/default/fulldoc/html/app.js +1 -1
  170. data/templates/default/fulldoc/html/{readme.erb → file.erb} +2 -2
  171. data/templates/default/fulldoc/html/header.erb +1 -1
  172. data/templates/default/fulldoc/html/index.erb +4 -3
  173. data/templates/default/fulldoc/html/style.css +13 -3
  174. data/templates/default/fulldoc/html/syntax_highlight.css +8 -5
  175. data/templates/default/method/text/header.erb +1 -0
  176. data/templates/default/method/text/title.erb +1 -0
  177. data/templates/default/methodsignature/html/main.erb +10 -8
  178. data/templates/default/methodsignature/text/main.erb +4 -1
  179. data/templates/default/methodsummary/html/summary.erb +8 -4
  180. data/templates/default/methodsummary/text/summary.erb +4 -1
  181. data/templates/default/mixins/html/header.erb +3 -3
  182. data/templates/default/overloads/html/header.erb +8 -0
  183. data/templates/default/overloads/text/header.erb +8 -0
  184. data/templates/default/root/html/header.erb +4 -0
  185. data/templates/default/tags/html/example.erb +20 -0
  186. data/templates/default/tags/html/option.erb +27 -0
  187. data/templates/default/tags/html/param.erb +21 -0
  188. data/templates/default/tags/html/tags.erb +4 -1
  189. data/templates/default/tags/html/todo.erb +8 -0
  190. data/templates/default/tags/text/example.erb +14 -0
  191. data/templates/default/tags/text/header.erb +3 -3
  192. data/templates/default/tags/text/option.erb +5 -0
  193. data/templates/default/tags/text/param.erb +9 -0
  194. data/templates/default/uml/dot/dependencies.erb +1 -1
  195. data/templates/default/uml/dot/info.erb +1 -1
  196. data/templates/default/uml/dot/superclasses.erb +2 -2
  197. data/templates/javadoc/methodsummary/html/summary.erb +2 -2
  198. data/templates/javadoc/mixins/html/header.erb +3 -3
  199. metadata +108 -139
  200. data/README +0 -211
  201. data/lib/yard/handlers/method_handler.rb +0 -27
  202. data/lib/yard/handlers/mixin_handler.rb +0 -16
  203. data/lib/yard/parser/statement_list.rb +0 -167
  204. data/lib/yard/tags/merbdoc_factory.rb +0 -47
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2008 Loren Segal
1
+ Copyright (c) 2007-2009 Loren Segal
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.markdown ADDED
@@ -0,0 +1,200 @@
1
+ YARD Release 0.2.3 (June 7th 2009)
2
+ ===================================
3
+
4
+ **Homepage**: [http://yard.rubyforge.org](http://yard.rubyforge.org)
5
+ **IRC**: **Join us on IRC in #yard on irc.freenode.net!**
6
+ **Git**: [http://github.com/lsegal/yard](http://github.com/lsegal/yard)
7
+ **Author**: Loren Segal
8
+ **Copyright**: 2007-2009
9
+ **License**: MIT License
10
+
11
+
12
+ SYNOPSIS
13
+ --------
14
+
15
+ YARD is a documentation generation tool for the Ruby programming language.

16
+ It enables the user to generate consistent, usable documentation that can be

17
+ exported to a number of formats very easily, and also supports extending for

18
+ custom Ruby constructs such as custom class level definitions. Below is a

19
+ summary of some of YARD's notable features.
20
+
21
+
22
+ FEATURE LIST
23
+ ------------
24
+
25
+ **1. RDoc/SimpleMarkup Formatting Compatibility**: YARD is made to be compatible

26
+ with RDoc formatting. In fact, YARD does no processing on RDoc documentation

27
+ strings, and leaves this up to the output generation tool to decide how to

28
+ render the documentation.

29
+
30
+ **2. Yardoc Meta-tag Formatting Like Python, Java, Objective-C and other languages**:

31
+ YARD uses a '@tag' style definition syntax for meta tags alongside regular code

32
+ documentation. These tags should be able to happily sit side by side RDoc formatted

33
+ documentation, but provide a much more consistent and usable way to describe

34
+ important information about objects, such as what parameters they take and what types
35
+ they are expected to be, what type a
method should return, what exceptions it can
36
+ raise, if it is deprecated, etc.. It also allows information to be better (and more
37
+ consistently) organized
during the output generation phase. You can find a list
38
+ of tags in the {file:GETTING_STARTED.markdown#taglist GETTING_STARTED.markdown} file.
39
+
40
+ YARD also supports an optional "types" declarations for certain tags.

41
+ This allows the developer to document type signatures for ruby methods and

42
+ parameters in a non intrusive but helpful and consistent manner. Instead of

43
+ describing this data in the body of the description, a developer may formally

44
+ declare the parameter or return type(s) in a single line. Consider the

45
+ following Yardoc'd method:

46
+
47
+ ##
48
+ # Reverses the contents of a String or IO object.
49
+ #
50
+ # @param [String, #read] contents the contents to reverse
51
+ # @return [String] the contents reversed lexically
52
+ def reverse(contents)
53
+ contents = contents.read if respond_to? :read
54
+ contents.reverse
55
+ end
56
+
57
+ With the above @param tag, we learn that the contents parameter can either be
58
+ a String or any object that responds to the 'read' method, which is more

59
+ powerful than the textual description, which says it should be an IO object.

60
+ This also informs the developer that they should expect to receive a String

61
+ object returned by the method, and although this may be obvious for a

62
+ 'reverse' method, it becomes very useful when the method name may not be as

63
+ descriptive.

64
+
65
+ **3. Custom Constructs and Extensibility of YARD**: Take for instance the example:

66
+
67
+ class A
68
+ class << self
69
+ def define_name(name, value)
70
+ class_eval "def #{name}; #{value.inspect} end"
71
+ end
72
+ end
73
+
74
+ # Documentation string for this name
75
+ define_name :publisher, "O'Reilly"
76
+ end
77
+
78
+ This custom declaration provides dynamically generated code that is hard for a
79
+ documentation tool to properly document without help from the developer. To

80
+ ease the pains of manually documenting the procedure, YARD can be extended by

81
+ the developer to handled the `define_name` construct and add the required

82
+ method to the defined methods of the class with its documentation. This makes

83
+ documenting external API's, especially dynamic ones, a lot more consistent for
84
+ consumption by the users.

85
+
86
+ **4. Raw Data Output**: YARD also outputs documented objects as raw data (the

87
+ dumped Namespace) which can be reloaded to do generation at a later date, or

88
+ even auditing on code. This means that any developer can use the raw data to

89
+ perform output generation for any custom format, such as YAML, for instance.

90
+ While YARD plans to support XHTML style documentation output as well as

91
+ command line (text based) and possibly XML, this may still be useful for those
92
+ who would like to reap the benefits of YARD's processing in other forms, such

93
+ as throwing all the documentation into a database. Another useful way of

94
+ exploiting this raw data format would be to write tools that can auto generate
95
+ test cases, for example, or show possible unhandled exceptions in code.

96
+
97
+
98
+ USAGE
99
+ -----
100
+
101
+ There are a couple of ways to use YARD. The first is via command-line, and the
102
+ second is the Rake task. There are also the `yard-graph` and `yri` binaries to
103
+ look at, if you want to poke around.
104
+
105
+ **1. yardoc Command-line Tool**
106
+
107
+ The most obvious way to run YARD is to run the `yardoc` binary file that comes
108
+ with YARD. This will, among other things, generate the HTML documentation for
109
+ your project code. You can type `yardoc --help` to see the options
110
+ that YARD provides, but the easiest way to generate docs for your code is to
111
+ simply type `yardoc` in your project root. This will assume your files are
112
+ located in the `lib/` directory. If they are located elsewhere, you can specify
113
+ paths and globs from the commandline via:
114
+
115
+ $ yardoc 'lib/**/*.rb' 'app/**/*.rb' ...etc...
116
+
117
+ The tool will generate a `.yardoc` file which will store the cached database
118
+ of your source code and documentation. If you want to re-generate your docs
119
+ with another template you can simply use the `--use-cache` (or -c)
120
+ option to speed up the generation process by skipping source parsing.
121
+
122
+ YARD will by default only document code in your public visibility. You can
123
+ document your protected and private code by adding `--protected` or
124
+ `--private` to the option switches.
125
+
126
+ You can also add extra informative files with the `--files` switch,
127
+ for example:
128
+
129
+ $ yardoc --files FAQ,LICENSE
130
+
131
+ Note that the README file is specified with its own `--readme` switch.
132
+
133
+ You can also add a `.yardopts` file to your project directory which lists
134
+ the switches separated by whitespace (newlines or space) to pass to yardoc
135
+ whenever it is run.
136
+
137
+ **2. Rake Task**
138
+
139
+ The second most obvious is to generate docs via a Rake task. You can do this by
140
+ adding the following to your `Rakefile`:
141
+
142
+ YARD::Rake::YardocTask.new do |t|
143
+ t.files = ['lib/**/*.rb', OTHER_PATHS] # optional
144
+ t.options = ['--any', '--extra', '--opts'] # optional
145
+ end
146
+
147
+ both the `files` and `options` settings are optional. `files` will default to
148
+ `lib/**/*.rb` and `options` will represents any options you might want
149
+ to add. Again, a full list of options is available by typing `yardoc --help`
150
+ in a shell. You can also override the options at the Rake command-line with the
151
+ OPTS environment variable:
152
+
153
+ $ rake yardoc OPTS='--any --extra --opts'
154
+
155
+ **3. `yri` RI Implementation**
156
+
157
+ The yri binary will use the cached .yardoc database to give you quick ri-style
158
+ access to your documentation. It's way faster than ri but currently does not
159
+ work with the stdlib or core Ruby libraries, only the active project. Example:
160
+
161
+ $ yri YARD::Handlers::Base#register
162
+ $ yri File::relative_path
163
+
164
+ **4. `yard-graph` Graphviz Generator**
165
+
166
+ You can use `yard-graph` to generate dot graphs of your code. This, of course,
167
+ requires [Graphviz](http://www.graphviz.org) and the `dot` binary. By default
168
+ this will generate a graph of the classes and modules in the best UML2 notation
169
+ that Graphviz can support, but without any methods listed. With the `--full`
170
+ option, methods and attributes will be listed. There is also a `--dependencies`
171
+ option to show mixin inclusions. You can output to stdout or a file, or pipe directly
172
+ to `dot`. The same public, protected and private visibility rules apply to yard-graph.
173
+ More options can be seen by typing `yard-graph --help`, but here is an example:
174
+
175
+ $ yard-graph --protected --full --dependencies
176
+
177
+
178
+ CHANGELOG
179
+ ---------
180
+
181
+ - **Jun.07.09**: 0.2.3 release. See the {file:WHATSNEW.markdown} file for a
182
+ list of important new features.
183
+
184
+ - **Jun.16.08**: 0.2.2 release. This is the largest changset since yard's
185
+ conception and involves a complete overhaul of the parser and API to make it
186
+ more robust and far easier to extend and use for the developer.
187
+
188
+ - **Feb.20.08**: 0.2.1 release.
189
+
190
+ - **Feb.24.07**: Released 0.1a experimental version for testing. The goal here is
191
+ to get people testing YARD on their code because there are too many possible
192
+ code styles to fit into a sane amount of test cases. It also demonstrates the
193
+ power of YARD and what to expect from the syntax (Yardoc style meta tags).
194
+
195
+
196
+ COPYRIGHT
197
+ ---------
198
+
199
+ YARD &copy; 2007-2009 by [Loren Segal](mailto:lsegal@soen.ca). Licensed under the MIT
200
+ license. Please see the {file:LICENSE} for more information.
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ end
19
19
  desc "Install the gem locally"
20
20
  task :install => :package do
21
21
  sh "#{SUDO} gem install pkg/#{SPEC.name}-#{SPEC.version}.gem --local"
22
+ sh "rm -rf pkg/yard-#{SPEC.version}" unless ENV['KEEP_FILES']
22
23
  end
23
24
 
24
25
  desc "Run all specs"
@@ -26,6 +27,10 @@ Spec::Rake::SpecTask.new("specs") do |t|
26
27
  $DEBUG = true if ENV['DEBUG']
27
28
  t.spec_opts = ["--format", "specdoc", "--colour"]
28
29
  t.spec_files = Dir["spec/**/*_spec.rb"].sort
30
+ # t.rcov = true
31
+ t.rcov_opts = ['-x', '_spec\.rb$,spec_helper\.rb$']
29
32
  end
30
33
 
31
- YARD::Rake::YardocTask.new
34
+ YARD::Rake::YardocTask.new do |t|
35
+ t.after = lambda { `cp -R docs/images/ doc/images/` }
36
+ end
@@ -0,0 +1,46 @@
1
+ require "benchmark"
2
+ require 'lib/yard'
3
+
4
+ def format_args_regex(object)
5
+ if object.signature
6
+ object.signature[/#{Regexp.quote object.name.to_s}\s*(.*)/, 1]
7
+ else
8
+ ""
9
+ end
10
+ end
11
+
12
+ def format_args_parameters(object)
13
+ if !object.parameters.empty?
14
+ args = object.parameters.map {|n, v| v ? "#{n} = #{v}" : n.to_s }.join(", ")
15
+ "(#{args})"
16
+ else
17
+ ""
18
+ end
19
+ end
20
+
21
+ YARD::Registry.load
22
+ $object = YARD::Registry.at('YARD::Generators::Base#G')
23
+
24
+ puts "regex: " + format_args_regex($object)
25
+ puts "params: " + format_args_parameters($object)
26
+ puts
27
+
28
+ TIMES = 100_000
29
+ Benchmark.bmbm do |x|
30
+ x.report("regex") { TIMES.times { format_args_regex($object) } }
31
+ x.report("parameters") { TIMES.times { format_args_parameters($object) } }
32
+ end
33
+
34
+ =begin LAST RUN Jun 23 2008
35
+ regex: (generator, opts = {})
36
+ params: (generator, opts = {})
37
+
38
+ Rehearsal ----------------------------------------------
39
+ regex 1.270000 0.020000 1.290000 ( 1.294558)
40
+ parameters 0.690000 0.000000 0.690000 ( 0.693324)
41
+ ------------------------------------- total: 1.980000sec
42
+
43
+ user system total real
44
+ regex 1.260000 0.010000 1.270000 ( 1.268214)
45
+ parameters 0.670000 0.000000 0.670000 ( 0.679114)
46
+ =end
@@ -1,8 +1,20 @@
1
1
  require "benchmark"
2
2
  require 'lib/yard'
3
3
 
4
+ PATH_ORDER = [
5
+ 'lib/yard/autoload.rb',
6
+ 'lib/yard/code_objects/base.rb',
7
+ 'lib/yard/code_objects/namespace_object.rb',
8
+ 'lib/yard/handlers/base.rb',
9
+ 'lib/yard/generators/helpers/*.rb',
10
+ 'lib/yard/generators/base.rb',
11
+ 'lib/yard/generators/method_listing_generator.rb',
12
+ 'lib/yard/serializers/base.rb',
13
+ 'lib/**/*.rb'
14
+ ]
15
+
4
16
  Benchmark.bmbm do |x|
5
- x.report("parse in order") { YARD::Registry.clear; YARD.parse YARD::PATH_ORDER, Logger::ERROR }
17
+ x.report("parse in order") { YARD::Registry.clear; YARD.parse PATH_ORDER, Logger::ERROR }
6
18
  x.report("parse") { YARD::Registry.clear; YARD.parse 'lib/**/*.rb', Logger::ERROR }
7
19
  end
8
20
 
@@ -0,0 +1,10 @@
1
+ require "benchmark"
2
+
3
+ files = Dir.glob(File.dirname(__FILE__) + '/../lib/**/*.rb').join(" ")
4
+ Benchmark.bmbm do |x|
5
+ x.report("rdoc") { `rm -rf rdoc && rdoc -q -o rdoc #{files} && rm -rf rdoc` }
6
+ x.report("yardoc") { `rm -rf yard && ./bin/yardoc -q -o yard #{files} && rm -rf yard` }
7
+ x.report("yardoc-cached") { `rm -rf yard && ./bin/yardoc -c -q -o yard #{files} && rm -rf yard` }
8
+ x.report("yardoc-legacy") { `rm -rf yard && ./bin/yardoc --legacy -q -o yard #{files} && rm -rf yard` }
9
+ x.report("yardoc-legacy-cached") { `rm -rf yard && ./bin/yardoc --legacy -c -q -o yard #{files} && rm -rf yard` }
10
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require 'benchmark'
3
+ require File.dirname(__FILE__) + '/../lib/yard'
4
+
5
+ $files = Dir[File.dirname(__FILE__) + '/../lib/**/*.rb'].map {|f| File.read(f) }
6
+ $files_rip = Dir[File.dirname(__FILE__) + '/../lib/**/*.rb'].map {|f| [File.read(f), f] }
7
+
8
+ TIMES = 2
9
+ Benchmark.bmbm do |x|
10
+ x.report("rip-parser") { TIMES.times { $files_rip.each {|f| YARD::Parser::Ruby::RubyParser.parse(*f) } } }
11
+ x.report("yard-parser ") { TIMES.times { $files.each {|f| YARD::Parser::Ruby::Legacy::StatementList.new(f) } } }
12
+ end
@@ -0,0 +1,121 @@
1
+ CodeObjects Architecture
2
+ ========================
3
+
4
+ Code objects are Ruby objects that describe the code being documented. For instance,
5
+ all classes, modules, methods, etc. are all extracted from the Ruby source as code
6
+ objects. All of these code objects extend from the {YARD::CodeObjects::Base} class, which
7
+ provides basic attributes like source location, source code, name and path.
8
+
9
+ CodeObjects Organization
10
+ ------------------------
11
+
12
+ Code objects are divided into two basic types. {YARD::CodeObjects::NamespaceObject NamespaceObjects}
13
+ and non-namespace objects. A namespace object refers to any object in Ruby that can have
14
+ other objects defined inside of it. In the context of Ruby, this specifically means
15
+ modules and classes (both of which are subclasses of `NamespaceObject`). These objects
16
+ act like tree structures, maintaining a list of all of their direct children. All non
17
+ namespace objects are simply subclasses of the Base class. The {YARD::CodeObjects::RootObject RootObject}
18
+ is a special kind of `NamespaceObject` which refers to the top level namespace in Ruby.
19
+ Methods that accept a namespace object as a parameter should also accept the symbol
20
+ `:root` as a shortcut for the root object.
21
+
22
+ The following is an overview of the classes within the `CodeObjects` namespace:
23
+
24
+ ![CodeObjects Class Diagram](images/code-objects-class-diagram.png)
25
+
26
+ Unique Path Representation
27
+ --------------------------
28
+
29
+ All CodeObjects are uniquely defined by their implementation of {YARD::CodeObjects::Base#path}.
30
+ This path is used to locate or store a code object in the {YARD::Registry}. It is therefore
31
+ essential that any Base subclass return a unique String value for #path so that the
32
+ object may co-exist with other objects in the Registry.
33
+
34
+ In practice, a path is simply the conventional Ruby representation of a class,
35
+ module, constant, class variable or method. For example, the following objects
36
+ would have the following respective paths:
37
+
38
+ * Class `Klass` inside module `Mod`: `Mod::Klass`
39
+ * Instance method `bar` inside class `Foo`: `Foo#bar`
40
+ * Class method `bar` inside class `Foo`: `Foo.bar`
41
+ * Constant `VERSION` inside class `YARD`: `YARD::VERSION`
42
+ * Class variable `@@abc` inside class `A`: `A::@@abc`
43
+
44
+ Registry
45
+ --------
46
+
47
+ CodeObjects classes are coupled with the {YARD::Registry} class which keeps track of
48
+ all instantiated code objects. This is an explicit design choice to allow objects
49
+ to be fetched, cached, imported and exported from a centralized location. As mentioned
50
+ above, this coupling is a result of the fact that each object is uniquely identified by
51
+ its path, which is used to implement lookups. You can read more about the registry
52
+ in the {YARD::Registry} class.
53
+
54
+ Identity Map
55
+ ------------
56
+
57
+ Code objects are instantiated using an identity-map like implementation that guarantees
58
+ only one unique Ruby object exists for an object described by a specific path. This
59
+ allows developers to create a code object without checking if it already exists in
60
+ the {YARD::Registry}. The following example will only create one object:
61
+
62
+ id = ClassObject.new(:root, "MyClass").object_id #=> 13352
63
+ ClassObject.new(:root, "MyClass").object_id #=> 13352
64
+
65
+ Proxy Objects
66
+ -------------
67
+
68
+ In addition to providing access to existing objects, a {YARD::CodeObjects::Proxy}
69
+ class exists which can represent an object at a path that may or may not have been
70
+ created. This is necessary to represent a reference to an object in code that is
71
+ never defined in the same body of source code, or perhaps defined later. If any
72
+ attributes of a proxy are accessed, it will immediately be resolved to the object
73
+ at its declared path. In the case where such an object exists, it will act as
74
+ a delegate to the object. However, if the object does not exist, a warning will
75
+ be raised. Whenever arbitrary code objects are used, care should be taken in
76
+ order to make sure attributes are not accessed on unresolvable proxies. An
77
+ unresolvable proxy will return a class name of `Proxy` and #type of `:proxy`,
78
+ for example:
79
+
80
+ P(:InvalidObject).type == :proxy #=> true
81
+ P(:InvalidObject).is_a?(Proxy) #=> true
82
+
83
+ Adding Data to Code Objects
84
+ ---------------------------
85
+
86
+ Code objects act as hash-like structures that allow any arbitrary value to be set.
87
+ This allows easy extending of existing objects without creating custom subclasses.
88
+ For instance, to add a timestamp to a method object (when it was modified, maybe),
89
+ it is possible to simply do:
90
+
91
+ object = MethodObject.new(:root, "my_method")
92
+ object[:modified_at] = Time.now
93
+
94
+ This value can now be retrieved on this object both by the hash `[]` syntax as
95
+ well as like any other method:
96
+
97
+ object.modified_at #=> 2009-06-03 20:08:46 -0400
98
+
99
+ Creating a Custom CodeObject
100
+ ----------------------------
101
+
102
+ It should first be mentioned that creating a custom code object should not be
103
+ necessary in most cases, except when functionality that cannot be represented
104
+ by classical Ruby objects is added. A good example *might* be a test class,
105
+ which although is technically a Ruby class, has a significantly different purpose
106
+ in documentation and needs a different set of metadata, as well as its own
107
+ representation in documentation.
108
+
109
+ The {YARD::CodeObjects::Base#path} implementation is the most important part of the
110
+ code object architecture. The first thing any custom code object must guarantee is
111
+ that its path value is unique among all other objects. The recommended way to do this
112
+ with custom objects is to add a descriptive prefix to the path. For example, the
113
+ following is an implementation of the path for a hypothetical `FooObject`:
114
+
115
+ def path
116
+ "__FooPrefix" + sep + super
117
+ end
118
+
119
+ Note that if our FooObject is a `NamespaceObject`, meaning if it can have child
120
+ FooObjects defined inside of it, you may need to verify that the prefix is only
121
+ applied once.
data/docs/FAQ.markdown ADDED
@@ -0,0 +1,34 @@
1
+ FAQ
2
+ ===
3
+
4
+ (1) So, show me some cool stuff. What can YARD do?
5
+ --------------------------------------------------
6
+
7
+ - [Visualize with GraphViz][graphviz] Visualize your classes and methods with GraphViz
8
+ - [Inline RSpecs][inline-rspecs] In your rspec files, call the following to refer
9
+ back to and call the inline rspecs: `described_in_docs "String", "camelcase"`
10
+ - [Inline doc testing][inline-doctest] Use the 'docspec' command line tool to
11
+ run the above tests. This is similar to [Ruby DocTest][rubydoctest]'s inline
12
+ irb testing.
13
+
14
+ (2) Why did you pick the @-symbol tags for documentation?
15
+ ---------------------------------------------------------
16
+ Java, C++, Python and many other languages have standard documentation tools
17
+ that use the @tag "standard". This has been extended to the Ruby language,
18
+ and YARD takes advantage of this common style.
19
+
20
+ (3) Can I tweak it to use some other documentation standard?
21
+ ------------------------------------------------------------
22
+ Yes. YARD is flexible enough to have other documentation syntaxes put into use. [TODO: Add information about customization here.]
23
+
24
+ (4) Why don't you use ParseTree, or sydparse? Why did you write your own parser?
25
+ ---------------------------------------------------------------------------------
26
+ As of Ruby 1.9, YARD uses Ripper parser which is packaged with the standard library
27
+ and maintained as such. The legacy parser is only being maintained for bug fixes,
28
+ but was written because no existing parser properly supported putting comments
29
+ into the parse tree and did not robustly support edge case scenarios.
30
+
31
+ [graphviz]:http://gnuu.org/2008/02/29/generating-class-diagrams-with-yard-and-graphviz/
32
+ [inline-rspecs]:http://github.com/lsegal/yard/tree/5b07d706eee6bc0d7f13d9ec1e6e0ab914d3679c/lib/yard/core_ext/string.rb
33
+ [inline-doctest]:http://github.com/lsegal/yard/tree/master/lib/yard/handlers/base.rb#L350
34
+ [rubydoctest]:http://github.com/tablatom/rubydoctest