Commit 3645ceb8 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for @ignore and @hide.

parent 15116570
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -55,8 +55,6 @@ module JsDuck
          at_extends
        elsif look(/@singleton\b/) then
          at_singleton
        elsif look(/@private\b/) then
          at_private
        elsif look(/@event\b/) then
          at_event
        elsif look(/@method\b/) then
@@ -73,6 +71,12 @@ module JsDuck
          at_property
        elsif look(/@type\b/) then
          at_type
        elsif look(/@private\b/) then
          match_boolean_at_tag(/@private/, :private)
        elsif look(/@ignore\b/) then
          match_boolean_at_tag(/@ignore/, :ignore)
        elsif look(/@hide\b/) then
          match_boolean_at_tag(/@hide/, :hide)
        elsif look(/@/) then
          @current_tag[:doc] += @input.scan(/@/)
        elsif look(/[^@]/) then
@@ -130,13 +134,13 @@ module JsDuck
      skip_white
    end

    # matches @private
    # sets :private property to true on the root tag
    def at_private
      match(/@private/)
    # matches @ignore
    # sets :ignore property to true on the root tag
    def at_ignore
      match(/@ignore/)
      tagname = [:class, :method, :event, :property, :default].find {|name| @tags[name]}
      if tagname
        @tags[tagname][:private] = true
        @tags[tagname][:ignore] = true
      end
      skip_white
    end
@@ -229,6 +233,17 @@ module JsDuck
      skip_white
    end

    # Used to match @private, @ignore, @hide
    # and set the corresponding property true on root tag
    def match_boolean_at_tag(regex, propname)
      match(regex)
      tagname = [:class, :method, :event, :property, :default].find {|name| @tags[name]}
      if tagname
        @tags[tagname][propname] = true
      end
      skip_white
    end

    # matches {type} if possible and sets it on @current_tag
    def maybe_type
      skip_horiz_white
+28 −12
Original line number Diff line number Diff line
@@ -59,12 +59,10 @@ class TestDocCommentParser < Test::Unit::TestCase
 * @class my.package.Foo
 * @extends my.Bar
 * Some docs.
 * @singleton
 */")
    assert_equal("my.package.Foo", doc[:class][:name])
    assert_equal("my.Bar", doc[:class][:extends])
    assert_equal("Some docs.", doc[:class][:doc])
    assert_equal(true, doc[:class][:singleton])
  end

  def test_extends_implies_class
@@ -230,50 +228,68 @@ class TestDocCommentParser < Test::Unit::TestCase
    assert_equal("My parameter.", doc[:param][0][:doc])
  end

  def test_private_class
  def test_class_modifiers
    doc = parse_single("/**
 * @class Foo
 * Blah blah
 * @singleton
 * @private
 * @ignore
 * @hide
 */")
    assert(doc[:class][:private])
    assert(doc[:class][:singleton])
    assert_modifiers(doc[:class])
  end

  def test_private_method
  def test_method_modifiers
    doc = parse_single("/**
 * @method foo
 * Some method
 * @param {type} x
 * @private
 * @ignore
 * @hide
 */")
    assert(doc[:method][:private])
    assert_modifiers(doc[:method])
  end

  def test_private_event
  def test_event_modifiers
    doc = parse_single("/**
 * @event foo
 * Some prop
 * @param {type} x
 * @private
 * @ignore
 * @hide
 */")
    assert(doc[:event][:private])
    assert_modifiers(doc[:event])
  end

  def test_private_property
  def test_property_modifiers
    doc = parse_single("/**
 * @property foo
 * Some prop
 * @private
 * @ignore
 * @hide
 */")
    assert(doc[:property][:private])
    assert_modifiers(doc[:property])
  end

  def test_private_default
  def test_default_modifiers
    doc = parse_single("/**
 * Some docs
 * @private
 * @ignore
 * @hide
 */")
    assert(doc[:default][:private])
    assert_modifiers(doc[:default])
  end

  def assert_modifiers(tag)
    assert(tag[:private])
    assert(tag[:ignore])
    assert(tag[:hide])
  end

end