yard 0.6.8 → 0.7.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 (224) hide show
  1. data/.yardopts +1 -0
  2. data/ChangeLog +723 -0
  3. data/README.md +16 -6
  4. data/docs/CodeObjects.md +10 -16
  5. data/docs/GettingStarted.md +232 -32
  6. data/docs/Glossary.md +1 -2
  7. data/docs/Handlers.md +10 -16
  8. data/docs/Overview.md +14 -13
  9. data/docs/Parser.md +13 -22
  10. data/docs/Tags.md +209 -16
  11. data/docs/Templates.md +237 -26
  12. data/docs/WhatsNew.md +178 -2
  13. data/lib/yard.rb +13 -10
  14. data/lib/yard/autoload.rb +22 -18
  15. data/lib/yard/cli/command.rb +13 -12
  16. data/lib/yard/cli/command_parser.rb +20 -19
  17. data/lib/yard/cli/config.rb +19 -19
  18. data/lib/yard/cli/diff.rb +46 -21
  19. data/lib/yard/cli/gems.rb +11 -11
  20. data/lib/yard/cli/graph.rb +13 -13
  21. data/lib/yard/cli/help.rb +1 -1
  22. data/lib/yard/cli/list.rb +22 -0
  23. data/lib/yard/cli/server.rb +17 -17
  24. data/lib/yard/cli/stats.rb +32 -32
  25. data/lib/yard/cli/yardoc.rb +181 -135
  26. data/lib/yard/cli/yri.rb +29 -29
  27. data/lib/yard/code_objects/base.rb +101 -101
  28. data/lib/yard/code_objects/class_object.rb +20 -20
  29. data/lib/yard/code_objects/constant_object.rb +1 -1
  30. data/lib/yard/code_objects/extended_method_object.rb +5 -5
  31. data/lib/yard/code_objects/extra_file_object.rb +89 -0
  32. data/lib/yard/code_objects/macro_object.rb +215 -0
  33. data/lib/yard/code_objects/method_object.rb +30 -30
  34. data/lib/yard/code_objects/module_object.rb +1 -1
  35. data/lib/yard/code_objects/namespace_object.rb +39 -39
  36. data/lib/yard/code_objects/proxy.rb +38 -38
  37. data/lib/yard/code_objects/root_object.rb +1 -1
  38. data/lib/yard/config.rb +40 -40
  39. data/lib/yard/core_ext/array.rb +2 -2
  40. data/lib/yard/core_ext/file.rb +11 -11
  41. data/lib/yard/core_ext/insertion.rb +10 -10
  42. data/lib/yard/core_ext/module.rb +2 -2
  43. data/lib/yard/core_ext/string.rb +2 -2
  44. data/lib/yard/core_ext/symbol_hash.rb +14 -14
  45. data/lib/yard/docstring.rb +122 -54
  46. data/lib/yard/globals.rb +2 -2
  47. data/lib/yard/handlers/base.rb +216 -127
  48. data/lib/yard/handlers/processor.rb +65 -27
  49. data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
  50. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
  51. data/lib/yard/handlers/ruby/base.rb +50 -31
  52. data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
  53. data/lib/yard/handlers/ruby/class_handler.rb +10 -10
  54. data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
  55. data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
  56. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  57. data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
  58. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
  59. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
  60. data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
  61. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
  62. data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
  63. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
  64. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
  65. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
  66. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
  67. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
  68. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
  69. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
  70. data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
  71. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
  72. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  73. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
  74. data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
  75. data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
  76. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  77. data/lib/yard/handlers/ruby/method_handler.rb +13 -13
  78. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
  79. data/lib/yard/handlers/ruby/module_handler.rb +2 -1
  80. data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
  81. data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
  82. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  83. data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
  84. data/lib/yard/logging.rb +11 -11
  85. data/lib/yard/parser/base.rb +8 -8
  86. data/lib/yard/parser/c_parser.rb +42 -33
  87. data/lib/yard/parser/ruby/ast_node.rb +62 -61
  88. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
  89. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
  90. data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
  91. data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
  92. data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
  93. data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
  94. data/lib/yard/parser/source_parser.rb +271 -46
  95. data/lib/yard/rake/yardoc_task.rb +18 -17
  96. data/lib/yard/registry.rb +64 -64
  97. data/lib/yard/registry_store.rb +34 -34
  98. data/lib/yard/rubygems/backports.rb +8 -0
  99. data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
  100. data/lib/yard/rubygems/backports/MIT.txt +20 -0
  101. data/lib/yard/rubygems/backports/gem.rb +8 -0
  102. data/lib/yard/rubygems/backports/source_index.rb +353 -0
  103. data/lib/yard/rubygems/specification.rb +2 -2
  104. data/lib/yard/serializers/base.rb +20 -20
  105. data/lib/yard/serializers/file_system_serializer.rb +28 -24
  106. data/lib/yard/serializers/process_serializer.rb +3 -3
  107. data/lib/yard/serializers/stdout_serializer.rb +6 -6
  108. data/lib/yard/serializers/yardoc_serializer.rb +17 -17
  109. data/lib/yard/server/adapter.rb +12 -12
  110. data/lib/yard/server/commands/base.rb +26 -26
  111. data/lib/yard/server/commands/display_file_command.rb +3 -2
  112. data/lib/yard/server/commands/display_object_command.rb +5 -5
  113. data/lib/yard/server/commands/frames_command.rb +1 -1
  114. data/lib/yard/server/commands/library_command.rb +7 -7
  115. data/lib/yard/server/commands/library_index_command.rb +2 -2
  116. data/lib/yard/server/commands/list_command.rb +8 -8
  117. data/lib/yard/server/commands/search_command.rb +8 -8
  118. data/lib/yard/server/commands/static_file_command.rb +3 -3
  119. data/lib/yard/server/doc_server_helper.rb +6 -3
  120. data/lib/yard/server/doc_server_serializer.rb +1 -1
  121. data/lib/yard/server/library_version.rb +45 -45
  122. data/lib/yard/server/rack_adapter.rb +10 -10
  123. data/lib/yard/server/router.rb +28 -28
  124. data/lib/yard/server/static_caching.rb +5 -5
  125. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
  126. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
  127. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
  128. data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
  129. data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
  130. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
  131. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
  132. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
  133. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
  134. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  135. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
  136. data/lib/yard/server/webrick_adapter.rb +2 -2
  137. data/lib/yard/tags/default_factory.rb +19 -19
  138. data/lib/yard/tags/default_tag.rb +1 -1
  139. data/lib/yard/tags/library.rb +68 -63
  140. data/lib/yard/tags/option_tag.rb +1 -1
  141. data/lib/yard/tags/overload_tag.rb +9 -9
  142. data/lib/yard/tags/ref_tag_list.rb +2 -2
  143. data/lib/yard/tags/tag.rb +7 -7
  144. data/lib/yard/templates/engine.rb +31 -31
  145. data/lib/yard/templates/erb_cache.rb +1 -1
  146. data/lib/yard/templates/helpers/base_helper.rb +46 -32
  147. data/lib/yard/templates/helpers/filter_helper.rb +2 -2
  148. data/lib/yard/templates/helpers/html_helper.rb +120 -81
  149. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
  150. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
  151. data/lib/yard/templates/helpers/markup_helper.rb +37 -30
  152. data/lib/yard/templates/helpers/method_helper.rb +7 -7
  153. data/lib/yard/templates/helpers/text_helper.rb +7 -7
  154. data/lib/yard/templates/helpers/uml_helper.rb +3 -3
  155. data/lib/yard/templates/section.rb +14 -14
  156. data/lib/yard/templates/template.rb +54 -54
  157. data/lib/yard/verifier.rb +27 -27
  158. data/spec/cli/list_spec.rb +8 -0
  159. data/spec/cli/yardoc_spec.rb +58 -10
  160. data/spec/code_objects/extra_file_object_spec.rb +132 -0
  161. data/spec/code_objects/macro_object_spec.rb +154 -0
  162. data/spec/docstring_spec.rb +90 -0
  163. data/spec/handlers/base_spec.rb +22 -0
  164. data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
  165. data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
  166. data/spec/handlers/macro_handler_spec.rb +140 -0
  167. data/spec/handlers/method_handler_spec.rb +28 -0
  168. data/spec/handlers/processor_spec.rb +4 -0
  169. data/spec/handlers/spec_helper.rb +1 -1
  170. data/spec/parser/c_parser_spec.rb +47 -16
  171. data/spec/parser/examples/extrafile.c.txt +8 -0
  172. data/spec/parser/examples/multifile.c.txt +6 -0
  173. data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
  174. data/spec/parser/source_parser_spec.rb +235 -0
  175. data/spec/rake/yardoc_task_spec.rb +22 -17
  176. data/spec/serializers/file_system_serializer_spec.rb +6 -0
  177. data/spec/server/commands/library_command_spec.rb +39 -0
  178. data/spec/spec_helper.rb +14 -0
  179. data/spec/templates/examples/method001.html +6 -6
  180. data/spec/templates/examples/method002.html +4 -4
  181. data/spec/templates/examples/method003.html +10 -10
  182. data/spec/templates/examples/method005.html +2 -2
  183. data/spec/templates/examples/module001.dot +2 -0
  184. data/spec/templates/examples/module001.html +76 -37
  185. data/spec/templates/examples/module001.txt +1 -1
  186. data/spec/templates/helpers/base_helper_spec.rb +7 -2
  187. data/spec/templates/helpers/html_helper_spec.rb +49 -5
  188. data/spec/templates/helpers/markup_helper_spec.rb +9 -8
  189. data/spec/templates/module_spec.rb +7 -0
  190. data/spec/templates/onefile_spec.rb +47 -0
  191. data/templates/default/fulldoc/html/css/style.css +7 -5
  192. data/templates/default/fulldoc/html/full_list.erb +13 -10
  193. data/templates/default/fulldoc/html/full_list_files.erb +1 -1
  194. data/templates/default/fulldoc/html/js/app.js +16 -14
  195. data/templates/default/fulldoc/html/js/full_list.js +7 -6
  196. data/templates/default/fulldoc/html/setup.rb +78 -17
  197. data/templates/default/layout/html/files.erb +1 -1
  198. data/templates/default/layout/html/headers.erb +11 -7
  199. data/templates/default/layout/html/search.erb +4 -4
  200. data/templates/default/layout/html/setup.rb +28 -8
  201. data/templates/default/module/html/inherited_attributes.erb +17 -0
  202. data/templates/default/module/setup.rb +1 -1
  203. data/templates/default/onefile/html/files.erb +2 -2
  204. data/templates/default/onefile/html/layout.erb +1 -1
  205. data/templates/default/onefile/html/setup.rb +7 -5
  206. data/templates/default/tags/html/option.erb +1 -1
  207. data/templates/default/tags/html/tag.erb +3 -3
  208. data/templates/guide/class/html/setup.rb +1 -0
  209. data/templates/guide/docstring/html/setup.rb +1 -0
  210. data/templates/guide/fulldoc/html/css/style.css +91 -0
  211. data/templates/guide/fulldoc/html/js/app.js +33 -0
  212. data/templates/guide/fulldoc/html/setup.rb +54 -0
  213. data/templates/guide/layout/html/layout.erb +81 -0
  214. data/templates/guide/layout/html/setup.rb +24 -0
  215. data/templates/guide/method/html/header.erb +18 -0
  216. data/templates/guide/method/html/setup.rb +21 -0
  217. data/templates/guide/module/html/header.erb +7 -0
  218. data/templates/guide/module/html/method_list.erb +5 -0
  219. data/templates/guide/module/html/setup.rb +26 -0
  220. data/templates/guide/tags/html/setup.rb +8 -0
  221. metadata +40 -7
  222. data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
  223. data/lib/yard/handlers/ruby/process_handler.rb +0 -18
  224. data/spec/handlers/process_handler_spec.rb +0 -17
