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.
- data/.yardopts +2 -0
- data/ChangeLog +1064 -0
- data/README.md +103 -42
- data/Rakefile +3 -2
- data/benchmarks/parsing.rb +2 -1
- data/bin/yard +4 -0
- data/bin/yard-graph +1 -1
- data/bin/yard-server +4 -0
- data/docs/GettingStarted.md +8 -8
- data/docs/Handlers.md +5 -5
- data/docs/Overview.md +5 -5
- data/docs/Parser.md +1 -1
- data/docs/Tags.md +1 -1
- data/docs/Templates.md +27 -6
- data/docs/WhatsNew.md +222 -2
- data/lib/rubygems_plugin.rb +1 -0
- data/lib/yard.rb +7 -1
- data/lib/yard/autoload.rb +46 -6
- data/lib/yard/cli/{base.rb → command.rb} +20 -6
- data/lib/yard/cli/command_parser.rb +87 -0
- data/lib/yard/cli/diff.rb +176 -0
- data/lib/yard/cli/gems.rb +74 -0
- data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
- data/lib/yard/cli/help.rb +18 -0
- data/lib/yard/cli/server.rb +137 -0
- data/lib/yard/cli/stats.rb +210 -0
- data/lib/yard/cli/yardoc.rb +315 -116
- data/lib/yard/cli/yri.rb +45 -4
- data/lib/yard/code_objects/base.rb +73 -30
- data/lib/yard/code_objects/class_object.rb +9 -1
- data/lib/yard/code_objects/method_object.rb +11 -0
- data/lib/yard/code_objects/namespace_object.rb +8 -2
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/core_ext/array.rb +3 -49
- data/lib/yard/core_ext/file.rb +7 -0
- data/lib/yard/core_ext/insertion.rb +60 -0
- data/lib/yard/docstring.rb +34 -7
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +101 -20
- data/lib/yard/handlers/processor.rb +23 -7
- data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
- data/lib/yard/handlers/ruby/base.rb +71 -2
- data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
- data/lib/yard/handlers/ruby/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_handler.rb +5 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/process_handler.rb +7 -1
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
- data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
- data/lib/yard/logging.rb +7 -1
- data/lib/yard/parser/base.rb +1 -0
- data/lib/yard/parser/c_parser.rb +2 -0
- data/lib/yard/parser/ruby/ast_node.rb +82 -63
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
- data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
- data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
- data/lib/yard/parser/source_parser.rb +6 -1
- data/lib/yard/registry.rb +284 -278
- data/lib/yard/registry_store.rb +4 -2
- data/lib/yard/serializers/base.rb +30 -13
- data/lib/yard/serializers/file_system_serializer.rb +10 -1
- data/lib/yard/server/adapter.rb +51 -0
- data/lib/yard/server/commands/base.rb +98 -0
- data/lib/yard/server/commands/display_file_command.rb +20 -0
- data/lib/yard/server/commands/display_object_command.rb +50 -0
- data/lib/yard/server/commands/frames_command.rb +31 -0
- data/lib/yard/server/commands/library_command.rb +83 -0
- data/lib/yard/server/commands/library_index_command.rb +23 -0
- data/lib/yard/server/commands/list_command.rb +44 -0
- data/lib/yard/server/commands/search_command.rb +67 -0
- data/lib/yard/server/commands/static_file_command.rb +45 -0
- data/lib/yard/server/doc_server_helper.rb +22 -0
- data/lib/yard/server/doc_server_serializer.rb +29 -0
- data/lib/yard/server/library_version.rb +86 -0
- data/lib/yard/server/rack_adapter.rb +38 -0
- data/lib/yard/server/router.rb +110 -0
- data/lib/yard/server/static_caching.rb +16 -0
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
- data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
- data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
- data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
- data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
- data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
- data/lib/yard/server/webrick_adapter.rb +38 -0
- data/lib/yard/tags/default_factory.rb +0 -5
- data/lib/yard/tags/library.rb +61 -22
- data/lib/yard/tags/tag.rb +26 -4
- data/lib/yard/templates/engine.rb +12 -1
- data/lib/yard/templates/erb_cache.rb +2 -1
- data/lib/yard/templates/helpers/base_helper.rb +96 -3
- data/lib/yard/templates/helpers/filter_helper.rb +5 -0
- data/lib/yard/templates/helpers/html_helper.rb +204 -94
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
- data/lib/yard/templates/helpers/markup_helper.rb +58 -3
- data/lib/yard/templates/helpers/method_helper.rb +7 -0
- data/lib/yard/templates/helpers/module_helper.rb +5 -0
- data/lib/yard/templates/helpers/text_helper.rb +10 -1
- data/lib/yard/templates/helpers/uml_helper.rb +13 -0
- data/lib/yard/templates/section.rb +106 -0
- data/lib/yard/templates/template.rb +20 -19
- data/lib/yard/verifier.rb +21 -2
- data/spec/cli/command_parser_spec.rb +43 -0
- data/spec/cli/diff_spec.rb +170 -0
- data/spec/cli/help_spec.rb +22 -0
- data/spec/cli/server_spec.rb +140 -0
- data/spec/cli/stats_spec.rb +75 -0
- data/spec/cli/yardoc_spec.rb +438 -182
- data/spec/cli/yri_spec.rb +13 -1
- data/spec/code_objects/base_spec.rb +51 -6
- data/spec/code_objects/class_object_spec.rb +15 -1
- data/spec/code_objects/method_object_spec.rb +29 -0
- data/spec/code_objects/namespace_object_spec.rb +150 -129
- data/spec/core_ext/array_spec.rb +4 -23
- data/spec/core_ext/insertion_spec.rb +37 -0
- data/spec/docstring_spec.rb +63 -0
- data/spec/handlers/attribute_handler_spec.rb +4 -0
- data/spec/handlers/base_spec.rb +98 -26
- data/spec/handlers/class_handler_spec.rb +5 -1
- data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/method_handler_spec.rb +5 -0
- data/spec/handlers/module_handler_spec.rb +4 -0
- data/spec/handlers/visibility_handler_spec.rb +6 -0
- data/spec/parser/source_parser_spec.rb +24 -0
- data/spec/registry_spec.rb +44 -8
- data/spec/server/adapter_spec.rb +38 -0
- data/spec/server/commands/base_spec.rb +87 -0
- data/spec/server/commands/static_file_command_spec.rb +67 -0
- data/spec/server/doc_server_serializer_spec.rb +58 -0
- data/spec/server/router_spec.rb +115 -0
- data/spec/server/spec_helper.rb +17 -0
- data/spec/server/static_caching_spec.rb +39 -0
- data/spec/server/webrick_servlet_spec.rb +20 -0
- data/spec/templates/constant_spec.rb +40 -0
- data/spec/templates/engine_spec.rb +9 -5
- data/spec/templates/examples/class002.html +1 -3
- data/spec/templates/examples/constant001.txt +25 -0
- data/spec/templates/examples/constant002.txt +7 -0
- data/spec/templates/examples/constant003.txt +11 -0
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +319 -0
- data/spec/templates/helpers/base_helper_spec.rb +2 -2
- data/spec/templates/helpers/html_helper_spec.rb +93 -3
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
- data/spec/templates/helpers/markup_helper_spec.rb +94 -67
- data/spec/templates/helpers/shared_signature_examples.rb +9 -0
- data/spec/templates/helpers/text_helper_spec.rb +12 -0
- data/spec/templates/module_spec.rb +21 -4
- data/spec/templates/section_spec.rb +146 -0
- data/spec/templates/template_spec.rb +9 -20
- data/templates/default/class/setup.rb +5 -5
- data/templates/default/constant/text/header.erb +11 -0
- data/templates/default/constant/text/setup.rb +3 -0
- data/templates/default/fulldoc/html/css/style.css +29 -3
- data/templates/default/fulldoc/html/js/app.js +67 -1
- data/templates/default/fulldoc/html/js/full_list.js +3 -8
- data/templates/default/fulldoc/html/js/jquery.js +150 -15
- data/templates/default/fulldoc/html/setup.rb +9 -0
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/setup.rb +7 -25
- data/templates/default/method_details/html/source.erb +1 -1
- data/templates/default/module/html/attribute_summary.erb +2 -2
- data/templates/default/module/html/method_summary.erb +2 -2
- data/templates/default/module/setup.rb +27 -4
- data/templates/default/onefile/html/files.erb +5 -0
- data/templates/default/onefile/html/layout.erb +22 -0
- data/templates/default/onefile/html/readme.erb +3 -0
- data/templates/default/onefile/html/setup.rb +40 -0
- data/templates/default/root/html/setup.rb +1 -0
- data/templates/default/tags/setup.rb +26 -33
- 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 =
|
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 =
|
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
|
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
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def generator_should_exit
|
20
|
+
STDERR.should_receive(:puts)
|
21
|
+
@gen.should_receive(:exit)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|