Commit 16291fb0 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Constructors named after class and sorted first.

Explained in README that unlike with ext-doc constructor documentation
inherited like documentation for any method.
parent 482b6a12
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -36,6 +36,11 @@ Basically JsDuck thinks that the following doc-comment really sucks:
     * <li><code>{@link Ext.form.TextField#stripCharsRe stripCharsRe}</code> :
     * filter characters after being typed in, but before being validated</li>
     * </ul></div>
     *
     * @constructor Creates a new TextField
     * @param {Object} config Configuration options
     *
     * @xtype textfield
     */
    Ext.form.TextField = Ext.extend(Ext.form.Field,  {

@@ -69,13 +74,17 @@ it would like that you wrote comments like that instead:
     *   filter out keystrokes before any validation occurs
     * - `{@link Ext.form.TextField#stripCharsRe stripCharsRe}` :
     *   filter characters after being typed in, but before being validated
     *
     * @xtype textfield
     */
    Ext.form.TextField = Ext.extend(Ext.form.Field,  {

As you can see, JsDuck supports formatting comments with friendly
[Markdown][] syntax.  And it can infer several things from the code
(like @class and @extends in this case), so you don't have to repeat
yourself.
yourself.  Also the constructor documentation is inherited from parent
class - so you don't have to restate that it takes a config object
again.

That's basically it.  Have fun.

@@ -121,7 +130,6 @@ currently missing:
* List of subclasses
* Tree of parent classes
* Syntax highlighting of code examples
* Constructor first in methods list
* Search, not just searching from official ExtJS documentation
* Support for custom @tags

+23 −2
Original line number Diff line number Diff line
@@ -25,9 +25,30 @@ module JsDuck
    end

    # Returns array of all public members of particular type in a class,
    # sorted by name.  See members_hash for details.
    # sorted by name.
    #
    # For methods the the constructor is listed as first method having
    # the same name as class itself.
    #
    # See members_hash for details.
    def members(type)
      members_hash(type).values.sort {|a,b| a[:name] <=> b[:name] }
      ms = members_hash(type).values.sort {|a,b| a[:name] <=> b[:name] }
      type == :method ? constructor_first(ms) : ms
    end

    # If methods list contains constructor, rename it with class name
    # and move into beginning of methods list.
    def constructor_first(ms)
      constr = ms.find {|m| m[:name] == "constructor" }
      if constr
        ms.delete(constr)
        # Clone it.  Otherwise the search for "constructor" from this
        # class will return nothing as we have renamed it.
        constr2 = constr.clone
        constr2[:name] = short_name
        ms.unshift(constr2)
      end
      ms
    end

    # Returns hash of public members of class (and parent classes).
+27 −0
Original line number Diff line number Diff line
@@ -43,6 +43,33 @@ describe JsDuck::Class do
    end
  end

  describe "#members(:method)" do
    before do
      @classes = {}
      @parent = JsDuck::Class.new({
          :name => "ParentClass",
          :method => [
            {:name => "baz", :member => "ParentClass"},
            {:name => "constructor", :member => "ParentClass"},
          ]
        }, @classes);
      @classes["ParentClass"] = @parent
      @child = JsDuck::Class.new({
          :name => "ChildClass",
          :extends => "ParentClass",
          :method => [
            {:name => "foo", :member => "ChildClass"}
          ]
        }, @classes);
      @classes["ChildClass"] = @child
    end

    it "returns constructor as first method" do
      ms = @child.members(:method)
      ms.first[:name].should == "ChildClass"
    end
  end

  describe "#inherits_from" do

    before do