yard 0.5.8 → 0.6.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 (211) hide show
  1. data/.yardopts +2 -0
  2. data/ChangeLog +1064 -0
  3. data/README.md +103 -42
  4. data/Rakefile +3 -2
  5. data/benchmarks/parsing.rb +2 -1
  6. data/bin/yard +4 -0
  7. data/bin/yard-graph +1 -1
  8. data/bin/yard-server +4 -0
  9. data/docs/GettingStarted.md +8 -8
  10. data/docs/Handlers.md +5 -5
  11. data/docs/Overview.md +5 -5
  12. data/docs/Parser.md +1 -1
  13. data/docs/Tags.md +1 -1
  14. data/docs/Templates.md +27 -6
  15. data/docs/WhatsNew.md +222 -2
  16. data/lib/rubygems_plugin.rb +1 -0
  17. data/lib/yard.rb +7 -1
  18. data/lib/yard/autoload.rb +46 -6
  19. data/lib/yard/cli/{base.rb → command.rb} +20 -6
  20. data/lib/yard/cli/command_parser.rb +87 -0
  21. data/lib/yard/cli/diff.rb +176 -0
  22. data/lib/yard/cli/gems.rb +74 -0
  23. data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
  24. data/lib/yard/cli/help.rb +18 -0
  25. data/lib/yard/cli/server.rb +137 -0
  26. data/lib/yard/cli/stats.rb +210 -0
  27. data/lib/yard/cli/yardoc.rb +315 -116
  28. data/lib/yard/cli/yri.rb +45 -4
  29. data/lib/yard/code_objects/base.rb +73 -30
  30. data/lib/yard/code_objects/class_object.rb +9 -1
  31. data/lib/yard/code_objects/method_object.rb +11 -0
  32. data/lib/yard/code_objects/namespace_object.rb +8 -2
  33. data/lib/yard/code_objects/proxy.rb +2 -2
  34. data/lib/yard/core_ext/array.rb +3 -49
  35. data/lib/yard/core_ext/file.rb +7 -0
  36. data/lib/yard/core_ext/insertion.rb +60 -0
  37. data/lib/yard/docstring.rb +34 -7
  38. data/lib/yard/globals.rb +2 -2
  39. data/lib/yard/handlers/base.rb +101 -20
  40. data/lib/yard/handlers/processor.rb +23 -7
  41. data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
  42. data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
  43. data/lib/yard/handlers/ruby/base.rb +71 -2
  44. data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
  45. data/lib/yard/handlers/ruby/class_handler.rb +7 -4
  46. data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
  47. data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
  48. data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
  49. data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
  50. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
  51. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
  52. data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
  53. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
  54. data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
  55. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
  56. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
  57. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
  58. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
  59. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
  60. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
  61. data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
  62. data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
  63. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
  64. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
  65. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
  66. data/lib/yard/handlers/ruby/method_handler.rb +5 -1
  67. data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
  68. data/lib/yard/handlers/ruby/module_handler.rb +1 -0
  69. data/lib/yard/handlers/ruby/process_handler.rb +7 -1
  70. data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
  71. data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
  72. data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
  73. data/lib/yard/logging.rb +7 -1
  74. data/lib/yard/parser/base.rb +1 -0
  75. data/lib/yard/parser/c_parser.rb +2 -0
  76. data/lib/yard/parser/ruby/ast_node.rb +82 -63
  77. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
  78. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
  79. data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
  80. data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
  81. data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
  82. data/lib/yard/parser/source_parser.rb +6 -1
  83. data/lib/yard/registry.rb +284 -278
  84. data/lib/yard/registry_store.rb +4 -2
  85. data/lib/yard/serializers/base.rb +30 -13
  86. data/lib/yard/serializers/file_system_serializer.rb +10 -1
  87. data/lib/yard/server/adapter.rb +51 -0
  88. data/lib/yard/server/commands/base.rb +98 -0
  89. data/lib/yard/server/commands/display_file_command.rb +20 -0
  90. data/lib/yard/server/commands/display_object_command.rb +50 -0
  91. data/lib/yard/server/commands/frames_command.rb +31 -0
  92. data/lib/yard/server/commands/library_command.rb +83 -0
  93. data/lib/yard/server/commands/library_index_command.rb +23 -0
  94. data/lib/yard/server/commands/list_command.rb +44 -0
  95. data/lib/yard/server/commands/search_command.rb +67 -0
  96. data/lib/yard/server/commands/static_file_command.rb +45 -0
  97. data/lib/yard/server/doc_server_helper.rb +22 -0
  98. data/lib/yard/server/doc_server_serializer.rb +29 -0
  99. data/lib/yard/server/library_version.rb +86 -0
  100. data/lib/yard/server/rack_adapter.rb +38 -0
  101. data/lib/yard/server/router.rb +110 -0
  102. data/lib/yard/server/static_caching.rb +16 -0
  103. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
  104. data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
  105. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
  106. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
  107. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
  108. data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
  109. data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
  110. data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
  111. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
  112. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
  113. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
  114. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
  115. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
  116. data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
  117. data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
  118. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
  119. data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
  120. data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
  121. data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
  122. data/lib/yard/server/webrick_adapter.rb +38 -0
  123. data/lib/yard/tags/default_factory.rb +0 -5
  124. data/lib/yard/tags/library.rb +61 -22
  125. data/lib/yard/tags/tag.rb +26 -4
  126. data/lib/yard/templates/engine.rb +12 -1
  127. data/lib/yard/templates/erb_cache.rb +2 -1
  128. data/lib/yard/templates/helpers/base_helper.rb +96 -3
  129. data/lib/yard/templates/helpers/filter_helper.rb +5 -0
  130. data/lib/yard/templates/helpers/html_helper.rb +204 -94
  131. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
  132. data/lib/yard/templates/helpers/markup_helper.rb +58 -3
  133. data/lib/yard/templates/helpers/method_helper.rb +7 -0
  134. data/lib/yard/templates/helpers/module_helper.rb +5 -0
  135. data/lib/yard/templates/helpers/text_helper.rb +10 -1
  136. data/lib/yard/templates/helpers/uml_helper.rb +13 -0
  137. data/lib/yard/templates/section.rb +106 -0
  138. data/lib/yard/templates/template.rb +20 -19
  139. data/lib/yard/verifier.rb +21 -2
  140. data/spec/cli/command_parser_spec.rb +43 -0
  141. data/spec/cli/diff_spec.rb +170 -0
  142. data/spec/cli/help_spec.rb +22 -0
  143. data/spec/cli/server_spec.rb +140 -0
  144. data/spec/cli/stats_spec.rb +75 -0
  145. data/spec/cli/yardoc_spec.rb +438 -182
  146. data/spec/cli/yri_spec.rb +13 -1
  147. data/spec/code_objects/base_spec.rb +51 -6
  148. data/spec/code_objects/class_object_spec.rb +15 -1
  149. data/spec/code_objects/method_object_spec.rb +29 -0
  150. data/spec/code_objects/namespace_object_spec.rb +150 -129
  151. data/spec/core_ext/array_spec.rb +4 -23
  152. data/spec/core_ext/insertion_spec.rb +37 -0
  153. data/spec/docstring_spec.rb +63 -0
  154. data/spec/handlers/attribute_handler_spec.rb +4 -0
  155. data/spec/handlers/base_spec.rb +98 -26
  156. data/spec/handlers/class_handler_spec.rb +5 -1
  157. data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
  158. data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
  159. data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
  160. data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
  161. data/spec/handlers/method_handler_spec.rb +5 -0
  162. data/spec/handlers/module_handler_spec.rb +4 -0
  163. data/spec/handlers/visibility_handler_spec.rb +6 -0
  164. data/spec/parser/source_parser_spec.rb +24 -0
  165. data/spec/registry_spec.rb +44 -8
  166. data/spec/server/adapter_spec.rb +38 -0
  167. data/spec/server/commands/base_spec.rb +87 -0
  168. data/spec/server/commands/static_file_command_spec.rb +67 -0
  169. data/spec/server/doc_server_serializer_spec.rb +58 -0
  170. data/spec/server/router_spec.rb +115 -0
  171. data/spec/server/spec_helper.rb +17 -0
  172. data/spec/server/static_caching_spec.rb +39 -0
  173. data/spec/server/webrick_servlet_spec.rb +20 -0
  174. data/spec/templates/constant_spec.rb +40 -0
  175. data/spec/templates/engine_spec.rb +9 -5
  176. data/spec/templates/examples/class002.html +1 -3
  177. data/spec/templates/examples/constant001.txt +25 -0
  178. data/spec/templates/examples/constant002.txt +7 -0
  179. data/spec/templates/examples/constant003.txt +11 -0
  180. data/spec/templates/examples/module001.txt +1 -1
  181. data/spec/templates/examples/module002.html +319 -0
  182. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  183. data/spec/templates/helpers/html_helper_spec.rb +93 -3
  184. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
  185. data/spec/templates/helpers/markup_helper_spec.rb +94 -67
  186. data/spec/templates/helpers/shared_signature_examples.rb +9 -0
  187. data/spec/templates/helpers/text_helper_spec.rb +12 -0
  188. data/spec/templates/module_spec.rb +21 -4
  189. data/spec/templates/section_spec.rb +146 -0
  190. data/spec/templates/template_spec.rb +9 -20
  191. data/templates/default/class/setup.rb +5 -5
  192. data/templates/default/constant/text/header.erb +11 -0
  193. data/templates/default/constant/text/setup.rb +3 -0
  194. data/templates/default/fulldoc/html/css/style.css +29 -3
  195. data/templates/default/fulldoc/html/js/app.js +67 -1
  196. data/templates/default/fulldoc/html/js/full_list.js +3 -8
  197. data/templates/default/fulldoc/html/js/jquery.js +150 -15
  198. data/templates/default/fulldoc/html/setup.rb +9 -0
  199. data/templates/default/layout/html/footer.erb +1 -1
  200. data/templates/default/layout/html/setup.rb +7 -25
  201. data/templates/default/method_details/html/source.erb +1 -1
  202. data/templates/default/module/html/attribute_summary.erb +2 -2
  203. data/templates/default/module/html/method_summary.erb +2 -2
  204. data/templates/default/module/setup.rb +27 -4
  205. data/templates/default/onefile/html/files.erb +5 -0
  206. data/templates/default/onefile/html/layout.erb +22 -0
  207. data/templates/default/onefile/html/readme.erb +3 -0
  208. data/templates/default/onefile/html/setup.rb +40 -0
  209. data/templates/default/root/html/setup.rb +1 -0
  210. data/templates/default/tags/setup.rb +26 -33
  211. metadata +80 -10