@@ -5,7 +5,7 @@ module YARD
5
5
  module Template
6
6
  attr_accessor :class, :section
7
7
  attr_reader :options
8
-
8
+
9
9
  class << self
10
10
  # @return [Array<Module>] a list of modules to be automatically included
11
11
  # into any new template module
@@ -16,23 +16,23 @@ module YARD
16
16
  klass.extend(ClassMethods)
17
17
  end
18
18
  end
19
-
19
+
20
20
  self.extra_includes = []
21
-
21
+
22
22
  include ErbCache
23
23
  include Helpers::BaseHelper
24
24
  include Helpers::MethodHelper
25
25
 
26
26
  module ClassMethods
27
27
  attr_accessor :path, :full_path
28
-
28
+
29
29
  def full_paths
30
30
  included_modules.inject([full_path]) do |paths, mod|
31
31
  paths |= mod.full_paths if mod.respond_to?(:full_paths)
32
32
  paths
33
33
  end
34
34
  end
35
-
35
+
36
36
  def initialize(path, full_paths)
37
37
  full_path = full_paths.shift
38
38
  self.path = path
@@ -41,11 +41,11 @@ module YARD
41
41
  include_parent
42
42
  load_setup_rb
43
43
  end
44
-
44
+
45
45
  # Searches for a file identified by +basename+ in the template's
