Commit 04b73c33 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for @return with object properties.

parent 9e602ce3
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -193,12 +193,18 @@ module JsDuck
      skip_white
    end

    # matches @return {type} ...
    # matches @return {type} [ return.name ] ...
    def at_return
      match(/@returns?/)
      add_tag(:return)
      maybe_type
      skip_white
      if look(/return\.\w/)
        @current_tag[:name] = ident_chain
      else
        @current_tag[:name] = "return"
      end
      skip_white
    end

    # matches @cfg {type} name ...
+2 −0
Original line number Diff line number Diff line
@@ -371,7 +371,9 @@ module JsDuck
      ret = doc_map[:return] ? doc_map[:return].first : {}
      return {
        :type => ret[:type] || default_type,
        :name => ret[:name] || "return",
        :doc => ret[:doc] || "",
        :properties => doc_map[:return] ? detect_subproperties(doc_map[:return], :return) : []
      }
    end

+25 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ describe JsDuck::Aggregator do

  shared_examples_for "object with properties" do
    it "has name" do
      @obj[:name].should == "coord"
      @obj[:name].should == @name
    end

    it "has type" do
@@ -101,6 +101,7 @@ describe JsDuck::Aggregator do
    describe "single param" do
      before do
        @obj = @doc[:params][0]
        @name = "coord"
      end

      it_should_behave_like "object with properties"
@@ -130,6 +131,7 @@ describe JsDuck::Aggregator do
    describe "single param" do
      before do
        @obj = @doc[:params][0]
        @name = "coord"
      end

      it_should_behave_like "object with properties"
@@ -156,6 +158,7 @@ describe JsDuck::Aggregator do
    describe "the config" do
      before do
        @obj = @doc[0]
        @name = "coord"
      end

      it_should_behave_like "object with properties"
@@ -182,9 +185,30 @@ describe JsDuck::Aggregator do
    describe "the property" do
      before do
        @obj = @doc[0]
        @name = "coord"
      end

      it_should_behave_like "object with properties"
    end
  end

  describe "method return value with properties" do
    before do
      @obj = parse(<<-EOS)[0][:return]
        /**
         * Some function
         * @return {Object} Geographical coordinates
         * @return {Object} return.lat Latitude
         * @return {Number} return.lat.numerator Numerator part of a fraction
         * @return {Number} return.lat.denominator Denominator part of a fraction
         * @return {Number} return.lng Longitude
         */
        function foo() {}
      EOS
      @name = "return"
    end

    it_should_behave_like "object with properties"
  end

end
+7 −1
Original line number Diff line number Diff line
@@ -474,9 +474,15 @@ Ext.define('Docs.view.cls.Overview', {
                    '<span class="pre">{type}</span>',
                    '<div class="sub-desc">',
                        '{doc}',
                        '<tpl if="properties && properties.length">',
                            '{[this.renderParamsAndReturn(values)]}',
                        '</tpl>',
                    '</div>',
                '</li>',
            '</ul>'
            '</ul>',
            {
                renderParamsAndReturn: Ext.Function.bind(this.renderParamsAndReturn, this)
            }
        );

        return this.returnTpl.apply(returnDoc);