Commit 32dece0d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

List of subclasses for each documentation page.

Now we have reached feature-parity with ext-doc.
parent b7bbc0c5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,6 @@ Missing features
It's still in early beta, so several things supported by ext-doc are
currently missing:

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

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

* 0.1 - initial version.
+3 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ require 'jsduck/source_formatter'
require 'jsduck/class'
require 'jsduck/tree'
require 'jsduck/tree_icons'
require 'jsduck/subclasses'
require 'jsduck/page'
require 'json'
require 'fileutils'
@@ -73,10 +74,11 @@ module JsDuck

    # Writes documentation page for each class
    def write_pages(path, docs)
      subclasses = Subclasses.new(docs)
      docs.each do |cls|
        filename = path + "/" + cls[:name] + ".html"
        puts "Writing to #{filename} ..." if @verbose
        File.open(filename, 'w') {|f| f.write( Page.new(cls).to_html ) }
        File.open(filename, 'w') {|f| f.write( Page.new(cls, subclasses).to_html ) }
      end
    end

+11 −3
Original line number Diff line number Diff line
@@ -9,8 +9,9 @@ module JsDuck

  # Creates HTML documentation page for one class.
  class Page
    def initialize(cls)
    def initialize(cls, subclasses = {})
      @cls = cls
      @subclasses = subclasses
      @formatter = DocFormatter.new(cls.full_name)
    end

@@ -44,18 +45,25 @@ module JsDuck
       "<table cellspacing='0'>",
        abstract_row("Extends:", @cls.parent ? class_link(@cls.parent.full_name) : "Object"),
        abstract_row("Defind In:", file_link),
        @subclasses[@cls] ? abstract_row("Subclasses:", subclasses) : "",
       "</table>",
      ].join("\n")
    end

    def class_link(name)
      "<a href='output/#{name}.html' ext:cls='#{name}'>#{name}</a>"
    def class_link(class_name, label=nil)
      label = label || class_name
      "<a href='output/#{class_name}.html' ext:cls='#{class_name}'>#{label}</a>"
    end

    def file_link
      "<a href='source/#{@cls[:href]}'>#{@cls[:filename]}</a>"
    end

    def subclasses
      subs = @subclasses[@cls].sort {|a, b| a.short_name <=> b.short_name }
      subs.collect {|cls| class_link(cls.full_name, cls.short_name) }.join(", ")
    end

    def abstract_row(label, info)
      "<tr><td class='label'>#{label}</td><td class='hd-info'>#{info}</td></tr>"
    end
+27 −0
Original line number Diff line number Diff line
module JsDuck

  # Provides information about direct descendants of particular class.
  #
  # The constructor is initialized with array of all available
  # classes.  Then through [] method subclasses of particlular class
  # can be asked for.
  class Subclasses
    def initialize(classes)
      @subs = {}
      classes.each do |cls|
        if !cls.parent
          # do nothing
        elsif @subs[cls.parent.full_name]
          @subs[cls.parent.full_name] << cls
        else
          @subs[cls.parent.full_name] = [cls]
        end
      end
    end

    def [](cls)
      @subs[cls.full_name]
    end
  end

end