Sha256: 809d331a2a27be3d676e43736255f3a64fb5e76bc30de585309a1180fd13aa7f

Contents?: true

Size: 891 Bytes

Versions: 2

Compression:

Stored size: 891 Bytes

Contents

module JsDuck

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

    # Renders the tree using HTML <pre> element
    def to_html
      i = -1
      html = (@cls.superclasses + [@cls]).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

    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
        @formatter.link(cls.full_name, nil, cls.short_name)
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jsduck-0.6.1 lib/jsduck/inheritance_tree.rb
jsduck-0.6 lib/jsduck/inheritance_tree.rb