Loading lib/jsduck/aggregator.rb +8 −3 Original line number Diff line number Diff line Loading @@ -124,14 +124,19 @@ module JsDuck @aliases.each do |al| orig = get_member(al[:alias][:cls], al[:alias][:owner]) al[:doc] = al[:doc] + "\n\n" + orig[:doc] al[:params] = orig[:params] al[:return] = orig[:return] al[:params] = orig[:params] if orig[:params] al[:return] = orig[:return] if orig[:return] end end def get_member(cls_name, member_name) cls = @classes[cls_name] return cls[:members][:method].find {|m| m[:name] == member_name } [:members, :statics].each do |group| cls[group].each_value do |members| match = members.find {|m| m[:name] == member_name } return match if match end end end # Creates class with name "global" and inserts all the remaining Loading spec/aggregator_alias_spec.rb +107 −16 Original line number Diff line number Diff line Loading @@ -10,7 +10,21 @@ describe JsDuck::Aggregator do agr.result end describe "@alias in doc-comment" do shared_examples_for "@alias" do it "original method keeps its name" do @orig[:name].should == "bar" end it "alias keeps its name" do @alias[:name].should == "foobar" end it "alias merges comment from original and its own comment" do @alias[:doc].should == "Alias comment.\n\nOriginal comment." end end describe "@alias of method" do before do @docs = parse(<<-EOF) /** @class Foo */ Loading @@ -33,27 +47,104 @@ describe JsDuck::Aggregator do @alias = @docs[1][:members][:method][0] end it "original method keeps its name" do @orig[:name].should == "bar" it_behaves_like "@alias" it "alias inherits parameters" do @alias[:params].length.should == 2 end describe "alias" do it "keeps its name" do @alias[:name].should == "foobar" it "alias inherits return value" do @alias[:return][:type].should == "String" end end describe "@alias of event" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @event bar * Original comment. * @param arg1 * @param arg2 */ /** @class Core */ /** * @event foobar * Alias comment. * @alias Foo#bar */ EOF @orig = @docs[0][:members][:event][0] @alias = @docs[1][:members][:event][0] end it "inherits parameters" do it_behaves_like "@alias" it "alias inherits parameters" do @alias[:params].length.should == 2 end it "inherits return value" do @alias[:return][:type].should == "String" it "alias doesn't get return value" do @alias[:return].should == nil end end it "merges comment from original and its own comment" do @alias[:doc].should == "Alias comment.\n\nOriginal comment." describe "@alias of cfg" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @cfg bar * Original comment. */ /** @class Core */ /** * @cfg foobar * Alias comment. * @alias Foo#bar */ EOF @orig = @docs[0][:members][:cfg][0] @alias = @docs[1][:members][:cfg][0] end it_behaves_like "@alias" it "alias doesn't get parameters" do @alias[:params].should == nil end it "alias doesn't get return value" do @alias[:return].should == nil end end describe "@alias of static method" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @method bar * Original comment. * @static */ /** @class Core */ /** * @method foobar * Alias comment. * @alias Foo#bar * @static */ EOF @orig = @docs[0][:statics][:method][0] @alias = @docs[1][:statics][:method][0] end it_behaves_like "@alias" end end Loading Loading
lib/jsduck/aggregator.rb +8 −3 Original line number Diff line number Diff line Loading @@ -124,14 +124,19 @@ module JsDuck @aliases.each do |al| orig = get_member(al[:alias][:cls], al[:alias][:owner]) al[:doc] = al[:doc] + "\n\n" + orig[:doc] al[:params] = orig[:params] al[:return] = orig[:return] al[:params] = orig[:params] if orig[:params] al[:return] = orig[:return] if orig[:return] end end def get_member(cls_name, member_name) cls = @classes[cls_name] return cls[:members][:method].find {|m| m[:name] == member_name } [:members, :statics].each do |group| cls[group].each_value do |members| match = members.find {|m| m[:name] == member_name } return match if match end end end # Creates class with name "global" and inserts all the remaining Loading
spec/aggregator_alias_spec.rb +107 −16 Original line number Diff line number Diff line Loading @@ -10,7 +10,21 @@ describe JsDuck::Aggregator do agr.result end describe "@alias in doc-comment" do shared_examples_for "@alias" do it "original method keeps its name" do @orig[:name].should == "bar" end it "alias keeps its name" do @alias[:name].should == "foobar" end it "alias merges comment from original and its own comment" do @alias[:doc].should == "Alias comment.\n\nOriginal comment." end end describe "@alias of method" do before do @docs = parse(<<-EOF) /** @class Foo */ Loading @@ -33,27 +47,104 @@ describe JsDuck::Aggregator do @alias = @docs[1][:members][:method][0] end it "original method keeps its name" do @orig[:name].should == "bar" it_behaves_like "@alias" it "alias inherits parameters" do @alias[:params].length.should == 2 end describe "alias" do it "keeps its name" do @alias[:name].should == "foobar" it "alias inherits return value" do @alias[:return][:type].should == "String" end end describe "@alias of event" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @event bar * Original comment. * @param arg1 * @param arg2 */ /** @class Core */ /** * @event foobar * Alias comment. * @alias Foo#bar */ EOF @orig = @docs[0][:members][:event][0] @alias = @docs[1][:members][:event][0] end it "inherits parameters" do it_behaves_like "@alias" it "alias inherits parameters" do @alias[:params].length.should == 2 end it "inherits return value" do @alias[:return][:type].should == "String" it "alias doesn't get return value" do @alias[:return].should == nil end end it "merges comment from original and its own comment" do @alias[:doc].should == "Alias comment.\n\nOriginal comment." describe "@alias of cfg" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @cfg bar * Original comment. */ /** @class Core */ /** * @cfg foobar * Alias comment. * @alias Foo#bar */ EOF @orig = @docs[0][:members][:cfg][0] @alias = @docs[1][:members][:cfg][0] end it_behaves_like "@alias" it "alias doesn't get parameters" do @alias[:params].should == nil end it "alias doesn't get return value" do @alias[:return].should == nil end end describe "@alias of static method" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @method bar * Original comment. * @static */ /** @class Core */ /** * @method foobar * Alias comment. * @alias Foo#bar * @static */ EOF @orig = @docs[0][:statics][:method][0] @alias = @docs[1][:statics][:method][0] end it_behaves_like "@alias" end end Loading