Loading lib/jsduck/doc_parser.rb +1 −2 Original line number Diff line number Diff line Loading @@ -189,7 +189,6 @@ module JsDuck match(/@param/) add_tag(:param) maybe_type #maybe_name maybe_ident_chain(:name) skip_white end Loading @@ -207,7 +206,7 @@ module JsDuck match(/@cfg/) add_tag(:cfg) maybe_type maybe_name maybe_ident_chain(:name) skip_white end Loading lib/jsduck/merger.rb +11 −2 Original line number Diff line number Diff line Loading @@ -164,6 +164,7 @@ module JsDuck :owner => detect_owner(doc_map) || owner, :type => detect_type(:cfg, doc_map, code), :doc => detect_doc(docs), :properties => detect_subproperties(docs), }, doc_map) end Loading Loading @@ -338,6 +339,10 @@ module JsDuck combine_properties(docs.find_all {|tag| tag[:tagname] == :param}) end def detect_subproperties(docs) combine_properties(docs.find_all {|tag| tag[:tagname] == :cfg})[0][:properties] end def combine_properties(raw_items) # build name-index of all items index = {} Loading Loading @@ -369,13 +374,17 @@ module JsDuck end # Combines :doc-s of most tags # Ignores tags that have doc comment themselves # Ignores tags that have doc comment themselves and subproperty tags def detect_doc(docs) ignore_tags = [:param, :return] doc_tags = docs.find_all { |tag| !ignore_tags.include?(tag[:tagname]) } doc_tags = docs.find_all { |tag| !ignore_tags.include?(tag[:tagname]) && !subproperty?(tag) } doc_tags.map { |tag| tag[:doc] }.compact.join(" ") end def subproperty?(tag) tag[:tagname] == :cfg && tag[:name] =~ /\./ end # Build map of at-tags for quick lookup def build_doc_map(docs) map = {} Loading spec/aggregator_object_properties_spec.rb +89 −60 Original line number Diff line number Diff line Loading @@ -9,49 +9,26 @@ describe JsDuck::Aggregator do agr.result end describe "method parameter with properties" do before do @doc = parse(<<-EOS)[0] /** * Some function * @param {Object} coord Geographical coordinates * @param {Object} coord.lat Latitude * @param {Number} coord.lat.numerator Numerator part of a fraction * @param {Number} coord.lat.denominator Denominator part of a fraction * @param {Number} coord.lng Longitude */ function foo(x, y) {} EOS end it "is interpreted as single parameter" do @doc[:params].length.should == 1 end describe "single param" do before do @param = @doc[:params][0] end shared_examples_for "object with properties" do it "has name" do @param[:name].should == "coord" @obj[:name].should == "coord" end it "has type" do @param[:type].should == "Object" @obj[:type].should == "Object" end it "has doc" do @param[:doc].should == "Geographical coordinates" @obj[:doc].should == "Geographical coordinates" end it "contains 2 properties" do @param[:properties].length.should == 2 @obj[:properties].length.should == 2 end describe "first property" do before do @prop = @param[:properties][0] @prop = @obj[:properties][0] end it "has name without namespace" do Loading Loading @@ -85,7 +62,7 @@ describe JsDuck::Aggregator do describe "second property" do before do @prop = @param[:properties][1] @prop = @obj[:properties][1] end it "has name without namespace" do Loading @@ -101,6 +78,58 @@ describe JsDuck::Aggregator do end end end describe "method parameter with properties" do before do @doc = parse(<<-EOS)[0] /** * Some function * @param {Object} coord Geographical coordinates * @param {Object} coord.lat Latitude * @param {Number} coord.lat.numerator Numerator part of a fraction * @param {Number} coord.lat.denominator Denominator part of a fraction * @param {Number} coord.lng Longitude */ function foo(x, y) {} EOS end it "is interpreted as single parameter" do @doc[:params].length.should == 1 end describe "single param" do before do @obj = @doc[:params][0] end it_should_behave_like "object with properties" end end describe "cfg with properties" do before do @doc = parse(<<-EOS) /** * @cfg {Object} coord Geographical coordinates * @cfg {Object} coord.lat Latitude * @cfg {Number} coord.lat.numerator Numerator part of a fraction * @cfg {Number} coord.lat.denominator Denominator part of a fraction * @cfg {Number} coord.lng Longitude */ EOS end it "is interpreted as single config" do @doc.length.should == 1 end describe "the config" do before do @obj = @doc[0] end it_should_behave_like "object with properties" end end end Loading
lib/jsduck/doc_parser.rb +1 −2 Original line number Diff line number Diff line Loading @@ -189,7 +189,6 @@ module JsDuck match(/@param/) add_tag(:param) maybe_type #maybe_name maybe_ident_chain(:name) skip_white end Loading @@ -207,7 +206,7 @@ module JsDuck match(/@cfg/) add_tag(:cfg) maybe_type maybe_name maybe_ident_chain(:name) skip_white end Loading
lib/jsduck/merger.rb +11 −2 Original line number Diff line number Diff line Loading @@ -164,6 +164,7 @@ module JsDuck :owner => detect_owner(doc_map) || owner, :type => detect_type(:cfg, doc_map, code), :doc => detect_doc(docs), :properties => detect_subproperties(docs), }, doc_map) end Loading Loading @@ -338,6 +339,10 @@ module JsDuck combine_properties(docs.find_all {|tag| tag[:tagname] == :param}) end def detect_subproperties(docs) combine_properties(docs.find_all {|tag| tag[:tagname] == :cfg})[0][:properties] end def combine_properties(raw_items) # build name-index of all items index = {} Loading Loading @@ -369,13 +374,17 @@ module JsDuck end # Combines :doc-s of most tags # Ignores tags that have doc comment themselves # Ignores tags that have doc comment themselves and subproperty tags def detect_doc(docs) ignore_tags = [:param, :return] doc_tags = docs.find_all { |tag| !ignore_tags.include?(tag[:tagname]) } doc_tags = docs.find_all { |tag| !ignore_tags.include?(tag[:tagname]) && !subproperty?(tag) } doc_tags.map { |tag| tag[:doc] }.compact.join(" ") end def subproperty?(tag) tag[:tagname] == :cfg && tag[:name] =~ /\./ end # Build map of at-tags for quick lookup def build_doc_map(docs) map = {} Loading
spec/aggregator_object_properties_spec.rb +89 −60 Original line number Diff line number Diff line Loading @@ -9,49 +9,26 @@ describe JsDuck::Aggregator do agr.result end describe "method parameter with properties" do before do @doc = parse(<<-EOS)[0] /** * Some function * @param {Object} coord Geographical coordinates * @param {Object} coord.lat Latitude * @param {Number} coord.lat.numerator Numerator part of a fraction * @param {Number} coord.lat.denominator Denominator part of a fraction * @param {Number} coord.lng Longitude */ function foo(x, y) {} EOS end it "is interpreted as single parameter" do @doc[:params].length.should == 1 end describe "single param" do before do @param = @doc[:params][0] end shared_examples_for "object with properties" do it "has name" do @param[:name].should == "coord" @obj[:name].should == "coord" end it "has type" do @param[:type].should == "Object" @obj[:type].should == "Object" end it "has doc" do @param[:doc].should == "Geographical coordinates" @obj[:doc].should == "Geographical coordinates" end it "contains 2 properties" do @param[:properties].length.should == 2 @obj[:properties].length.should == 2 end describe "first property" do before do @prop = @param[:properties][0] @prop = @obj[:properties][0] end it "has name without namespace" do Loading Loading @@ -85,7 +62,7 @@ describe JsDuck::Aggregator do describe "second property" do before do @prop = @param[:properties][1] @prop = @obj[:properties][1] end it "has name without namespace" do Loading @@ -101,6 +78,58 @@ describe JsDuck::Aggregator do end end end describe "method parameter with properties" do before do @doc = parse(<<-EOS)[0] /** * Some function * @param {Object} coord Geographical coordinates * @param {Object} coord.lat Latitude * @param {Number} coord.lat.numerator Numerator part of a fraction * @param {Number} coord.lat.denominator Denominator part of a fraction * @param {Number} coord.lng Longitude */ function foo(x, y) {} EOS end it "is interpreted as single parameter" do @doc[:params].length.should == 1 end describe "single param" do before do @obj = @doc[:params][0] end it_should_behave_like "object with properties" end end describe "cfg with properties" do before do @doc = parse(<<-EOS) /** * @cfg {Object} coord Geographical coordinates * @cfg {Object} coord.lat Latitude * @cfg {Number} coord.lat.numerator Numerator part of a fraction * @cfg {Number} coord.lat.denominator Denominator part of a fraction * @cfg {Number} coord.lng Longitude */ EOS end it "is interpreted as single config" do @doc.length.should == 1 end describe "the config" do before do @obj = @doc[0] end it_should_behave_like "object with properties" end end end