@@ -5,7 +5,7 @@ describe YARD::Templates::Helpers::BaseHelper do
5
5
 
6
6
  describe '#run_verifier' do
7
7
  it "should run verifier proc against list if provided" do
8
- mock = mock(:verifier)
8
+ mock = Verifier.new
9
9
  mock.should_receive(:call).with(1)
10
10
  mock.should_receive(:call).with(2)
11
11
  mock.should_receive(:call).with(3)
@@ -14,7 +14,7 @@ describe YARD::Templates::Helpers::BaseHelper do
14
14
  end
15
15
 
16
16
  it "should prune list if lambda returns false and only false" do
17
- mock = mock(:verifier)
17
+ mock = Verifier.new
18
18
  should_receive(:options).at_least(1).times.and_return(:verifier => mock)
19
19
  mock.should_receive(:call).with(1).and_return(false)
20
20
  mock.should_receive(:call).with(2).and_return(true)
@@ -36,14 +36,14 @@ describe YARD::Templates::Helpers::HtmlHelper do
36
36
  describe '#charset' do
37
37
  it "should return foo if LANG=foo" do
38
38
  ENV.should_receive(:[]).with('LANG').and_return('shift_jis') if RUBY18
39
- Encoding.default_external.should_receive(:name).and_return('shift_jis') if RUBY19
39
+ Encoding.default_external.should_receive(:name).and_return('shift_jis') if defined?(Encoding)
40
40
  charset.should == 'shift_jis'
