Commit 67f5aae5 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for (required) syntax.

Config options are optional by default, except when labeled with
"(required)".
parent f98b1955
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ module JsDuck
      add_tag(:cfg)
      maybe_type
      maybe_name_with_default
      maybe_optional
      maybe_required
      skip_white
    end

@@ -376,6 +376,15 @@ module JsDuck
      end
    end

    # matches: "(required)"
    def maybe_required
      skip_horiz_white
      if look(/\(required\)/i)
        match(/\(required\)/i)
        @current_tag[:optional] = false
      end
    end

    # matches identifier name if possible and sets it on @current_tag
    def maybe_name
      skip_horiz_white
+6 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ module JsDuck
        :owner => detect_owner(doc_map) || owner,
        :type => detect_type(:cfg, doc_map, code),
        :doc => detect_doc(docs),
        :optional => detect_optional(:cfg, doc_map),
        :default => detect_default(:cfg, doc_map, code),
        :properties => detect_subproperties(docs, :cfg),
      }, doc_map)
@@ -281,6 +282,11 @@ module JsDuck
      end
    end

    def detect_optional(tagname, doc_map)
      main_tag = doc_map[tagname] ? doc_map[tagname].first : {}
      return main_tag[:optional] != false
    end

    # for detecting mixins and alternateClassNames
    def detect_list(type, doc_map, code)
      if doc_map[type]
+26 −0
Original line number Diff line number Diff line
@@ -304,4 +304,30 @@ describe JsDuck::Aggregator do
    end
  end

  describe "a normal config option" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg foo Something
         */
      EOS
    end
    it "is optional by default" do
      @doc[:optional].should == true
    end
  end

  describe "a config option labeled as required" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg foo (required) Something
         */
      EOS
    end
    it "has optional flag set to false" do
      @doc[:optional].should == false
    end
  end

end