Commit 6a778adc authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Automatic links to ClassNames.

DocFormatter will now look for names like Ext.form.Field and convert
them automatically to links.  The same works for method names, when
written like MyClass#method.

Only links to existing classes are created.  So that when there is
Foo.Bar in method description but the Foo.Bar class doesn't exists
(not included to documentation), then no link is created.

Additionally a DocFormatter instance is now created only once per
the creation of one documentation page, and then passed on to all
the classes taking part of page creation.  So, no more repeated
initialization code.
parent 839ece45
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ require 'jsduck/table'
module JsDuck

  class CfgTable < Table
    def initialize(cls, cache={})
      super(cls, cache)
    def initialize(cls, formatter, cache={})
      super(cls, formatter, cache)
      @type = :cfg
      @id = @cls.full_name + "-configs"
      @title = "Config Options"
+33 −0
Original line number Diff line number Diff line
@@ -21,18 +21,34 @@ module JsDuck
    # Maximum length for text that doesn't get shortened, defaults to 120
    attr_accessor :max_length

    # JsDuck::Relations for looking up class names.
    #
    # When auto-creating class links from CamelCased names found from
    # text, we check the relations object to see if a class with that
    # name actually exists.
    attr_accessor :relations

    def initialize
      @context = ""
      @css_class = nil
      @url_template = "%cls%"
      @max_length = 120
      @relations = {}
    end

    # Replaces {@link Class#member link text} in given string with
    # HTML links pointing to documentation.  In addition to the href
    # attribute links will also contain ext:cls and ext:member
    # attributes.
    #
    # Additionally replaces strings recognized as ClassNames with
    # links to these classes.  So one doesn even need to use the @link
    # tag to create a link.
    def replace(input)
      replace_class_names(replace_link_tags(input))
    end

    def replace_link_tags(input)
      input.gsub(/\{@link\s+(\S*?)(?:\s+(.+?))?\}/m) do
        target = $1
        text = $2
@@ -57,6 +73,23 @@ module JsDuck
      end
    end

    def replace_class_names(input)
      input.gsub(/(\A|\s)([A-Z][A-Za-z0-9.]*[A-Za-z0-9])(?:(#)([A-Za-z0-9]+))?([.,]?(?:\s|\Z))/m) do
        before = $1
        cls = $2
        hash = $3
        method = $4
        after = $5

        if @relations[cls]
          label = method ? cls+"."+method : cls
          before + link(cls, method, label) + after
        else
          before + cls + (hash || "") + (method || "") + after
        end
      end
    end

    # Creates HTML link to class and/or member
    def link(cls, member, label)
      anchor = member ? "#" + member : ""
+3 −3
Original line number Diff line number Diff line
@@ -5,15 +5,15 @@ require 'jsduck/long_params'
module JsDuck

  class EventTable < Table
    def initialize(cls, cache={})
      super(cls, cache)
    def initialize(cls, formatter, cache={})
      super(cls, formatter, cache)
      @type = :event
      @id = @cls.full_name + "-events"
      @title = "Public Events"
      @column_title = "Event"
      @row_class = "event-row"
      @short_params = ShortParams.new
      @long_params = LongParams.new(@cls)
      @long_params = LongParams.new(@formatter)
    end

    def signature_suffix(item)
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ module JsDuck
      @relations = relations
      @formatter = DocFormatter.new
      @formatter.css_class = 'docClass'
      @formatter.relations = relations
    end

    # Returns all data in Class object as hash.
+2 −7
Original line number Diff line number Diff line
require 'jsduck/doc_formatter'

module JsDuck

  # Creates the inheritance tree shown on class documentation page.
  class InheritanceTree
    def initialize(cls)
    def initialize(cls, formatter)
      @cls = cls
      @formatter = DocFormatter.new
      @formatter.context = cls.full_name
      @formatter.css_class = 'docClass'
      @formatter.url_template = 'output/%cls%.html'
      @formatter = formatter
    end

    # Renders the tree using HTML <pre> element
Loading