41
41
  end
42
42
 
43
43
  ['US-ASCII', 'ASCII-7BIT', 'ASCII-8BIT'].each do |type|
44
44
  it "should convert #{type} to iso-8859-1" do
45
45
  ENV.should_receive(:[]).with('LANG').and_return(type) if RUBY18
46
- Encoding.default_external.should_receive(:name).and_return(type) if RUBY19
46
+ Encoding.default_external.should_receive(:name).and_return(type) if defined?(Encoding)
47
47
  charset.should == 'iso-8859-1'
48
48
  end
49
49
  end
@@ -98,8 +98,16 @@ describe YARD::Templates::Helpers::HtmlHelper do
98
98
 
99
99
  describe '#htmlify' do
100
100
  it "should not use hard breaks for textile markup (RedCloth specific)" do
101
+ begin; require 'redcloth'; rescue LoadError; pending 'test requires redcloth gem' end
101
102
  htmlify("A\nB", :textile).should_not include("<br")
102
103
  end
104
+
105
+ it "should handle various encodings" do
106
+ stub!(:object).and_return(Registry.root)
107
+ Encoding.default_internal = 'utf-8' if defined?(Encoding)
108
+ htmlify("\xB0\xB1", :text)
109
+ # TODO: add more encoding tests
110
+ end
103
111
  end
104
112
 
105
113
  describe "#link_object" do
@@ -135,6 +143,15 @@ describe YARD::Templates::Helpers::HtmlHelper do
135
143
  stub!(:object).and_return(obj)
136
144
  link_object("Bar#a").should =~ %r{href="Bar.html#a-instance_method"}
