From b7162ad9f3715e7eba10739ceb5174d861c6a7fb Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 18 Oct 2012 12:24:44 +0300 Subject: [PATCH] Allow links to private members. Remove an old restriction left over from the days when JSDuck didn't show private members at all. --- lib/jsduck/inline/link.rb | 2 +- spec/doc_formatter_spec.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/jsduck/inline/link.rb b/lib/jsduck/inline/link.rb index d125f100..33179fc5 100644 --- a/lib/jsduck/inline/link.rb +++ b/lib/jsduck/inline/link.rb @@ -208,7 +208,7 @@ module JsDuck end def get_matching_member(cls, query) - ms = find_members(cls, query).find_all {|m| !m[:private] } + ms = find_members(cls, query) if ms.length > 1 instance_ms = ms.find_all {|m| !m[:meta][:static] } instance_ms.length > 0 ? instance_ms[0] : ms.find_all {|m| m[:meta][:static] }[0] diff --git a/spec/doc_formatter_spec.rb b/spec/doc_formatter_spec.rb index af0557da..3feab1ec 100644 --- a/spec/doc_formatter_spec.rb +++ b/spec/doc_formatter_spec.rb @@ -26,6 +26,7 @@ describe JsDuck::DocFormatter do {:tagname => :cfg, :name => "bar", :id => "cfg-bar"}, {:tagname => :method, :name => "id", :id => "static-method-id", :meta => {:static => true}}, + {:tagname => :method, :name => "privMeth", :id => "method-privMeth", :private => true}, ], :alternateClassNames => ["FooBar"] }), @@ -51,6 +52,11 @@ describe JsDuck::DocFormatter do 'Look at Foo.id' end + it "replaces {@link Foo#privMeth} with link to private class member" do + @formatter.replace("Look at {@link Foo#privMeth}").should == + 'Look at Foo.privMeth' + end + it "uses context to replace {@link #bar} with link to class member" do @formatter.replace("Look at {@link #bar}").should == 'Look at bar' @@ -151,7 +157,8 @@ describe JsDuck::DocFormatter do JsDuck::Class.new({ :name => "Context", :members => [ - {:tagname => :method, :name => "bar", :id => "method-bar"} + {:tagname => :method, :name => "bar", :id => "method-bar"}, + {:tagname => :method, :name => "privMeth", :id => "method-privMeth", :private => true}, ] }), ]) @@ -234,6 +241,11 @@ describe JsDuck::DocFormatter do 'Look at bar method' end + it "converts #privMeth to link to private method" do + @formatter.replace("Look at #privMeth method").should == + 'Look at privMeth method' + end + it "Doesn't convert #unknown to link" do @formatter.replace("Ahh, an #unknown method").should == 'Ahh, an #unknown method' -- GitLab