Commit c701d753 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Refactor 'required' of config into attributes hash.

The required attribute is detected in a different way than other
things inside attributes hash, but it fits there nicely.
parent e22c488e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ module JsDuck

    def compact_member(m)
      m_copy = {}
      [:name, :tagname, :owner, :static, :deprecated, :required, :attributes, :id].each do |key|
      [:name, :tagname, :owner, :static, :deprecated, :attributes, :id].each do |key|
        m_copy[key] = m[key]
      end
      m_copy
+5 −6
Original line number Diff line number Diff line
@@ -175,7 +175,6 @@ module JsDuck
        :owner => detect_owner(doc_map) || owner,
        :type => detect_type(:cfg, doc_map, code),
        :doc => detect_doc(docs),
        :required => detect_required(:cfg, doc_map),
        :default => detect_default(:cfg, doc_map, code),
        :properties => detect_subproperties(docs, :cfg),
        :accessor => !!doc_map[:accessor],
@@ -313,11 +312,6 @@ module JsDuck
      return explicit_name == "" || explicit_name == implicit_name
    end

    def detect_required(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]
@@ -382,9 +376,14 @@ module JsDuck
      (doc_map[:attribute] || []).each do |tag|
        attributes[tag[:name]] = true
      end
      attributes[:required] = true if detect_required(doc_map)
      attributes
    end

    def detect_required(doc_map)
      doc_map[:cfg] && doc_map[:cfg].first[:optional] == false
    end

    def detect_params(docs, code)
      implicit = detect_implicit_params(code)
      explicit = detect_explicit_params(docs)
+1 −1
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ module JsDuck
      if m[:deprecated]
        after += "<strong class='deprecated signature'>deprecated</strong>"
      end
      if m[:required]
      if m[:attributes][:required]
        after += "<strong class='required signature'>required</strong>"
      end
      if m[:attributes][:template]
+43 −1
Original line number Diff line number Diff line
@@ -54,8 +54,50 @@ 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 not required by default" do
      @doc[:attributes][:required].should_not == 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 required flag set to true" do
      @doc[:attributes][:required].should == true
    end
  end

  describe "a class with @cfg (required)" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @class MyClass
         * @cfg foo (required)
         */
      EOS
    end
    it "doesn't become a required class" do
      @doc[:attributes][:required].should_not == true
    end
    it "contains required config" do
      @doc[:members][:cfg][0][:attributes][:required].should == true
    end
  end

  # @static
  # @deprecated
  # (required)

end
+0 −26
Original line number Diff line number Diff line
@@ -393,30 +393,4 @@ 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 not required by default" do
      @doc[:required].should == false
    end
  end

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

end
Loading