137
145
  end
146
+
147
+ it "should use relative path in title" do
148
+ CodeObjects::ModuleObject.new(:root, :YARD)
149
+ CodeObjects::ClassObject.new(P('YARD'), :Bar)
150
+ stub!(:object).and_return(CodeObjects::ModuleObject.new(P('YARD'), :Foo))
151
+ serializer = Serializers::FileSystemSerializer.new
152
+ stub!(:serializer).and_return(serializer)
153
+ link_object("Bar").should =~ %r{>Bar</a>}
154
+ end
138
155
  end
139
156
 
140
157
  describe '#url_for' do
@@ -243,6 +260,61 @@ describe YARD::Templates::Helpers::HtmlHelper do
243
260
  :title => 'Steve'
244
261
  }
245
262
  end
263
+
264
+ it "should ignore {links} that begin with |...|" do
265
+ resolve_links("{|x|x == 1}").should == "{|x|x == 1}"
266
+ end
267
+
268
+ it "should warn about missing reference at right file location for object" do
269
+ YARD.parse_string <<-eof
270
+ # Comments here
271
+ # And a reference to {InvalidObject}
272
+ class MyObject; end
273
+ eof
274
+ logger = mock(:log)
275
+ logger.should_receive(:warn).ordered.with("In file `(stdin)':2: Cannot resolve link to InvalidObject from text:")
276
+ logger.should_receive(:warn).ordered.with("...{InvalidObject}")
277
+ stub!(:log).and_return(logger)
278
+ stub!(:object).and_return(Registry.at('MyObject'))
279
+ resolve_links(object.docstring)
280
+ end
281
+
282
+ it "should show ellipsis on either side if there is more on the line in a reference warning" do
283
+ YARD.parse_string <<-eof
284
+ # {InvalidObject1} beginning of line
285
+ # end of line {InvalidObject2}
286
+ # Middle of {InvalidObject3} line
287
+ # {InvalidObject4}
288
+ class MyObject; end
289
+ eof
290
+ logger = mock(:log)
291
+ logger.should_receive(:warn).ordered.with("In file `(stdin)':1: Cannot resolve link to InvalidObject1 from text:")
292
+ logger.should_receive(:warn).ordered.with("{InvalidObject1}...")
293
+ logger.should_receive(:warn).ordered.with("In file `(stdin)':2: Cannot resolve link to InvalidObject2 from text:")
294
+ logger.should_receive(:warn).ordered.with("...{InvalidObject2}")
295
+ logger.should_receive(:warn).ordered.with("In file `(stdin)':3: Cannot resolve link to InvalidObject3 from text:")
296
+ logger.should_receive(:warn).ordered.with("...{InvalidObject3}...")
297
+ logger.should_receive(:warn).ordered.with("In file `(stdin)':4: Cannot resolve link to InvalidObject4 from text:")
298
+ logger.should_receive(:warn).ordered.with("{InvalidObject4}")
299
+ stub!(:log).and_return(logger)
300
+ stub!(:object).and_return(Registry.at('MyObject'))
301
+ resolve_links(object.docstring)
302
+ end
303
+
304
+ it "should warn about missing reference for file template (no object)" do
305
+ @file = "myfile.txt"
306
+ logger = mock(:log)
307
+ logger.should_receive(:warn).ordered.with("In file `myfile.txt':3: Cannot resolve link to InvalidObject from text:")
308
+ logger.should_receive(:warn).ordered.with("...{InvalidObject Some Title}")
309
+ stub!(:log).and_return(logger)
310
+ stub!(:object).and_return(Registry.root)
311
+ resolve_links(<<-eof)
312
+ Hello world
313
+ This is a line
314
+ And {InvalidObject Some Title}
315
+ And more.
316
+ eof
317
+ end
246
318
  end
247
319
 
248
320
  describe '#signature' do
@@ -269,10 +341,11 @@ describe YARD::Templates::Helpers::HtmlHelper do
269
341
 
270
342
  it_should_behave_like "signature"
271
343
  end
272
-
344
+
273
345
  describe '#html_syntax_highlight' do
274
346
  before do
275
347
  stub!(:options).and_return(:no_highlight => false)
348
+ stub!(:object).and_return(Registry.root)
276
349
  end
277
350
 
278
351
  it "should return empty string on nil input" do
@@ -280,10 +353,18 @@ describe YARD::Templates::Helpers::HtmlHelper do
280
353
  end
281
354
 
282
355
  it "should call #html_syntax_highlight_ruby by default" do
356
+ Registry.root.source_type = nil
283
357
  should_receive(:html_syntax_highlight_ruby).with('def x; end')
