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

Inheritance tree of ancestor classes.

Just ext-doc does it.

Updated README changelog also.
parent cee34b56
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -181,7 +181,6 @@ It's still in early beta, so several things supported by ext-doc are
currently missing:

* List of subclasses
* Tree of parent classes
* Search, not just searching from official ExtJS documentation
* Support for custom @tags

@@ -200,5 +199,6 @@ Changelog
* Latest version.
  * Links from documentation to source code
  * Syntax highlighting of code examples
  * Tree of parent classes

* 0.1 - initial version.
+51 −0
Original line number Diff line number Diff line
module JsDuck

  # Creates the inheritance tree shown on class documentation page.
  class InheritanceTree
    def initialize(cls)
      @cls = cls
    end

    # Renders the tree using HTML <pre> element
    def to_html
      i = -1
      html = ancestors(@cls).reverse.collect do |cls|
        i += 1
        make_indent(i) + make_link(cls)
      end.join("\n")

      return <<-EOHTML
        <div class="inheritance res-block">
          <pre class="res-block-inner">#{html}</pre>
        </div>
      EOHTML
    end

    # Returns array of the names of ancestor classes for given class.
    # Including the name of the class itself.
    # Example result when ascing ancestors of MyPanel might be:
    #
    #   [MyPanel, Ext.Panel, Ext.Component, Ext.util.Observable]
    #
    def ancestors(cls)
      cls.parent ? [cls] + ancestors(cls.parent) : [cls]
    end

    def make_indent(level)
      if level > 0
        ("  " * level) + "<img src='resources/elbow-end.gif' alt=''>"
      else
        ""
      end
    end

    def make_link(cls)
      if cls == @cls
        cls.short_name
      else
        "<a href='output/#{cls.full_name}.html' ext:cls='#{cls.full_name}'>#{cls.short_name}</a>"
      end
    end
  end

end
+7 −0
Original line number Diff line number Diff line
require 'jsduck/doc_formatter'
require 'jsduck/inheritance_tree'
require 'jsduck/cfg_table'
require 'jsduck/property_table'
require 'jsduck/method_table'
@@ -16,6 +17,7 @@ module JsDuck
    def to_html
      [
       '<div class="body-wrap">',
       inheritance_tree,
       heading,
       abstract,
       description,
@@ -28,6 +30,11 @@ module JsDuck
      ].join("\n")
    end

    # only render the tree if class has at least one ancestor
    def inheritance_tree
      @cls.parent ? InheritanceTree.new(@cls).to_html : ""
    end

    def heading
      "<h1>Class <a href='source/sample.html#cls-#{@cls.full_name}'>#{@cls.full_name}</a></h1>"
    end
+844 B
Loading image diff...
+2 −0
Original line number Diff line number Diff line
@@ -120,6 +120,8 @@
    margin: 5px 0;
    overflow: hidden;
    line-height: 1px;
    /* Force the line always below inheritance tree */
    clear: both;
}