46
46
  # path as well as any mixed in template paths. Equivalent to calling
47
47
  # {ClassMethods#find_nth_file} with index of 1.
48
- #
48
+ #
49
49
  # @param [String] basename the filename to search for
50
50
  # @return [String] the full path of a file on disk with filename
51
51
  # +basename+ in one of the template's paths.
@@ -53,10 +53,10 @@ module YARD
53
53
  def find_file(basename)
54
54
  find_nth_file(basename)
55
55
  end
56
-
56
+
57
57
  # Searches for the nth file (where n = +index+) identified
58
58
  # by basename in the template's path and any mixed in template paths.
59
- #
59
+ #
60
60
  # @param [String] basename the filename to search for
61
61
  # @param [Fixnum] index the nth existing file to return
62
62
  # @return [String] the full path of the nth file on disk with
@@ -70,7 +70,7 @@ module YARD
70
70
  n += 1
71
71
  end
72
72
  end
73
-
73
+
74
74
  nil
75
75
  end
76
76
 
@@ -86,22 +86,22 @@ module YARD
86
86
  obj.send(:initialize, *args)
87
87
  obj
88
88
  end
89
-
89
+
90
90
  def run(*args)
91
91
  new(*args).run
92
92
  end
93
-
93
+
94
94
  def T(*path)