284
358
  html_syntax_highlight('def x; end')
285
359
  end
286
360
 
361
+ it "should call #html_syntax_highlight_NAME if there's an object with a #source_type" do
362
+ Registry.root.source_type = :NAME
363
+ should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(true)
364
+ should_receive(:html_syntax_highlight_NAME).and_return("foobar")
365
+ html_syntax_highlight('def x; end').should == 'foobar'
366
+ end
367
+
287
368
  it "should call html_syntax_highlight_NAME if source starts with !!!NAME" do
288
369
  should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(true)
289
370
  should_receive(:html_syntax_highlight_NAME).and_return("foobar")
@@ -318,4 +399,13 @@ describe YARD::Templates::Helpers::HtmlHelper do
318
399
  resolve_links("({file:TEST})")
319
400
  end
320
401
  end
402
+
403
+ describe '#link_url' do
404
+ it "should add target if scheme is provided" do
405
+ link_url("http://url.com").should include(" target=\"_parent\"")
406
+ link_url("https://url.com").should include(" target=\"_parent\"")
407
+ link_url("irc://url.com").should include(" target=\"_parent\"")
408
+ link_url("../not/scheme").should_not include("target")
409
+ end
410
+ end
321
411
  end
@@ -5,6 +5,11 @@ describe YARD::Templates::Helpers::HtmlSyntaxHighlightHelper do
5
5
  include YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
6
6
 
7
7
  describe '#html_syntax_highlight' do
8
+ before do
9
+ stub!(:object).and_return Registry.root
10
+ Registry.root.source_type = :ruby
11
+ end
12
+
8
13
  it "should not highlight source if options[:no_highlight] is set" do
9
14
  should_receive(:options).and_return(:no_highlight => true)
10
15
  html_syntax_highlight("def x\nend").should == "def x\nend"
@@ -10,85 +10,112 @@ class MyMock
10
10
  end
11
11
 
12
12
  describe YARD::Templates::Helpers::MarkupHelper do
13
- before do
14
- @gen = mock('Generator')
15
- @gen.extend(YARD::Templates::Helpers::MarkupHelper)
16
- end
13
+ describe '#load_markup_provider' do
14
+ before do
15
+ @gen = mock('Generator')
16
+ @gen.extend(YARD::Templates::Helpers::MarkupHelper)
17
+ end
17
18
 
18
- def generator_should_exit
19
- STDERR.should_receive(:puts)
20
- @gen.should_receive(:exit)
21
- end
19
+ def generator_should_exit
20
+ STDERR.should_receive(:puts)
21
+ @gen.should_receive(:exit)
22
+ end
22
23
 
23
- it "should exit on an invalid markup type" do
24
- generator_should_exit
25
- @gen.stub!(:options).and_return({:markup => :invalid})
24
+ it "should exit on an invalid markup type" do
25
+ generator_should_exit
26
+ @gen.stub!(:options).and_return({:markup => :invalid})
26
27
 
27
- # it will raise since providers == nil
28
- # but in reality it would have already `exit`ed.
29
- @gen.load_markup_provider rescue nil
30
- end
28
+ # it will raise since providers == nil
29
+ # but in reality it would have already `exit`ed.
30
+ @gen.load_markup_provider rescue nil
31
+ end
31
32
 
32
- it "should exit on when an invalid markup provider is specified" do
33
- generator_should_exit
34
- @gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :invalid})
33
+ it "should exit on when an invalid markup provider is specified" do
34
+ generator_should_exit
35
+ @gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :invalid})
35
36
 
36
- # it will raise since providers == nil
37
- # but in reality it would have already `exit`ed.
38
- @gen.load_markup_provider rescue nil
39
- @gen.markup_class.should == nil
40
- end
37
+ # it will raise since providers == nil
38
+ # but in reality it would have already `exit`ed.
39
+ @gen.load_markup_provider rescue nil
40
+ @gen.markup_class.should == nil
41
+ end
41
42
 
42
- it "should load nothing if rdoc is specified" do
43
- @gen.stub!(:options).and_return({:markup => :rdoc})
44
- @gen.load_markup_provider
45
- @gen.markup_class.should == YARD::Templates::Helpers::MarkupHelper::SimpleMarkup
46
- end
43
+ it "should load nothing if rdoc is specified" do
44
+ @gen.stub!(:options).and_return({:markup => :rdoc})
45
+ @gen.load_markup_provider
46
+ @gen.markup_class.should == YARD::Templates::Helpers::MarkupHelper::SimpleMarkup
47
+ end
47
48
 
