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

Different icons for Ext components.

Implemented Class.inherits_from? through which we check if
class inherits from Ext.Component (or if needed, from any other
class).

Unlike in ext-doc we mark the Ext.Component itself also with component
icon.  It always had bothered me that the base component itself was
not easily identifiable as component.
parent e669a72b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,12 @@ module JsDuck
      @doc[:extends] ? @classes[@doc[:extends]] : nil
    end

    # Returns true when this class inherits from the specified class.
    # Also returns true when the class itself is the one we are asking about.
    def inherits_from?(class_name)
      return full_name == class_name || (parent ? parent.inherits_from?(class_name) : false)
    end

    # Returns array of all members of particular type in a class,
    # sorted by name.  See members_hash for details.
    def members(type)
+11 −1
Original line number Diff line number Diff line
@@ -72,12 +72,22 @@ module JsDuck
        :text => cls.short_name,
        :id => cls.full_name,
        :isClass => true,
        :iconCls => cls[:singleton] ? "icon-static" : "icon-cls",
        :iconCls => class_icon(cls),
        :cls => "cls",
        :leaf => true
      }
    end

    def class_icon(cls)
      if cls[:singleton]
        "icon-static"
      elsif cls.inherits_from?("Ext.Component")
        "icon-cmp"
      else
        "icon-cls"
      end
    end

    # Given full package name like my.package creates package node
    def package_node(name)
      return {
+28 −0
Original line number Diff line number Diff line
@@ -45,5 +45,33 @@ class TestClass < Test::Unit::TestCase
    assert_equal("ParentClass", ms["baz"][:member], "baz is only in parent class")
  end

  def test_inherits_from
    classes = {}
    parent = JsDuck::Class.new({
      :name => "Parent",
    }, classes);
    classes["Parent"] = parent

    child = JsDuck::Class.new({
      :name => "Child",
      :extends => "Parent",
    }, classes);
    classes["Child"] = child

    grandchild = JsDuck::Class.new({
      :name => "GrandChild",
      :extends => "Child",
    }, classes);
    classes["GrandChild"] = grandchild

    assert_equal(true, parent.inherits_from?("Parent"), "Parent inherits from Parent")
    assert_equal(false, parent.inherits_from?("Child"), "Parent does not inherit from Child")

    assert_equal(true, child.inherits_from?("Parent"), "Child inherits from Parent")

    assert_equal(true, grandchild.inherits_from?("Parent"), "GrandChild inherits from Parent")
    assert_equal(true, grandchild.inherits_from?("Child"), "GrandChild inherits from Child")
  end

end