Commit 3a983832 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implemented @mixins tag.

When @mixins tag present, it will override all the implied mixins
possibly detected from code.  One can either use just one @mixins:

    @mixins Foo Bar Baz

Or several:

    @mixins Foo
    @mixins Bar
    @mixins Baz

The result will be the same.
parent a8ca78a6
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ module JsDuck
          at_class
        elsif look(/@extends?\b/)
          at_extends
        elsif look(/@mixins?\b/)
          at_mixins
        elsif look(/@singleton\b/)
          boolean_at_tag(/@singleton/, :singleton)
        elsif look(/@event\b/)
@@ -132,6 +134,20 @@ module JsDuck
      skip_white
    end

    # matches @mixins name1 name2 ...
    def at_mixins
      match(/@mixins?/)
      add_tag(:mixins)
      skip_horiz_white
      mixins = []
      while look(/\w/)
        mixins << ident_chain
        skip_horiz_white
      end
      @current_tag[:mixins] = mixins
      skip_white
    end

    # matches @event name ...
    def at_event
      match(/@event/)
+3 −1
Original line number Diff line number Diff line
@@ -263,7 +263,9 @@ module JsDuck
    end

    def detect_mixins(doc_map, code)
      if code[:type] == :ext_define && code[:mixins]
      if doc_map[:mixins]
        doc_map[:mixins].map {|d| d[:mixins] }.flatten
      elsif code[:type] == :ext_define && code[:mixins]
        code[:mixins]
      else
        []
+28 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ describe JsDuck::Aggregator do
        /**
         * @class MyClass
         * @extends Your.Class
         * @mixins Foo.Mixin Bar.Mixin
         * Some documentation.
         * @singleton
         * @xtype nicely
@@ -35,6 +36,9 @@ describe JsDuck::Aggregator do
    it "detects extends" do
      @doc[:extends].should == "Your.Class"
    end
    it "detects mixins" do
      @doc[:mixins].should == ["Foo.Mixin", "Bar.Mixin"]
    end
    it "takes documentation from doc-comment" do
      @doc[:doc].should == "Some documentation."
    end
@@ -46,21 +50,43 @@ describe JsDuck::Aggregator do
    end
  end

  describe "class with @extend" do
  describe "class @tag aliases" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @class MyClass
         * @extend Your.Class
         * @mixin My.Mixin
         * Some documentation.
         */
      EOS
    end

    it_should_behave_like "class"
    it "treated as alias for @extends" do
    it "@extend treated as alias for @extends" do
      @doc[:extends].should == "Your.Class"
    end
    it "@mixin treated as alias for @mixins" do
      @doc[:mixins].should == ["My.Mixin"]
    end
  end

  describe "class with multiple @mixins" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @class MyClass
         * @mixins My.Mixin
         * @mixins Your.Mixin Other.Mixin
         * Some documentation.
         */
      EOS
    end

    it_should_behave_like "class"
    it "collects all mixins together" do
      @doc[:mixins].should == ["My.Mixin", "Your.Mixin", "Other.Mixin"]
    end
  end

  describe "function after doc-comment" do