yard 0.2.1 → 0.2.2

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 (264) hide show
  1. data/{LICENSE.txt → LICENSE} +1 -1
  2. data/README +211 -0
  3. data/Rakefile +31 -0
  4. data/benchmarks/builtins_vs_eval.rb +23 -0
  5. data/benchmarks/erb_vs_erubis.rb +53 -0
  6. data/benchmarks/generation.rb +37 -0
  7. data/benchmarks/parsing.rb +33 -0
  8. data/bin/view_generator +17 -0
  9. data/bin/yard-graph +4 -0
  10. data/bin/yardoc +1 -93
  11. data/bin/yri +12 -3
  12. data/lib/yard.rb +10 -5
  13. data/lib/yard/autoload.rb +116 -0
  14. data/lib/yard/cli/yard_graph.rb +86 -0
  15. data/lib/yard/cli/yardoc.rb +131 -0
  16. data/lib/yard/code_objects/base.rb +321 -0
  17. data/lib/yard/code_objects/class_object.rb +89 -0
  18. data/lib/yard/code_objects/class_variable_object.rb +4 -0
  19. data/lib/yard/code_objects/constant_object.rb +4 -0
  20. data/lib/yard/code_objects/method_object.rb +51 -0
  21. data/lib/yard/code_objects/module_object.rb +4 -0
  22. data/lib/yard/code_objects/namespace_object.rb +88 -0
  23. data/lib/yard/code_objects/proxy.rb +183 -0
  24. data/lib/yard/code_objects/root_object.rb +8 -0
  25. data/lib/yard/core_ext/file.rb +26 -0
  26. data/lib/yard/core_ext/logger.rb +5 -0
  27. data/lib/yard/core_ext/module.rb +9 -0
  28. data/lib/yard/core_ext/string.rb +13 -0
  29. data/lib/yard/core_ext/symbol_hash.rb +24 -0
  30. data/lib/yard/generators/attributes_generator.rb +22 -0
  31. data/lib/yard/generators/base.rb +285 -0
  32. data/lib/yard/generators/class_generator.rb +25 -0
  33. data/lib/yard/generators/constants_generator.rb +73 -0
  34. data/lib/yard/generators/constructor_generator.rb +25 -0
  35. data/lib/yard/generators/deprecated_generator.rb +15 -0
  36. data/lib/yard/generators/docstring_generator.rb +15 -0
  37. data/lib/yard/generators/full_doc_generator.rb +59 -0
  38. data/lib/yard/generators/helpers/base_helper.rb +52 -0
  39. data/lib/yard/generators/helpers/filter_helper.rb +21 -0
  40. data/lib/yard/generators/helpers/html_helper.rb +137 -0
  41. data/lib/yard/generators/helpers/method_helper.rb +27 -0
  42. data/lib/yard/generators/helpers/uml_helper.rb +16 -0
  43. data/lib/yard/generators/inheritance_generator.rb +16 -0
  44. data/lib/yard/generators/method_details_generator.rb +18 -0
  45. data/lib/yard/generators/method_generator.rb +31 -0
  46. data/lib/yard/generators/method_listing_generator.rb +105 -0
  47. data/lib/yard/generators/method_missing_generator.rb +25 -0
  48. data/lib/yard/generators/method_signature_generator.rb +19 -0
  49. data/lib/yard/generators/method_summary_generator.rb +21 -0
  50. data/lib/yard/generators/mixins_generator.rb +15 -0
  51. data/lib/yard/generators/module_generator.rb +22 -0
  52. data/lib/yard/generators/quick_doc_generator.rb +31 -0
  53. data/lib/yard/generators/source_generator.rb +26 -0
  54. data/lib/yard/generators/tags_generator.rb +50 -0
  55. data/lib/yard/generators/uml_generator.rb +92 -0
  56. data/lib/yard/generators/visibility_group_generator.rb +26 -0
  57. data/lib/yard/handlers/alias_handler.rb +32 -0
  58. data/lib/yard/handlers/attribute_handler.rb +54 -0
  59. data/lib/yard/handlers/base.rb +509 -0
  60. data/lib/yard/handlers/class_handler.rb +44 -0
  61. data/lib/yard/handlers/class_variable_handler.rb +13 -0
  62. data/lib/yard/handlers/constant_handler.rb +13 -0
  63. data/lib/yard/handlers/exception_handler.rb +12 -0
  64. data/lib/yard/handlers/method_handler.rb +27 -0
  65. data/lib/yard/handlers/mixin_handler.rb +16 -0
  66. data/lib/yard/handlers/module_handler.rb +9 -0
  67. data/lib/yard/handlers/visibility_handler.rb +14 -0
  68. data/lib/yard/handlers/yield_handler.rb +26 -0
  69. data/lib/yard/logging.rb +27 -0
  70. data/lib/yard/parser/ruby_lex.rb +1344 -0
  71. data/lib/yard/parser/source_parser.rb +109 -0
  72. data/lib/yard/parser/statement.rb +36 -0
  73. data/lib/yard/parser/statement_list.rb +167 -0
  74. data/lib/yard/parser/token_list.rb +58 -0
  75. data/lib/yard/rake/yardoc_task.rb +30 -0
  76. data/lib/yard/registry.rb +136 -0
  77. data/lib/yard/serializers/base.rb +16 -0
  78. data/lib/yard/serializers/file_system_serializer.rb +48 -0
  79. data/lib/yard/serializers/process_serializer.rb +14 -0
  80. data/lib/yard/serializers/stdout_serializer.rb +21 -0
  81. data/lib/yard/tags/default_factory.rb +98 -0
  82. data/lib/yard/tags/library.rb +109 -0
  83. data/lib/yard/tags/merbdoc_factory.rb +47 -0
  84. data/lib/yard/tags/tag.rb +35 -0
  85. data/spec/code_objects/base_spec.rb +219 -0
  86. data/spec/code_objects/class_object_spec.rb +176 -0
  87. data/spec/code_objects/code_object_list_spec.rb +33 -0
  88. data/spec/code_objects/constants_spec.rb +79 -0
  89. data/spec/code_objects/method_object_spec.rb +30 -0
  90. data/spec/code_objects/module_object_spec.rb +73 -0
  91. data/spec/code_objects/namespace_object_spec.rb +129 -0
  92. data/spec/code_objects/proxy_spec.rb +80 -0
  93. data/spec/code_objects/spec_helper.rb +3 -0
  94. data/spec/core_ext/file_spec.rb +20 -0
  95. data/spec/core_ext/string_spec.rb +4 -0
  96. data/spec/core_ext/symbol_hash_spec.rb +80 -0
  97. data/spec/generators/base_spec.rb +64 -0
  98. data/spec/generators/helpers/base_helper_spec.rb +15 -0
  99. data/spec/generators/helpers/html_helper_spec.rb +56 -0
  100. data/spec/generators/quick_doc_generator_spec.rb +13 -0
  101. data/spec/handlers/alias_handler_spec.rb +50 -0
  102. data/spec/handlers/attribute_handler_spec.rb +78 -0
  103. data/spec/handlers/base_spec.rb +165 -0
  104. data/spec/handlers/class_handler_spec.rb +68 -0
  105. data/spec/handlers/class_variable_handler_spec.rb +9 -0
  106. data/spec/handlers/constant_handler_spec.rb +13 -0
  107. data/spec/handlers/examples/alias_handler_001.rb.txt +24 -0
  108. data/spec/handlers/examples/attribute_handler_001.rb.txt +19 -0
  109. data/spec/handlers/examples/class_handler_001.rb.txt +39 -0
  110. data/spec/handlers/examples/class_variable_handler_001.rb.txt +9 -0
  111. data/spec/handlers/examples/constant_handler_001.rb.txt +10 -0
  112. data/spec/handlers/examples/exception_handler_001.rb.txt +42 -0
  113. data/spec/handlers/examples/method_handler_001.rb.txt +35 -0
  114. data/spec/handlers/examples/mixin_handler_001.rb.txt +12 -0
  115. data/spec/handlers/examples/module_handler_001.rb.txt +16 -0
  116. data/spec/handlers/examples/visibility_handler_001.rb.txt +20 -0
  117. data/spec/handlers/examples/yield_handler_001.rb.txt +55 -0
  118. data/spec/handlers/exception_handler_spec.rb +35 -0
  119. data/spec/handlers/method_handler_spec.rb +35 -0
  120. data/spec/handlers/mixin_handler_spec.rb +30 -0
  121. data/spec/handlers/module_handler_spec.rb +25 -0
  122. data/spec/handlers/spec_helper.rb +21 -0
  123. data/spec/handlers/visibility_handler_spec.rb +24 -0
  124. data/spec/handlers/yield_handler_spec.rb +51 -0
  125. data/spec/parser/examples/example1.rb.txt +8 -0
  126. data/spec/parser/examples/tag_handler_001.rb.txt +8 -0
  127. data/spec/parser/source_parser_spec.rb +43 -0
  128. data/spec/parser/tag_parsing_spec.rb +18 -0
  129. data/spec/parser/token_list_spec.rb +35 -0
  130. data/spec/registry_spec.rb +70 -0
  131. data/spec/serializers/file_system_serializer_spec.rb +91 -0
  132. data/spec/serializers/spec_helper.rb +2 -0
  133. data/spec/spec_helper.rb +77 -0
  134. data/templates/default/attributes/html/header.erb +35 -0
  135. data/templates/default/attributes/text/header.erb +10 -0
  136. data/templates/default/class/html/header.erb +4 -0
  137. data/templates/default/constants/html/constants.erb +9 -0
  138. data/templates/default/constants/html/header.erb +3 -0
  139. data/templates/default/constants/html/included.erb +9 -0
  140. data/templates/default/constants/html/inherited.erb +9 -0
  141. data/templates/default/constructor/html/header.erb +10 -0
  142. data/templates/default/deprecated/html/main.erb +4 -0
  143. data/templates/default/deprecated/text/main.erb +3 -0
  144. data/templates/default/docstring/html/main.erb +3 -0
  145. data/templates/default/docstring/text/main.erb +3 -0
  146. data/templates/default/fulldoc/html/all_methods.erb +25 -0
  147. data/templates/default/fulldoc/html/all_namespaces.erb +19 -0
  148. data/templates/default/fulldoc/html/app.js +18 -0
  149. data/templates/default/fulldoc/html/header.erb +15 -0
  150. data/templates/default/fulldoc/html/html_head.erb +3 -0
  151. data/templates/default/fulldoc/html/index.erb +18 -0
  152. data/templates/default/fulldoc/html/jquery.js +11 -0
  153. data/templates/default/fulldoc/html/readme.erb +15 -0
  154. data/templates/default/fulldoc/html/style.css +65 -0
  155. data/templates/default/fulldoc/html/syntax_highlight.css +21 -0
  156. data/templates/default/inheritance/html/header.erb +8 -0
  157. data/templates/default/inheritance/text/header.erb +3 -0
  158. data/templates/default/method/html/aliases.erb +6 -0
  159. data/templates/default/method/html/header.erb +3 -0
  160. data/templates/default/method/html/title.erb +3 -0
  161. data/templates/default/methoddetails/html/header.erb +8 -0
  162. data/templates/default/methoddetails/html/method_header.erb +3 -0
  163. data/templates/default/methodmissing/html/header.erb +12 -0
  164. data/templates/default/methodsignature/html/main.erb +8 -0
  165. data/templates/default/methodsignature/text/main.erb +5 -0
  166. data/templates/default/methodsummary/html/header.erb +5 -0
  167. data/templates/default/methodsummary/html/included.erb +9 -0
  168. data/templates/default/methodsummary/html/inherited.erb +9 -0
  169. data/templates/default/methodsummary/html/summary.erb +25 -0
  170. data/templates/default/methodsummary/text/header.erb +5 -0
  171. data/templates/default/methodsummary/text/included.erb +0 -0
  172. data/templates/default/methodsummary/text/inherited.erb +0 -0
  173. data/templates/default/methodsummary/text/summary.erb +3 -0
  174. data/templates/default/mixins/html/header.erb +4 -0
  175. data/templates/default/module/html/header.erb +4 -0
  176. data/templates/default/quickdoc/html/header.erb +15 -0
  177. data/templates/default/quickdoc/text/header.erb +12 -0
  178. data/templates/default/source/html/main.erb +15 -0
  179. data/templates/default/source/text/main.erb +4 -0
  180. data/templates/default/tags/html/header.erb +4 -0
  181. data/templates/default/tags/html/see.erb +13 -0
  182. data/templates/default/tags/html/tags.erb +20 -0
  183. data/templates/default/tags/text/header.erb +3 -0
  184. data/templates/default/tags/text/see.erb +5 -0
  185. data/templates/default/tags/text/tags.erb +7 -0
  186. data/templates/default/uml/dot/child.erb +1 -0
  187. data/templates/default/uml/dot/dependencies.erb +10 -0
  188. data/templates/default/uml/dot/header.erb +6 -0
  189. data/templates/default/uml/dot/info.erb +14 -0
  190. data/templates/default/uml/dot/subgraph.erb +6 -0
  191. data/templates/default/uml/dot/superclasses.erb +9 -0
  192. data/templates/default/uml/dot/unknown.erb +3 -0
  193. data/templates/default/uml/dot/unknown_child.erb +1 -0
  194. data/templates/default/visibilitygroup/html/header.erb +6 -0
  195. data/templates/javadoc/attributes/html/header.erb +16 -0
  196. data/templates/javadoc/class/html/header.erb +4 -0
  197. data/templates/javadoc/constants/html/constants.erb +9 -0
  198. data/templates/javadoc/constants/html/header.erb +3 -0
  199. data/templates/javadoc/constants/html/included.erb +12 -0
  200. data/templates/javadoc/constants/html/inherited.erb +12 -0
  201. data/templates/javadoc/constructor/html/header.erb +10 -0
  202. data/templates/javadoc/deprecated/html/main.erb +0 -0
  203. data/templates/javadoc/docstring/html/main.erb +6 -0
  204. data/templates/javadoc/fulldoc/html/all_methods.erb +25 -0
  205. data/templates/javadoc/fulldoc/html/all_namespaces.erb +19 -0
  206. data/templates/javadoc/fulldoc/html/app.js +18 -0
  207. data/templates/javadoc/fulldoc/html/header.erb +15 -0
  208. data/templates/javadoc/fulldoc/html/html_head.erb +3 -0
  209. data/templates/javadoc/fulldoc/html/index.erb +18 -0
  210. data/templates/javadoc/fulldoc/html/jquery.js +11 -0
  211. data/templates/javadoc/fulldoc/html/readme.erb +15 -0
  212. data/templates/javadoc/fulldoc/html/style.css +22 -0
  213. data/templates/javadoc/fulldoc/html/syntax_highlight.css +21 -0
  214. data/templates/javadoc/inheritance/html/header.erb +6 -0
  215. data/templates/javadoc/method/html/aliases.erb +6 -0
  216. data/templates/javadoc/method/html/header.erb +4 -0
  217. data/templates/javadoc/method/html/title.erb +4 -0
  218. data/templates/javadoc/methoddetails/html/header.erb +8 -0
  219. data/templates/javadoc/methoddetails/html/method_header.erb +0 -0
  220. data/templates/javadoc/methodmissing/html/header.erb +12 -0
  221. data/templates/javadoc/methodsignature/html/main.erb +8 -0
  222. data/templates/javadoc/methodsummary/html/header.erb +5 -0
  223. data/templates/javadoc/methodsummary/html/included.erb +12 -0
  224. data/templates/javadoc/methodsummary/html/inherited.erb +12 -0
  225. data/templates/javadoc/methodsummary/html/summary.erb +25 -0
  226. data/templates/javadoc/mixins/html/header.erb +5 -0
  227. data/templates/javadoc/module/html/header.erb +4 -0
  228. data/templates/javadoc/source/html/main.erb +15 -0
  229. data/templates/javadoc/tags/html/header.erb +5 -0
  230. data/templates/javadoc/tags/html/see.erb +8 -0
  231. data/templates/javadoc/tags/html/tags.erb +19 -0
  232. data/templates/javadoc/visibilitygroup/html/header.erb +5 -0
  233. metadata +352 -50
  234. data/README.pdf +0 -0
  235. data/lib/code_object.rb +0 -337
  236. data/lib/extra.rb +0 -8
  237. data/lib/formatter.rb +0 -90
  238. data/lib/handlers/all_handlers.rb +0 -2
  239. data/lib/handlers/attribute_handler.rb +0 -51
  240. data/lib/handlers/class_handler.rb +0 -30
  241. data/lib/handlers/class_variable_handler.rb +0 -9
  242. data/lib/handlers/code_object_handler.rb +0 -104
  243. data/lib/handlers/constant_handler.rb +0 -11
  244. data/lib/handlers/exception_handler.rb +0 -20
  245. data/lib/handlers/method_handler.rb +0 -28
  246. data/lib/handlers/mixin_handler.rb +0 -15
  247. data/lib/handlers/module_handler.rb +0 -9
  248. data/lib/handlers/visibility_handler.rb +0 -7
  249. data/lib/handlers/yield_handler.rb +0 -33
  250. data/lib/logger.rb +0 -19
  251. data/lib/namespace.rb +0 -98
  252. data/lib/quick_doc.rb +0 -104
  253. data/lib/ruby_lex.rb +0 -1321
  254. data/lib/source_parser.rb +0 -253
  255. data/lib/tag_library.rb +0 -175
  256. data/lib/tag_type.rb +0 -155
  257. data/templates/default/html/_fulldoc.erb +0 -64
  258. data/templates/default/html/class.erb +0 -226
  259. data/templates/default/html/method.erb +0 -20
  260. data/templates/default/html/module.erb +0 -126
  261. data/test/fixtures/docstring.txt +0 -23
  262. data/test/fixtures/docstring2.txt +0 -4
  263. data/test/test_code_object.rb +0 -66
  264. data/test/test_namespace.rb +0 -10
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007 Loren Segal
1
+ Copyright (c) 2007-2008 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 ADDED
@@ -0,0 +1,211 @@
1
+ = YARD Release 0.2.2 (June 16th 2008)
2
+ Copyright 2007-2008 Loren Segal
3
+
4
+ == SYNOPSIS
5
+
6
+ YARD is a documentation generation tool for the Ruby programming language
7
+ (http://www.ruby-lang.org). It enables the user to generate consistent, usable
8
+ documentation that can be exported to a number of formats very easily, and
9
+ also supports extending for custom Ruby constructs such as custom class level
10
+ definitions. Below is a summary of some of YARD's notable features.
11
+
12
+
13
+ == FEATURE LIST
14
+
15
+ 1. <b>RDoc/SimpleMarkup Formatting Compatibility</b>: YARD is made to be compatible
16
+ with RDoc formatting. In fact, YARD does no processing on RDoc documentation
17
+ strings, and leaves this up to the output generation tool to decide how to
18
+ render the documentation.
19
+
20
+ 2. <b>Yardoc Meta-tag Formatting Like Python, Java, Objective-C and other
21
+ languages</b>: YARD uses a '@tag' style definition syntax for meta tags alongside
22
+ regular code documentation. These tags should be able to happily sit side by
23
+ side RDoc formatted documentation, but provide a much more consistent and
24
+ usable way to describe important information about objects, such as what
25
+ parameters they take and what types they are expected to be, what type a
26
+ method should return, what exceptions it can raise, if it is deprecated, etc..
27
+ It also allows information to be better (and more consistently) organized
28
+ during the output generation phase. Some of the main tags are listed below:
29
+
30
+ <b>Table 1. Meta-tags and their descriptions</b>
31
+
32
+ <tt>@param [Types] name description</tt>::
33
+ Description Allows for the definition of a method parameter with
34
+ optional type information.
35
+
36
+ <tt>@yieldparam [Types] name description</tt>::
37
+ Description Allows for the definition of a method parameter to a
38
+ yield block with optional type information.
39
+
40
+ <tt>@yield description</tt>::
41
+ Allows the developer to document the purpose of a yield block in
42
+ a method.
43
+
44
+ @return [Types] description</tt>::
45
+ Describes what the method returns with optional type information.
46
+
47
+ <tt>@deprecated description</tt>::
48
+ Informs the developer that a method is deprecated and should no
49
+ longer be used. The description offers the developer an alternative
50
+ solution or method for the problem.
51
+
52
+ <tt>@raise class description</tt>::
53
+ Tells the developer that the method may raise an exception and of
54
+ what type.
55
+
56
+ <tt>@see name</tt>::
57
+ References another object, URL, or other for extra information.
58
+
59
+ <tt>@since number</tt>::
60
+ Lists the version number in which the object first appeared.
61
+
62
+ <tt>@version number</tt>::
63
+ Lists the current version of the documentation for the object.
64
+
65
+ <tt>@author name</tt>::
66
+ The authors responsible for the module
67
+
68
+ You might have noticed the optional "types" declarations for certain tags.
69
+ This allows the developer to document type signatures for ruby methods and
70
+ parameters in a non intrusive but helpful and consistent manner. Instead of
71
+ describing this data in the body of the description, a developer may formally
72
+ declare the parameter or return type(s) in a single line. Consider the
73
+ following Yardoc'd method:
74
+
75
+ ##
76
+ # Reverses the contents of a String or IO object.
77
+ #
78
+ # @param [String, #read] contents the contents to reverse
79
+ # @return [String] the contents reversed lexically
80
+ def reverse(contents)
81
+ contents = contents.read if respond_to? :read
82
+ contents.reverse
83
+ end
84
+
85
+ With the above @param tag, we learn that the contents parameter can either be
86
+ a String or any object that responds to the 'read' method, which is more
87
+ powerful than the textual description, which says it should be an IO object.
88
+ This also informs the developer that they should expect to receive a String
89
+ object returned by the method, and although this may be obvious for a
90
+ 'reverse' method, it becomes very useful when the method name may not be as
91
+ descriptive.
92
+
93
+ 3. <b>Custom Constructs and Extensibility of YARD</b>: Take for instance the example:
94
+
95
+ class A
96
+ class << self
97
+ def define_name(name, value)
98
+ class_eval "def #{name}; #{value.inspect} end"
99
+ end
100
+ end
101
+
102
+ # Documentation string for this name
103
+ define_name :publisher, "O'Reilly"
104
+ end
105
+
106
+ This custom declaration provides dynamically generated code that is hard for a
107
+ documentation tool to properly document without help from the developer. To
108
+ ease the pains of manually documenting the procedure, YARD can be extended by
109
+ the developer to handled the 'define_name' construct and add the required
110
+ method to the defined methods of the class with its documentation. This makes
111
+ documenting external API's, especially dynamic ones, a lot more consistent for
112
+ consumption by the users.
113
+
114
+ 4. <b>Raw Data Output</b>: YARD also outputs documented objects as raw data (the
115
+ dumped Namespace) which can be reloaded to do generation at a later date, or
116
+ even auditing on code. This means that any developer can use the raw data to
117
+ perform output generation for any custom format, such as YAML, for instance.
118
+ While YARD plans to support XHTML style documentation output as well as
119
+ command line (text based) and possibly XML, this may still be useful for those
120
+ who would like to reap the benefits of YARD's processing in other forms, such
121
+ as throwing all the documentation into a database. Another useful way of
122
+ exploiting this raw data format would be to write tools that can auto generate
123
+ test cases, for example, or show possible unhandled exceptions in code.
124
+
125
+
126
+ == USAGE
127
+
128
+ There are a couple of ways to use YARD. The first is via command-line, and the
129
+ second is the Rake task. There are also the +yard-graph+ and +yri+ binaries to
130
+ look at, if you want to poke around.
131
+
132
+ === 1. yardoc Command-line Tool
133
+
134
+ The most obvious way to run YARD is to run the +yardoc+ binary file that comes
135
+ with YARD. This will, among other things, generate the HTML documentation for
136
+ your project code. You can type <tt>yardoc --help</tt> to see the options
137
+ that YARD provides, but the easiest way to generate docs for your code is to
138
+ simply type +yardoc+ in your project root. This will assume your files are
139
+ located in the +lib/+ directory. If they are located elsewhere, you can specify
140
+ paths and globs from the commandline via:
141
+
142
+ yardoc 'lib/**/*.rb' 'app/**/*.rb' ...etc...
143
+
144
+ The tool will generate a +.yardoc+ file which will store the cached database
145
+ of your source code and documentation. If you want to re-generate your docs
146
+ with another template you can simply use the <tt>--use-cache</tt> (or -c)
147
+ option to speed up the generation process by skipping source parsing.
148
+
149
+ YARD will by default only document code in your public visibility. You can
150
+ document your protected and private code by adding <tt>--protected</tt> or
151
+ <tt>--private</tt> to the option switches.
152
+
153
+ === 2. Rake Task
154
+
155
+ The second most obvious is to generate docs via a Rake task. You can do this by
156
+ adding the following to your +Rakefile+:
157
+
158
+ YARD::Rake::YardocTask.new do |t|
159
+ t.files = ['lib/**/*.rb', OTHER_PATHS] # optional
160
+ t.options = ['--any', '--extra', '--opts'] # optional
161
+ end
162
+
163
+ both the +files+ and +options+ settings are optional. +files+ will default to
164
+ <tt>lib/**/*.rb</tt> and +options+ will represents any options you might want
165
+ to add. Again, a full list of options is available by typing <tt>yardoc --help</tt>
166
+ in a shell. You can also override the options at the Rake command-line with the
167
+ OPTS environment variable:
168
+
169
+ > rake yardoc OPTS='--any --extra --opts'
170
+
171
+ === 3. yri RI Implementation
172
+
173
+ The yri binary will use the cached .yardoc database to give you quick ri-style
174
+ access to your documentation. It's way faster than ri but currently does not
175
+ work with the stdlib or core Ruby libraries, only the active project. Example:
176
+
177
+ > yri YARD::Handlers::Base#register
178
+ > yri File::relative_path
179
+
180
+ === 4. yard-graph Graphviz Generator
181
+
182
+ You can use +yard-graph+ to generate dot graphs of your code. This, of course,
183
+ requires Graphviz (http://www.graphviz.org) and the +dot+ binary. By default
184
+ this will generate a graph of the classes and modules in the best UML2 notation
185
+ that Graphviz can support, but without any methods listed. With the <tt>--full</tt>
186
+ option, methods and attributes will be listed. There is also a <tt>--dependencies</tt>
187
+ option to show mixin inclusions. You can output to stdout or a file, or pipe directly
188
+ to +dot+. The same public, protected and private visibility rules apply to yard-graph.
189
+ More options can be seen by typing <tt>yard-graph --help</tt>, but here is an example:
190
+
191
+ > yard-graph --protected --full --dependencies
192
+
193
+
194
+ == CHANGELOG
195
+
196
+ - <b>Jun.16.08</b>: 0.2.2 release. This is the largest changset since yard's
197
+ conception and involves a complete overhaul of the parser and API to make it
198
+ more robust and far easier to extend and use for the developer.
199
+
200
+ - <b>Feb.20.08</b>: 0.2.1 release.
201
+
202
+ - <b>Feb.24.07</b>: Released 0.1a experimental version for testing. The goal here is
203
+ to get people testing YARD on their code because there are too many possible
204
+ code styles to fit into a sane amount of test cases. It also demonstrates the
205
+ power of YARD and what to expect from the syntax (Yardoc style meta tags).
206
+
207
+
208
+ == COPYRIGHT
209
+
210
+ YARD was created in 2007-2008 by Loren Segal (lsegal -AT- soen -DOT- ca) and is
211
+ licensed under the MIT license. Please see the LICENSE.txt for more information.
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/lib/yard'
2
+ require 'rubygems'
3
+ require 'rake/gempackagetask'
4
+ require 'spec'
5
+ require 'spec/rake/spectask'
6
+
7
+ WINDOWS = (PLATFORM =~ /win32|cygwin/ ? true : false) rescue false
8
+ SUDO = WINDOWS ? '' : 'sudo'
9
+
10
+ task :default => :specs
11
+
12
+ load 'yard.gemspec'
13
+ Rake::GemPackageTask.new(SPEC) do |pkg|
14
+ pkg.gem_spec = SPEC
15
+ pkg.need_zip = true
16
+ pkg.need_tar = true
17
+ end
18
+
19
+ desc "Install the gem locally"
20
+ task :install => :package do
21
+ sh "#{SUDO} gem install pkg/#{SPEC.name}-#{SPEC.version}.gem --local"
22
+ end
23
+
24
+ desc "Run all specs"
25
+ Spec::Rake::SpecTask.new("specs") do |t|
26
+ $DEBUG = true if ENV['DEBUG']
27
+ t.spec_opts = ["--format", "specdoc", "--colour"]
28
+ t.spec_files = Dir["spec/**/*_spec.rb"].sort
29
+ end
30
+
31
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,23 @@
1
+ require 'benchmark'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
3
+
4
+ TIMES = (ARGV[0] || 10_000).to_i
5
+
6
+ def bench_builtins(name)
7
+ YARD::CodeObjects::BUILTIN_EXCEPTIONS_HASH.has_key? name
8
+ end
9
+
10
+ def bench_eval(name)
11
+ eval(name).is_a?(Class)
12
+ rescue
13
+ false
14
+ end
15
+
16
+ Benchmark.bmbm do |b|
17
+ b.report("builtins PASS") { TIMES.times {YARD::CodeObjects::BUILTIN_EXCEPTIONS.each {|y| bench_builtins(y) } } }
18
+ b.report("eval PASS") { TIMES.times {YARD::CodeObjects::BUILTIN_EXCEPTIONS.each {|y| bench_eval(y) }} }
19
+ b.report("builtins FAIL") { TIMES.times {YARD::CodeObjects::BUILTIN_MODULES.each {|y| bench_builtins(y) } } }
20
+ b.report("eval FAIL") { TIMES.times {YARD::CodeObjects::BUILTIN_MODULES.each {|y| bench_eval(y) }} }
21
+ b.report("builtins ANY") { TIMES.times {YARD::CodeObjects::BUILTIN_CLASSES.each {|y| bench_builtins(y) } } }
22
+ b.report("eval ANY") { TIMES.times {YARD::CodeObjects::BUILTIN_CLASSES.each {|y| bench_eval(y) }} }
23
+ end
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'erubis'
3
+ require 'erubis/tiny'
4
+ require 'erb'
5
+ require "benchmark"
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
7
+
8
+ def rungen
9
+ YARD::Registry.clear
10
+ YARD::CLI::Yardoc.run('--quiet', '--use-cache')
11
+ end
12
+
13
+ Benchmark.bmbm do |x|
14
+ x.report("erubis") do
15
+ eval <<-eof
16
+ class YARD::Generators::Base
17
+ def erb(str) Erubis::Eruby.new(str) end
18
+ end
19
+ eof
20
+
21
+ rungen
22
+ end
23
+
24
+ x.report("fast-erubis") do
25
+ eval <<-eof
26
+ class YARD::Generators::Base
27
+ def erb(str) Erubis::FastEruby.new(str) end
28
+ end
29
+ eof
30
+
31
+ rungen
32
+ end
33
+
34
+ x.report("tiny-erubis") do
35
+ eval <<-eof
36
+ class YARD::Generators::Base
37
+ def erb(str) Erubis::TinyEruby.new(str) end
38
+ end
39
+ eof
40
+
41
+ rungen
42
+ end
43
+
44
+ x.report("erb") do
45
+ eval <<-eof
46
+ class YARD::Generators::Base
47
+ def erb(str) ERB.new(str, nil, '<>') end
48
+ end
49
+ eof
50
+
51
+ rungen
52
+ end
53
+ end
@@ -0,0 +1,37 @@
1
+ require "benchmark"
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')
3
+
4
+ unless YARD::CodeObjects::Proxy.private_instance_methods.include?('to_obj')
5
+ raise "This benchmark is dependent on YARD::CodeObjects::Proxy#to_obj"
6
+ end
7
+
8
+ def rungen
9
+ YARD::Registry.clear
10
+ YARD::CLI::Yardoc.run('--quiet', '--use-cache')
11
+ end
12
+
13
+ def redef(lock = false)
14
+ eval <<-eof
15
+ class YARD::CodeObjects::Proxy;
16
+ def to_obj
17
+ @obj #{lock ? '||' : ''}= YARD::Registry.resolve(@namespace, @name)
18
+ end
19
+ end
20
+ eof
21
+ end
22
+
23
+ Benchmark.bmbm do |x|
24
+ x.report("gen-w/o-locking") { redef; rungen }
25
+ x.report("gen-with-locking") { redef(true); rungen }
26
+ end
27
+
28
+ =begin Results from 2008-06-07
29
+ Rehearsal ----------------------------------------------------
30
+ gen-w/o-locking 9.650000 0.450000 10.100000 ( 10.150556)
31
+ gen-with-locking 7.790000 0.400000 8.190000 ( 8.373811)
32
+ ------------------------------------------ total: 18.290000sec
33
+
34
+ user system total real
35
+ gen-w/o-locking 9.820000 0.430000 10.250000 ( 10.293283)
36
+ gen-with-locking 7.820000 0.380000 8.200000 ( 8.243326)
37
+ =end
@@ -0,0 +1,33 @@
1
+ require "benchmark"
2
+ require 'lib/yard'
3
+
4
+ Benchmark.bmbm do |x|
5
+ x.report("parse in order") { YARD::Registry.clear; YARD.parse YARD::PATH_ORDER, Logger::ERROR }
6
+ x.report("parse") { YARD::Registry.clear; YARD.parse 'lib/**/*.rb', Logger::ERROR }
7
+ end
8
+
9
+ =begin
10
+ load_order branch (2008-06-07):
11
+
12
+ Rehearsal --------------------------------------------------
13
+ parse in order 6.510000 0.050000 6.560000 ( 6.563223)
14
+ parse 6.300000 0.040000 6.340000 ( 6.362272)
15
+ ---------------------------------------- total: 12.900000sec
16
+
17
+ user system total real
18
+ parse in order 6.310000 0.060000 6.370000 ( 6.390945)
19
+ parse 6.300000 0.050000 6.350000 ( 6.366709)
20
+
21
+
22
+ api_changes branch before merge (2008-06-07)
23
+
24
+ Rehearsal --------------------------------------------------
25
+ parse in order 6.330000 0.050000 6.380000 ( 6.397552)
26
+ parse 6.380000 0.050000 6.430000 ( 6.446954)
27
+ ---------------------------------------- total: 12.810000sec
28
+
29
+ user system total real
30
+ parse in order 6.320000 0.040000 6.360000 ( 6.394460)
31
+ parse 6.040000 0.040000 6.080000 ( 6.099738)
32
+ =end
33
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../lib/yard'
3
+
4
+ log.level = Logger::DEBUG
5
+ YARD::Registry.load
6
+ gclass = eval("YARD::Generators::#{ARGV[0]}")
7
+ sclass = ARGV[1] == "nil" ? nil : eval("YARD::Serializers::#{ARGV[1]}")
8
+ obj = ARGV[2] == "all" ? YARD::Registry.all(:module, :class) : P(ARGV[2])
9
+ format = ARGV[3].to_sym
10
+
11
+ if sclass
12
+ sclass = sclass.new
13
+ else
14
+ sclass = YARD::Serializers::StdoutSerializer.new(80)
15
+ end
16
+ verifier = lambda {|gen, obj| return false if gen.respond_to?(:visibility) && [:protected, :private].include?(gen.visibility) }
17
+ gclass.new(:format => format, :template => :default, :serializer => sclass, :verifier => verifier).generate(obj)
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../lib/yard'
3
+
4
+ YARD::CLI::YardGraph.run(*ARGV)
data/bin/yardoc CHANGED
@@ -1,96 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + '/../lib/yard'
3
- include YARD
4
3
 
5
- if ARGV[0] == "-h"
6
- puts "yardoc #{VERSION}"
7
- return
8
- end
9
-
10
- Dir.mkdir("doc") unless FileTest.directory?("doc")
11
- Namespace.load(Namespace::DEFAULT_YARDOC_FILE, true)
12
- ac = File.open("doc/all-classes.html", "w")
13
- ac.puts <<-eof
14
- <html>
15
- <head>
16
- <base target="main" />
17
- </head>
18
- <body>
19
- <h3>All Classes</h3>
20
- eof
21
- am = File.open("doc/all-modules.html", "w")
22
- am.puts <<-eof
23
- <html>
24
- <head>
25
- <base target="main" />
26
- </head>
27
- <body>
28
- <h3>All Modules</h3>
29
- eof
30
- meths = []
31
- Namespace.all.sort.each do |path|
32
- object = Namespace.at(path)
33
- if object.is_a?(MethodObject) && object.visibility == :public
34
- meths << [object.name, object]
35
- end
36
-
37
- indexfile = nil
38
-
39
- case object
40
- when ClassObject
41
- indexfile = ac
42
- when ModuleObject
43
- indexfile = am
44
- else
45
- next
46
- end
47
-
48
- indexfile.puts "<a href='" + path.gsub("::","_") + ".html'>" + path + "</a><br />"
49
- puts "Generating " + (docfile = "doc/#{path.gsub('::','_')}.html") + "..."
50
- File.open(docfile, "w") {|f| f.write(object.to_s) }
51
- end
52
- ac.puts "</body></html>"
53
- ac.close
54
- am.puts "</body></html>"
55
- am.close
56
-
57
- File.open("doc/all-methods.html", "w") do |f|
58
- f.puts <<-eof
59
- <html>
60
- <head>
61
- <base target="main" />
62
- </head>
63
- <body>
64
- <h3>All Methods</h3>
65
- eof
66
- meths.sort {|a,b| a.first <=> b.first }.each do |name, object|
67
- f.puts "<a href='" + object.parent.path.gsub("::", "_") + ".html##{object.scope}_method-#{name}'>#{name}</a><br />"
68
- end
69
- end
70
-
71
- if ARGV[0]
72
- main_page = ARGV[0]
73
- else
74
- main_page = Namespace.all.sort.find {|name| Namespace.at(name).is_a? YARD::ClassObject }
75
- end
76
- main_page = main_page.gsub("::", "_") + ".html"
77
- File.open("doc/index.html", "w") do |f|
78
- f.puts <<-eof
79
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
80
- "http://www.w3.org/TR/html4/loose.dtd">
81
- <html>
82
- <head>
83
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
84
- <title>Ruby Classes</title>
85
- </head>
86
- <frameset cols="250,*">
87
- <frameset rows="40%,40%,20%">
88
- <frame src="all-classes.html">
89
- <frame src="all-modules.html">
90
- <frame src="all-methods.html">
91
- </frameset>
92
- <frame name="main" src="#{main_page}">
93
- </frameset>
94
- </html>
95
- eof
96
- end
4
+ YARD::CLI::Yardoc.run(*ARGV)