48
- it "should search through available markup providers for the markup type if none is set" do
49
- @gen.should_receive(:require).with('bluecloth').and_return(true)
50
- @gen.stub!(:options).and_return({:markup => :markdown})
51
- # this only raises an exception because we mock out require to avoid
52
- # loading any libraries but our implementation tries to return the library
53
- # name as a constant
54
- @gen.load_markup_provider rescue nil
55
- @gen.markup_provider.should == :bluecloth
56
- end
49
+ it "should search through available markup providers for the markup type if none is set" do
50
+ @gen.should_receive(:require).with('bluecloth').and_return(true)
51
+ @gen.stub!(:options).and_return({:markup => :markdown})
52
+ # this only raises an exception because we mock out require to avoid
53
+ # loading any libraries but our implementation tries to return the library
54
+ # name as a constant
55
+ @gen.load_markup_provider rescue nil
56
+ @gen.markup_provider.should == :bluecloth
57
+ end
57
58
 
58
- it "should continue searching if some of the providers are unavailable" do
59
- @gen.should_receive(:require).with('bluecloth').and_raise(LoadError)
60
- @gen.should_receive(:require).with('maruku').and_raise(LoadError)
61
- @gen.should_receive(:require).with('rpeg-markdown').and_return(true)
62
- @gen.stub!(:options).and_return({:markup => :markdown})
63
- # this only raises an exception because we mock out require to avoid
64
- # loading any libraries but our implementation tries to return the library
65
- # name as a constant
66
- @gen.load_markup_provider rescue nil
67
- @gen.markup_provider.should == :"rpeg-markdown"
68
- end
59
+ it "should continue searching if some of the providers are unavailable" do
60
+ @gen.should_receive(:require).with('bluecloth').and_raise(LoadError)
61
+ @gen.should_receive(:require).with('maruku').and_raise(LoadError)
62
+ @gen.should_receive(:require).with('rpeg-markdown').and_return(true)
63
+ @gen.stub!(:options).and_return({:markup => :markdown})
64
+ # this only raises an exception because we mock out require to avoid
65
+ # loading any libraries but our implementation tries to return the library
66
+ # name as a constant
67
+ @gen.load_markup_provider rescue nil
68
+ @gen.markup_provider.should == :"rpeg-markdown"
69
+ end
69
70
 
70
- it "should override the search if `:markup_provider` is set in options" do
71
- @gen.should_receive(:require).with('rdiscount').and_return(true)
72
- @gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :rdiscount})
73
- @gen.load_markup_provider rescue nil
74
- @gen.markup_provider.should == :rdiscount
75
- end
71
+ it "should override the search if `:markup_provider` is set in options" do
72
+ @gen.should_receive(:require).with('rdiscount').and_return(true)
73
+ @gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :rdiscount})
74
+ @gen.load_markup_provider rescue nil
75
+ @gen.markup_provider.should == :rdiscount
76
+ end
76
77
 
77
- it "should fail if no provider is found" do
78
- generator_should_exit
79
- YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].each do |p|
80
- @gen.should_receive(:require).with(p[:lib].to_s).and_raise(LoadError)
78
+ it "should fail if no provider is found" do
79
+ generator_should_exit
80
+ YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].each do |p|
81
+ @gen.should_receive(:require).with(p[:lib].to_s).and_raise(LoadError)
82
+ end
83
+ @gen.stub!(:options).and_return({:markup => :markdown})
84
+ @gen.load_markup_provider rescue nil
85
+ @gen.markup_provider.should == nil
86
+ end
87
+
88
+ it "should fail if overridden provider is not found" do
89
+ generator_should_exit
90
+ @gen.should_receive(:require).with('rdiscount').and_raise(LoadError)
91
+ @gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :rdiscount})
92
+ @gen.load_markup_provider rescue nil
93
+ @gen.markup_provider.should == nil
81
94
  end
82
- @gen.stub!(:options).and_return({:markup => :markdown})
83
- @gen.load_markup_provider rescue nil
84
- @gen.markup_provider.should == nil
85
95
  end
96
+
97
+ describe '#markup_for_file' do
98
+ include YARD::Templates::Helpers::MarkupHelper
86
99
 