95
95
  Engine.template(*path)
96
96
  end
97
-
97
+
98
98
  # Alias for creating a {Section} with arguments
99
99
  # @see Section#initialize
100
100
  # @since 0.6.0
101
101
  def S(*args)
102
102
  Section.new(*args)
103
103
  end
104
-
104
+
105
105
  private
106
106
 
107
107
  def include_parent
@@ -116,7 +116,7 @@ module YARD
116
116
  end
117
117
  end
118
118
  end
119
-
119
+
120
120
  def include_inherited(full_paths)
121
121
  full_paths.reverse.each do |full_path|
122
122
  include Engine.template!(path, full_path)
@@ -130,12 +130,12 @@ module YARD
130
130
  end
131
131
  end
132
132
  end
133
-
133
+
134
134
  def initialize(opts = {})
135
135
  @cache, @cache_filename = {}, {}
136
136
  @sections, @options = [], {}
137
137
  add_options(opts)
138
-
138
+
139
139
  extend(Helpers::HtmlHelper) if options[:format] == :html
140
140
  extend(Helpers::TextHelper) if options[:format] == :text
141
141
  extend(Helpers::UMLHelper) if options[:format] == :dot
@@ -143,11 +143,11 @@ module YARD
143
143
 
144
144
  init
145
145
  end
146
-
146
+
147
147
  # Loads a template specified by path. If +:template+ or +:format+ is
148
148
  # specified in the {#options} hash, they are prepended and appended
149
149
  # to the path respectively.
150
- #
150
+ #
151
151
  # @param [Array<String, Symbol>] path the path of the template
152
152
  # @return [Template] the loaded template module
153
153
  def T(*path)
@@ -155,9 +155,9 @@ module YARD
155
155
  path.push(options[:format]) if options[:format]
156
156
  self.class.T(*path)
