Commit 1561182c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Make @ignore completely hide class or member.

When used on a member, it's treated as if the doc-comment wasn't even
there.

When used on a class, all its members will be ignored too.

This makes it a useful tool to easily exclude a class or a member from docs.
parent e77295d6
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ module JsDuck
    # Items without @member belong by default to the preceding class.
    # When no class precedes them - they too are orphaned.
    def add_member(node)
      # Completely ignore member if @ignore used
      return if node[:meta][:ignore]

      if node[:owner]
        if @classes[node[:owner]]
          add_to_class(@classes[node[:owner]], node)
@@ -191,6 +194,16 @@ module JsDuck
      })
    end

    # Gets rid of classes marked with @ignore
    def remove_ignored_classes
      @documentation.delete_if do |cls|
        if cls[:meta][:ignore]
          @classes.delete(cls["name"])
          true
        end
      end
    end

    # Appends Ext4 options parameter to each event parameter list.
    # But only when we are dealing with Ext4 codebase.
    def append_ext4_event_options
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ module JsDuck
      end
      agr.classify_orphans
      agr.create_global_class
      agr.remove_ignored_classes
      agr.create_accessors
      agr.append_ext4_event_options
      agr.result
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ module JsDuck::Tag
  class Ignore < JsDuck::MetaTag
    def initialize
      @name = "ignore"
      @key = :private
      @key = :ignore
      @boolean = true
    end
  end
+57 −8
Original line number Diff line number Diff line
@@ -6,12 +6,13 @@ describe JsDuck::Aggregator do
  def parse(string)
    agr = JsDuck::Aggregator.new
    agr.aggregate(JsDuck::SourceFile.new(string))
    agr.remove_ignored_classes
    agr.result
  end

  shared_examples_for "private" do
  describe "@private" do
    before do
      @doc = parse("/**\n * #{@tagname}\n */")[0]
      @doc = parse("/** @private */")[0]
    end

    it "marks item as private" do
@@ -23,14 +24,62 @@ describe JsDuck::Aggregator do
    end
  end

  describe "@private" do
    before { @tagname = "@private" }
    it_should_behave_like "private"
  describe "@ignore in member" do
    before do
      @docs = parse("/** @ignore */")
    end

    it "ignores the member completely" do
      @docs.length.should == 0
    end
  end

  describe "@ignore in class" do
    before do
      @docs = parse(<<-EOSTR)
      /**
       * @class Foo
       * @ignore
       */
          /**
           * @method bar
           */
          /**
           * @method baz
           */
      EOSTR
    end

  describe "@ignore" do
    before { @tagname = "@ignore" }
    it_should_behave_like "private"
    it "ignores the class and all it's members" do
      @docs.length.should == 0
    end
  end

  describe "@ignore in duplicate member" do
    before do
      @doc = parse(<<-EOSTR)[0]
      /**
       * @class Foo
       */
          /**
           * @method bar
           * First method docs
           */
          /**
           * @method bar
           * Second method docs
           * @ignore
           */
      EOSTR
    end

    it "ignores one member" do
      @doc[:members][:method].length.should == 1
    end

    it "lets the other member stay" do
      @doc[:members][:method][0][:doc].should == "First method docs"
    end
  end

  describe "@hide" do