87
- it "should fail if overridden provider is not found" do
88
- generator_should_exit
89
- @gen.should_receive(:require).with('rdiscount').and_raise(LoadError)
90
- @gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :rdiscount})
91
- @gen.load_markup_provider rescue nil
92
- @gen.markup_provider.should == nil
100
+ it "should look for a shebang line" do
101
+ markup_for_file("#!text\ntext here", 'file.rdoc').should == :text
102
+ end
103
+
104
+ it "should return the default markup type if no shebang is found or no valid ext is found" do
105
+ stub!(:options).and_return({:markup => :default_type})
106
+ markup_for_file('', 'filename').should == :default_type
107
+ end
108
+
109
+ it "should look for a file extension if no shebang is found" do
110
+ markup_for_file('', 'filename.MD').should == :markdown
111
+ end
112
+
113
+ Templates::Helpers::MarkupHelper::MARKUP_EXTENSIONS.each do |type, exts|
114
+ exts.each do |ext|
115
+ it "should recognize .#{ext} as #{type} markup type" do
116
+ markup_for_file('', "filename.#{ext}").should == type
117
+ end
118
+ end
119
+ end
93
120
  end
94
121
  end
@@ -58,6 +58,15 @@ shared_examples_for "signature" do
58
58
  eof
59
59
  signature(Registry.at('#foo')).should == @results[:type_nil]
60
60
  end
61
+
62
+ it "should show 'Type?' if return types are [Type, nil, nil] (extra nil)" do
63
+ YARD.parse_string <<-'eof'
64
+ # @return [Type, nil]
65
+ # @return [nil]
66
+ def foo; end
67
+ eof
68
+ signature(Registry.at('#foo')).should == @results[:type_nil]
69
+ end
61
70
 
62
71
  it "should show 'Type+' if return types are [Type, Array<Type>]" do
63
72
  YARD.parse_string <<-'eof'
@@ -28,4 +28,16 @@ describe YARD::Templates::Helpers::TextHelper do
28
28
 
29
29
  it_should_behave_like "signature"
30
30
  end
31
+
32
+ describe '#align_right' do
33
+ it "should align text right" do
34
+ text = "Method: #some_method (SomeClass)"
35
+ align_right(text).should == ' ' * 40 + text
36
+ end
37
+
38
+ it "should truncate text that is longer than allowed width" do
39
+ text = "(Defined in: /home/user/.rip/.packages/some_gem-2460672e333ac07b9190ade88ec9a91c/long/path.rb)"
40
+ align_right(text).should == ' ' + text[0,68] + '...'
41
+ end
42
+ end
31
43
  end
@@ -56,10 +56,6 @@ describe YARD::Templates::Engine.template(:default, :module) do
56
56
  module TMP; include A end
57
57
  class TMP2; extend A end
58
58
  eof
59
-
60
- # Hack to clear mixin list
61
- mod = YARD::Templates::Engine.template(:default, :module)
62
- mod.send(:class_variable_set, "@@mixed_into", nil)
63
59
  end
64
60
 
65
61
  it "should render html format correctly" do
@@ -82,4 +78,25 @@ describe YARD::Templates::Engine.template(:default, :module) do
82
78
  it "should render dot format correctly" do
83
79
  Registry.at('A').format(:format => :dot, :dependencies => true, :full => true).should == example(:module001, 'dot')
84
80
  end