157
157
  end
158
-
158
+
159
159
  # Sets the sections (and subsections) to be rendered for the template
160
- #
160
+ #
161
161
  # @example Sets a set of erb sections
162
162
  # sections :a, :b, :c # searches for a.erb, b.erb, c.erb
163
163
  # @example Sets a set of method and erb sections
@@ -168,18 +168,18 @@ module YARD
168
168
  # # if they are yielded by the template (see #yieldall)
169
169
  # @param [Array<Symbol, String, Template, Array>] args the sections
170
170
  # to use to render the template. For symbols and strings, the
171
- # section will be executed as a method (if one exists), or rendered
172
- # from the file "name.erb" where name is the section name. For
173
- # templates, they will have {Template::ClassMethods#run} called on them.
171
+ # section will be executed as a method (if one exists), or rendered
172
+ # from the file "name.erb" where name is the section name. For
173
+ # templates, they will have {Template::ClassMethods#run} called on them.
174
174
  # Any subsections can be yielded to using yield or {#yieldall}
175
175
  def sections(*args)
176
176
  @sections = Section.new(nil, *args) if args.size > 0
177
177
  @sections
178
178
  end
179
-
179
+
180
180
  # Initialization called on the template. Override this in a 'setup.rb'
181
181
  # file in the template's path to implement a template
182
- #
182
+ #
183
183
  # @example A default set of sections
184
184
  # def init
185
185
  # sections :section1, :section2, [:subsection1, :etc]
@@ -187,10 +187,10 @@ module YARD
187
187
  # @see #sections
188
188
  def init
189
189
  end
190
-
190
+
191
191
  # Runs a template on +sects+ using extra options. This method should
192
192
  # not be called directly. Instead, call the class method {ClassMethods#run}
193
- #
193
+ #
194
194
  # @param [Hash, nil] opts any extra options to apply to sections
195
195
  # @param [Section, Array] sects a section list of sections to render
196
196
  # @param [Fixnum] start_at the index in the section list to start from
@@ -211,7 +211,7 @@ module YARD
211
211
  value = with_section do
212
212
  run(args.first, section, subsection_index, true, &block)
213
213
  end
214
- subsection_index += 1
214
+ subsection_index += 1
215
215
  value
216
216
  end
217
217
  out << (value || "")
@@ -220,14 +220,14 @@ module YARD
220
220
  end
221
221
  out
222
222
  end
223
-
223
+
224
224
  # Yields all subsections with any extra options
225
- #
225
+ #
226
226
  # @param [Hash] opts extra options to be applied to subsections
227
227
  def yieldall(opts = nil, &block)
228
228
  with_section { run(opts, section, &block) }
229
229
  end
230
-
230
+
231
231
  # @param [String, Symbol] section the section name
232
232
  # @yield calls subsections to be rendered
233
233
  # @return [String] the contents of the ERB rendered section
@@ -237,26 +237,26 @@ module YARD
237
237
  end
238
238
  send(method_name, &block)
239
239
  end
240
-
240
+
241
241
  # Returns the contents of a file. If +allow_inherited+ is set to +true+,
242
242
  # use +{{{__super__}}}+ inside the file contents to insert the contents
243
243
  # of the file from an inherited template. For instance, if +templates/b+
244
244
  # inherits from +templates/a+ and file "test.css" exists in both directories,
245
245
  # both file contents can be retrieved by having +templates/b/test.css+ look
246
246
  # like:
247
- #
247
+ #
248
248
  # {{{__super__}}}
249
249
  # ...
250
250
  # body { css styles here }
251
251
  # p.class { other styles }
252
- #
252
+ #
253
253
  # @param [String] basename the name of the file
254
254
  # @param [Boolean] allow_inherited whether inherited templates can
255
255
  # be inserted with +{{{__super__}}}+
256
256
  # @return [String] the contents of a file identified by +basename+. All
257
257
  # template paths (including any mixed in templates) are searched for
258
258
  # the file
259
- # @see ClassMethods#find_file
259
+ # @see ClassMethods#find_file
260
260
  # @see ClassMethods#find_nth_file
261
261
  def file(basename, allow_inherited = false)
