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

Support for ptype and ftype in addition to xtype.

The xtypes property now basically reflects the alias property in
Ext.define class definition. It's a hash with structure like:

    xtype: {
        widget: ["text", "textfield"],
        feature: ["blah"]
    }

When rendering the class header "widget" is mapped to "xtype",
"feature" to "ftype", "plugin" to "ptype".

Explicit @xtype foo is converted to xtypes: {widget: ["foo"]}

The choice of names is currently misfortunate.  It would be logical
to use "alias", but we already have @alias which does a completely
different thing.  This issue has been disturbing us for long, but
now it really starts to hurt.  I feel we have to reclame @alias
from its current occupating and use some other tag like @include
to replace @alias.
parent 09f34bc2
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -50,12 +50,15 @@ module JsDuck

    # Merges new class-doc into old one.
    def merge_classes(old, new)
      [:extends, :xtype, :singleton, :private, :protected].each do |tag|
      [:extends, :singleton, :private, :protected].each do |tag|
        old[tag] = old[tag] || new[tag]
      end
      [:mixins, :alternateClassNames, :xtypes].each do |tag|
      [:mixins, :alternateClassNames].each do |tag|
        old[tag] = old[tag] + new[tag]
      end
      new[:xtypes].each_pair do |key, xtypes|
        old[:xtypes][key] = (old[:xtypes][key] || []) + xtypes
      end
      old[:doc] = old[:doc].length > 0 ? old[:doc] : new[:doc]
      # Additionally the doc-comment can contain configs and constructor
      old[:members][:cfg] += new[:members][:cfg]
+13 −3
Original line number Diff line number Diff line
@@ -310,11 +310,21 @@ module JsDuck

    def detect_xtypes(doc_map, code)
      if doc_map[:xtype]
        doc_map[:xtype].map {|tag| tag[:name] }
        {"widget" => doc_map[:xtype].map {|tag| tag[:name] } }
      elsif code[:alias]
        code[:alias].find_all {|a| a =~ /^widget\./ }.map {|a| a.sub(/^widget\./, "") }
        xtypes = {}
        code[:alias].each do |a|
          if a =~ /^(\w+)\.(\w+)$/
            if xtypes[$1]
              xtypes[$1] << $2
            else
        []
              xtypes[$1] = [$2]
            end
          end
        end
        xtypes
      else
        {}
      end
    end

+6 −6
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ describe JsDuck::Aggregator do
      @doc[:singleton].should == true
    end
    it "detects xtype" do
      @doc[:xtypes].should == ["nicely"]
      @doc[:xtypes].should == {"widget" => ["nicely"]}
    end
  end

@@ -130,7 +130,7 @@ describe JsDuck::Aggregator do

    it_should_behave_like "class"
    it "collects all xtypes together" do
      @doc[:xtypes].should == ["foo", "bar"]
      @doc[:xtypes].should == {"widget" => ["foo", "bar"]}
    end
  end

@@ -197,7 +197,7 @@ describe JsDuck::Aggregator do
      @doc[:alternateClassNames].should == ["JustClass"]
    end
    it "detects implied xtype" do
      @doc[:xtypes].should == ["foo"]
      @doc[:xtypes].should == {"widget" => ["foo"]}
    end
    it "detects implied singleton" do
      @doc[:singleton].should == true
@@ -251,7 +251,7 @@ describe JsDuck::Aggregator do
          extend: 'Your.Class',
          uses: ['ClassC'],
          conf: {foo: 10},
          alias: ['widget.foo', 'something.bar'],
          alias: ['widget.foo'],
          singleton: true,
          alternateClassName: ['JustClass'],
          stuff: ["foo", "bar"],
@@ -349,7 +349,7 @@ describe JsDuck::Aggregator do

    it_should_behave_like "class"
    it "detects xtype" do
      @doc[:xtypes].should == ["nicely"]
      @doc[:xtypes].should == {"widget" => ["nicely"]}
    end
  end

@@ -528,7 +528,7 @@ describe JsDuck::Aggregator do
    end

    it "combines all @xtypes" do
      @classes[0][:xtypes].length.should == 2
      @classes[0][:xtypes]["widget"].length.should == 2
    end

    it "combines all configs" do
+15 −3
Original line number Diff line number Diff line
@@ -167,13 +167,13 @@ Ext.define('Docs.controller.Search', {
            // Otherwise search from just the member name (e.g. "focus" or "Component")
            var name = hasDot ? r.cls + (r.type === "cls" ? "" : "." + r.member) : r.member;

            if (r.xtypes && Ext.Array.some(r.xtypes, function(x) {return reFull.test(x);})) {
            if (r.xtypes && this.matchXType(r.xtypes, reFull)) {
                results[xFull].push(r);
            }
            else if (reFull.test(name)) {
                results[r.type === "cls" ? clsFull : mFull].push(r);
            }
            else if (r.xtypes && Ext.Array.some(r.xtypes, function(x) {return reBeg.test(x);})) {
            else if (r.xtypes && this.matchXType(r.xtypes, reBeg)) {
                results[xBeg].push(r);
            }
            else if (reBeg.test(name)) {
@@ -182,9 +182,21 @@ Ext.define('Docs.controller.Search', {
            else if (reMid.test(name)) {
                results[r.type === "cls" ? clsMid : mMid].push(r);
            }
        });
        }, this);

        return Ext.Array.flatten(results);
    },

    // true if xtype, ptype, ftype, etc matches regex
    matchXType: function(xtypes, regex) {
        for (var key in xtypes) {
            if (xtypes.hasOwnProperty(key)) {
                if (Ext.Array.some(xtypes[key], function(x) {return regex.test(x);})) {
                    return true;
                }
            }
        }
        return false;
    }

});
+21 −3
Original line number Diff line number Diff line
@@ -17,9 +17,7 @@ Ext.define('Docs.view.cls.Header', {
                    '<span class="private">Private</span>',
                '</tpl>',
                '<a href="source/{href}" target="_blank">{name}</a>',
                '<tpl if="xtypes.length &gt; 0">',
                    '<span>xtype: {[values.xtypes.join(", ")]}</span>',
                '</tpl>',
                '{[this.renderXTypes(values.xtypes)]}',
            '</h1>',
            '<a class="print" href="?print=/api/{name}" target="_blank">Print</a>',
            {
@@ -33,6 +31,26 @@ Ext.define('Docs.view.cls.Header', {
                    else {
                        return "class";
                    }
                },
                renderXTypes: function(xtypes) {
                    var map = {
                        widget: "xtype",
                        plugin: "ptype",
                        feature: "ftype"
                    };
                    var r = [];
                    Ext.Object.each(map, function(ns, title) {
                        if (xtypes[ns]) {
                            r.push(title + ": " + xtypes[ns].join(", "));
                        }
                    });

                    if (r.length > 0) {
                        return "<span>" + r.join(", ") + "</span>";
                    }
                    else {
                        return "";
                    }
                }
            }
        );