81
+
82
+ it "should render groups correctly in html" do
83
+ Registry.clear
84
+ YARD.parse_string <<-'eof'
85
+ module A
86
+ # @group Foo
87
+ attr_accessor :foo_attr
88
+ def foo; end
89
+ def self.bar; end
90
+
91
+ # @group Bar
92
+ def baz; end
93
+
94
+ # @endgroup
95
+
96
+ def self.baz; end
97
+ end
98
+ eof
99
+
100
+ html_equals(Registry.at('A').format(:format => :html, :no_highlight => true), :module002)
101
+ end
85
102
  end
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe YARD::Templates::Section do
4
+ include YARD::Templates
5
+
6
+ describe '#initialize' do
7
+ it "should convert first argument to splat if it is array" do
8
+ s = Section.new(:name, [:foo, :bar])
9
+ s.name.should == :name
10
+ s[0].name.should == :foo
11
+ s[1].name.should == :bar
12
+ end
13
+
14
+ it "should allow initialization with Section objects" do
15
+ s = Section.new(:name, [:foo, Section.new(:bar)])
16
+ s.name.should == :name
17
+ s[0].should == Section.new(:foo)
18
+ s[1].should == Section.new(:bar)
19
+ end
20
+
21
+ it "should make a list of sections" do
22
+ s = Section.new(:name, [:foo, [:bar]])
23
+ s.should == Section.new(:name, Section.new(:foo, Section.new(:bar)))
24
+ end
25
+ end
26
+
27
+ describe '#[]' do
28
+ it "should use Array#[] if argument is integer" do
29
+ Section.new(:name, [:foo, :bar])[0].name.should == :foo
30
+ end
31
+
32
+ it "should return new Section object if more than one argument" do
33
+ Section.new(:name, :foo, :bar, :baz)[1, 2].should ==
34
+ Section.new(:name, :bar, :baz)
35
+ end
36
+
37
+ it "should return new Section object if arg is Range" do
38
+ Section.new(:name, :foo, :bar, :baz)[1..2].should ==
39
+ Section.new(:name, :bar, :baz)
40
+ end
41
+
42
+ it "should look for section by name if arg is object" do
43
+ Section.new(:name, :foo, :bar, [:baz])[:bar][:baz].should ==
44
+ Section.new(:baz)
45
+ end
46
+ end
47
+
48
+ describe '#eql?' do
49
+ it "should check for equality of two equal sections" do
50
+ Section.new(:foo, [:a, :b]).should be_eql(Section.new(:foo, :a, :b))
51
+ Section.new(:foo, [:a, :b]).should == Section.new(:foo, :a, :b)
52
+ end
53
+
54
+ it "should not be equal if section names are different" do
55
+ Section.new(:foo, [:a, :b]).should_not be_eql(Section.new(:bar, :a, :b))
56
+ Section.new(:foo, [:a, :b]).should_not == Section.new(:bar, :a, :b)
57
+ end
58
+ end
59
+
60
+ describe '#==' do
61
+ it "should allow comparison to Symbol" do
62
+ Section.new(:foo, 2, 3).should == :foo
63
+ end
64
+
65
+ it "should allow comparison to String" do
66
+ Section.new("foo", 2, 3).should == "foo"
67
+ end
68
+
69
+ it "should allow comparison to Template" do
70
+ t = YARD::Templates::Engine.template!(:xyzzy, '/full/path/xyzzy')
71
+ Section.new(t, 2, 3).should == t
72
+ end
73
+
74
+ it "should allow comparison to Section" do
75
+ Section.new(1, [2, 3]).should == Section.new(1, 2, 3)
76
+ end
77
+
78
+ it "should allow comparison to Object" do
79
+ Section.new(1, [2, 3]).should == 1
80
+ end
81
+
82
+ it "should allow comparison to Array" do
83
+ Section.new(1, 2, [3]).should == [1, [2, [3]]]
84
+ end
85
+ end
86
+
87
+ describe '#to_a' do
88
+ it "should convert Section to regular Array list" do
89
+ arr = Section.new(1, 2, [3, [4]]).to_a
90
+ arr.class.should == Array
91
+ arr.should == [1, [2, [3, [4]]]]
92
+ end
93
+ end
94
+
95
+ describe '#place' do
96
+ it "should place objects as Sections" do
97
+ Section.new(1, 2, 3).place(4).before(3).should == [1, [2, 4, 3]]
98
+ end
99
+
100
+ it "should place objects anywhere inside Section with before/after_any" do
101
+ Section.new(1, 2, [3, [4]]).place(5).after_any(4).should == [1, [2, [3, [4, 5]]]]
102
+ Section.new(1, 2, [3, [4]]).place(5).before_any(4).should == [1, [2, [3, [5, 4]]]]
103
+ end
104
+
105
+ it "should allow multiple sections to be placed" do
106
+ Section.new(1, 2, 3).place(4, 5).after(3).to_a.should == [1, [2, 3, 4, 5]]
107
+ Section.new(1, 2, 3).place(4, [5]).after(3).to_a.should == [1, [2, 3, 4, [5]]]
108
+ end
109
+ end
110
+
111
+ describe '#push' do
112
+ it "should push objects as Sections" do
113
+ s = Section.new(:foo)
114
+ s.push :bar
115
+ s[0].should == Section.new(:bar)
116
+ end
117
+
118
+ it "should alias to #<<" do
119
+ s = Section.new(1)
120
+ s << :index
121
+ s[:index].should be_a(Section)
122
+ end
123
+ end
124
+
125
+ describe '#unshift' do
126
+ it "should unshift objects as Sections" do
127
+ s = Section.new(:foo)
128
+ s.unshift :bar
129
+ s[0].should == Section.new(:bar)
130
+ end
131
+ end
132
+
133
+ describe '#any' do
134
+ it "should find item inside sections" do
135
+ s = Section.new(:foo, Section.new(:bar, Section.new(:bar)))
136
+ s.any(:bar).push(:baz)
137
+ s.to_a.should == [:foo, [:bar, [:bar, :baz]]]
138
+ end
139
+
140
+ it "should find item in any deeply nested set of sections" do
141
+ s = Section.new(:foo, Section.new(:bar, Section.new(:baz)))
142
+ s.any(:baz).push(:qux)
143
+ s.to_a.should == [:foo, [:bar, [:baz, [:qux]]]]
144
+ end
145
+ end
146
+ end