262
262
  file = self.class.find_file(basename)
@@ -270,9 +270,9 @@ module YARD
270
270
 
271
271
  data
272
272
  end
273
-
273
+
274
274
  # Calls the ERB file from the last inherited template with {#section}.erb
275
- #
275
+ #
276
276
  # @param [Symbol, String] section if provided, uses a specific section name
277
277
  # @return [String] the rendered ERB file in any of the inherited template
278
278
  # paths.
@@ -282,36 +282,36 @@ module YARD
282
282
  method_name = ErbCache.method_for(filename) { erb_with(IO.read(filename), filename) }
283
283
  send(method_name, &block)
284
284
  end
285
-
285
+
286
286
  def options=(value)
287
287
  @options = value
288
288
  set_ivars
289
289
  end
290
-
290
+
291
291
  def inspect
292
292
  "Template(#{self.class.path}) [section=#{section.name}]"
293
293
  end
294
-
294
+
295
295
  protected
296
-
296
+
297
297
  def erb_file_for(section)
298
298
  "#{section}.erb"
299
299
  end
300
-
300
+
301
301
  def erb_with(content, filename = nil)
302
302
  erb = ERB.new(content, nil, options[:format] == :text ? '<>' : nil)
303
303
  erb.filename = filename if filename
304
304
  erb
305
305
  end
306
-
306
+
307
307
  private
308
-
308
+
309
309
  def render_section(section, &block)
310
310
  section = section.name if section.is_a?(Section)
311
311
  case section
312
312
  when Section, String, Symbol
313
313
  if respond_to?(section)
314
- send(section, &block)
314
+ send(section, &block)
315
315
  else
316
316
  erb(section, &block)
317
317
  end
@@ -323,37 +323,37 @@ module YARD
323
323
  def cache(section)
324
324
  content = @cache[section.to_sym]
325
325
  return content if content
326
-
326
+
327
327
  file = cache_filename(section)
328
328
  @cache_filename[section.to_sym] = file
329
329
  raise ArgumentError, "no template for section '#{section}' in #{self.class.path}" unless file
330
330
  @cache[section.to_sym] = IO.read(file)
331
331
  end
332
-
332
+
333
333
  def cache_filename(section)
334
334
  @cache_filename[section.to_sym] ||=
335
335
  self.class.find_file(erb_file_for(section))
336
336
  end
337
-
337
+
338
338
  def set_ivars
339
339
  options.each do |k, v|
340
340
  instance_variable_set("@#{k}", v)
341
341
  end
342
342
  end
343
-
343
+
344
344
  def add_options(opts = nil)
345
345
  return(yield) if opts.nil? && block_given?
346
346
  cur_opts = options if block_given?
347
-
347
+
348
348
  self.options = options.merge(opts)
349
-
349
+
350
350
  if block_given?
351
351
  value = yield
352
- self.options = cur_opts
352
+ self.options = cur_opts
353
353
  value
354
354
  end
355
355
  end
356
-
356
+
357
357
  def with_section(&block)
358
358
  sect = section
359
359
  value = yield
data/lib/yard/verifier.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  module YARD
2
2
  # Similar to a Proc, but runs a set of Ruby expressions using a small
3
3
  # DSL to make tag lookups easier.
4
- #
4
+ #
5
5
  # The syntax is as follows:
6
6
  # * All syntax is Ruby compatible
7
7
  # * +object+ (+o+ for short) exist to access the object being verified
8
8
  # * +@TAGNAME+ is translated into +object.tag('TAGNAME')+
9
9
  # * +@@TAGNAME+ is translated into +object.tags('TAGNAME')+
10
10
  # * +object+ can be omitted as target for method calls (it is implied)
11
- #
11
+ #
12
12
  # @example Create a verifier to check for objects that don't have @private tags
13
13
  # verifier = Verifier.new('!@private')
14
14
  # verifier.call(object) # => true (no @private tag)
@@ -34,30 +34,30 @@ module YARD
34
34
  # @return [Array<String>] a list of all expressions the verifier checks for
35
35
  # @since 0.5.6
36
36
  attr_reader :expressions
