Loading lib/jsduck/merger.rb +12 −6 Original line number Diff line number Diff line Loading @@ -339,16 +339,22 @@ module JsDuck end def combine_properties(raw_items) # build name-index of all items index = {} raw_items.each {|it| index[it[:name]] = it } # If item name has no dots, add it directly to items array. # Otherwise look up the parent of item and add it as the # property of that parent. items = [] previous = {} raw_items.each do |it| if it[:name] =~ /\.(.*)$/ it[:name] = $1 previous[:properties] = [] unless previous[:properties] previous[:properties] << it if it[:name] =~ /^(.+)\.([^.]+)$/ it[:name] = $2 parent = index[$1] parent[:properties] = [] unless parent[:properties] parent[:properties] << it else items << it previous = it end end items Loading spec/aggregator_object_properties_spec.rb +20 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ describe JsDuck::Aggregator do /** * Some function * @param {Object} coord Geographical coordinates * @param {Number} coord.lat Latitude * @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) {} Loading Loading @@ -57,12 +59,28 @@ describe JsDuck::Aggregator do end it "has type" do @prop[:type].should == "Number" @prop[:type].should == "Object" end it "has doc" do @prop[:doc].should == "Latitude" end it "contains 2 subproperties" do @prop[:properties].length.should == 2 end describe "first subproperty" do it "has name without namespace" do @prop[:properties][0][:name].should == "numerator" end end describe "second subproperty" do it "has name without namespace" do @prop[:properties][1][:name].should == "denominator" end end end describe "second property" do Loading Loading
lib/jsduck/merger.rb +12 −6 Original line number Diff line number Diff line Loading @@ -339,16 +339,22 @@ module JsDuck end def combine_properties(raw_items) # build name-index of all items index = {} raw_items.each {|it| index[it[:name]] = it } # If item name has no dots, add it directly to items array. # Otherwise look up the parent of item and add it as the # property of that parent. items = [] previous = {} raw_items.each do |it| if it[:name] =~ /\.(.*)$/ it[:name] = $1 previous[:properties] = [] unless previous[:properties] previous[:properties] << it if it[:name] =~ /^(.+)\.([^.]+)$/ it[:name] = $2 parent = index[$1] parent[:properties] = [] unless parent[:properties] parent[:properties] << it else items << it previous = it end end items Loading
spec/aggregator_object_properties_spec.rb +20 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ describe JsDuck::Aggregator do /** * Some function * @param {Object} coord Geographical coordinates * @param {Number} coord.lat Latitude * @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) {} Loading Loading @@ -57,12 +59,28 @@ describe JsDuck::Aggregator do end it "has type" do @prop[:type].should == "Number" @prop[:type].should == "Object" end it "has doc" do @prop[:doc].should == "Latitude" end it "contains 2 subproperties" do @prop[:properties].length.should == 2 end describe "first subproperty" do it "has name without namespace" do @prop[:properties][0][:name].should == "numerator" end end describe "second subproperty" do it "has name without namespace" do @prop[:properties][1][:name].should == "denominator" end end end describe "second property" do Loading