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

Support for @cfg.

Plus some logic to set_default_name to prevent @cfg-s and @event-s
from becoming functions.
parent 22e80122
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ module JsDuck
      name = name_chain.last
      tagname = (name[0,1] == name[0,1].upcase) ? :class : :function

      if !@tags[:class] && !@tags[:function] then
      if !@tags[:class] && !@tags[:function] && !@tags[:event] && !@tags[:cfg] then
        @tags[tagname] = {:name => (tagname == :function) ? name : name_chain.join(".")}
        @tags[tagname][:doc] = @tags[:default][:doc]
      end
@@ -87,6 +87,8 @@ module JsDuck
          at_param
        elsif look(/@return\b/) then
          at_return
        elsif look(/@cfg\b/) then
          at_cfg
        elsif look(/@/) then
          @current_tag[:doc] += @input.scan(/@/)
        elsif look(/[^@]/) then
@@ -195,6 +197,21 @@ module JsDuck
      skip_white
    end

    # matches @cfg {type} name ...
    def at_cfg
      match(/@cfg/)
      @current_tag = @tags[:cfg] = {:doc => ""}
      skip_white
      if look(/\{/) then
        @current_tag[:type] = typedef
      end
      skip_white
      if look(/\w/) then
        @current_tag[:name] = ident
      end
      skip_white
    end

    # matches {...} and returns text inside brackets
    def typedef
      match(/\{/)
+10 −0
Original line number Diff line number Diff line
@@ -57,6 +57,16 @@ class TestDocComment < Test::Unit::TestCase
    assert_equal("Fires when the mouse button is depressed.", doc[:event][:doc])
  end

  def test_cfg
    doc = JsDuck::DocComment.new("/**
 * @cfg {Boolean} enabled
 * True to enable this.
 */")
    assert_equal("enabled", doc[:cfg][:name])
    assert_equal("Boolean", doc[:cfg][:type])
    assert_equal("True to enable this.", doc[:cfg][:doc])
  end

  def test_long_docs
    doc = JsDuck::DocComment.new("/**
 * @function foo