37
-
37
+
38
38
  def expressions=(value)
39
39
  @expressions = value
40
40
  create_method_from_expressions
41
41
  end
42
-
42
+
43
43
  # Creates a verifier from a set of expressions
44
- #
44
+ #
45
45
  # @param [Array<String>] expressions a list of Ruby expressions to
46
46
  # parse.
47
47
  def initialize(*expressions)
48
48
  @expressions = []
49
49
  add_expressions(*expressions)
50
50
  end
51
-
51
+
52
52
  # Adds a set of expressions and recompiles the verifier
53
- #
53
+ #
54
54
  # @param [Array<String>] expressions a list of expressions
55
55
  # @return [void]
56
56
  # @since 0.5.6
57
57
  def add_expressions(*expressions)
58
58
  self.expressions += expressions.flatten
59
59
  end
60
-
60
+
61
61
  # Passes any method calls to the object from the {#call}
62
62
  def method_missing(sym, *args, &block)
63
63
  if object.respond_to?(sym)
@@ -68,7 +68,7 @@ module YARD
68
68
  end
69
69
 
70
70
  # Tests the expressions on the object.
71
- #
71
+ #
72
72
  # @note If the object is a {CodeObjects::Proxy} the result will always be true.
73
73
  # @param [CodeObjects::Base] object the object to verify
74
74
  # @return [Boolean] the result of the expressions
@@ -80,64 +80,64 @@ module YARD
80
80
  unmodify_nilclass
81
81
  retval
82
82
  end
83
-
84
- # Runs a list of objects against the verifier and returns the subset
83
+
84
+ # Runs a list of objects against the verifier and returns the subset
85
85
  # of verified objects.
86
- #
86
+ #
87
87
  # @param [Array<CodeObjects::Base>] list a list of code objects
88
88
  # @return [Array<CodeObjects::Base>] a list of code objects that match
89
89
  # the verifier.
90
90
  def run(list)
91
91
  list.reject {|item| call(item).is_a?(FalseClass) }
92
92
  end
93
-
93
+
94
94
  protected
95
-
95
+
96
96
  # @return [CodeObjects::Base] the current object being tested
97
97
  attr_reader :object
98
98
  alias o object
99
-
99
+
100
100
  private
101
-
101
+
102
102
  # @private
103
103
  NILCLASS_METHODS = [:type, :method_missing]
104
-
104
+
105
105
  # Modifies nil to not throw NoMethodErrors. This allows
106
106
  # syntax like object.tag(:return).text to work if the #tag
107
107
  # call returns nil, which means users don't need to perform
108
108
  # stringent nil checking
109
- #
110
- # @return [void]
109
+ #
110
+ # @return [void]
111
111
  def modify_nilclass
112
112
  NILCLASS_METHODS.each do |meth|
113
113
  NilClass.send(:define_method, meth) {|*args| }
114
114
  end
115
115
  end
116
-
116
+
117
117
  # Returns the state of NilClass back to normal
118
- # @return [void]
118
+ # @return [void]
119
119
  def unmodify_nilclass
120
120
  NILCLASS_METHODS.each do |meth|
121
121
  NilClass.send(:undef_method, meth)
122
122
  end
123
123
  end
124
-
124
+
125
125
  # Creates the +__execute+ method by evaluating the expressions
126
126
  # as Ruby code
127
- # @return [void]
127
+ # @return [void]
128
128
  def create_method_from_expressions
129
129
  expr = expressions.map {|e| "(#{parse_expression(e)})" }.join(" && ")
130
-
130
+
131
131
  instance_eval(<<-eof, __FILE__, __LINE__ + 1)
132
132
  def __execute; #{expr}; end
133
133
  eof
134
134
  end
135
-
135
+
136
136
  # Parses a single expression, handling some of the DSL syntax.
137
- #
137
+ #
138
138
  # The syntax "@tag" should be turned into object.tag(:tag),
139
139
  # and "@@tag" should be turned into object.tags(:tag)
140
- #
140
+ #
141
141
  # @return [String] the parsed expression
142
142
  def parse_expression(expr)
143
143
  expr = expr.gsub(/@@(\w+)/, 'object.tags("\1")')