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

Implemented @alternateClassNames tag.

The name is now in plural (although the singular @tag works too,
but inside JSDuck the name is now "alternateClassNames" and is also
exported with that name).

Overall it behaves like @mixins tag, which too can contain multiple
items.

Correctly implemented merging of mixins and alternateClassNames when
merging class definitions.

Alternate classnames are also shown in JSDuck generated docs.
parent 3a983832
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -77,9 +77,12 @@ module JsDuck

    # Merges new class-doc into old one.
    def merge_classes(old, new)
      [:extends, :xtype, :singleton, :private, :alternateClassName, :mixins].each do |tag|
      [:extends, :xtype, :singleton, :private].each do |tag|
        old[tag] = old[tag] || new[tag]
      end
      [:mixins, :alternateClassNames].each do |tag|
        old[tag] = old[tag] + new[tag]
      end
      old[:doc] = old[:doc].length > 0 ? old[:doc] : new[:doc]
      old[:cfg] = old[:cfg] + new[:cfg]
    end
@@ -155,6 +158,7 @@ module JsDuck
        :name => name,
        :doc => "",
        :mixins => [],
        :alternateClassNames => [],
        :cfg => [],
        :property => [],
        :method => [],
+23 −6
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ module JsDuck
          at_extends
        elsif look(/@mixins?\b/)
          at_mixins
        elsif look(/@alternateClassNames?\b/)
          at_alternateClassName
        elsif look(/@singleton\b/)
          boolean_at_tag(/@singleton/, :singleton)
        elsif look(/@event\b/)
@@ -139,12 +141,16 @@ module JsDuck
      match(/@mixins?/)
      add_tag(:mixins)
      skip_horiz_white
      mixins = []
      while look(/\w/)
        mixins << ident_chain
        skip_horiz_white
      @current_tag[:mixins] = class_list
      skip_white
    end
      @current_tag[:mixins] = mixins

    # matches @alternateClassName name1 name2 ...
    def at_alternateClassName
      match(/@alternateClassNames?/)
      add_tag(:alternateClassNames)
      skip_horiz_white
      @current_tag[:alternateClassNames] = class_list
      skip_white
    end

@@ -303,6 +309,17 @@ module JsDuck
      return name
    end

    # matches <ident_chain> <ident_chain> ... until line end
    def class_list
      skip_horiz_white
      classes = []
      while look(/\w/)
        classes << ident_chain
        skip_horiz_white
      end
      classes
    end

    # matches chained.identifier.name and returns it
    def ident_chain
      @input.scan(/[\w.]+/)
+1 −1
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ module JsDuck
          cfg[:mixins] = ext_define_mixins
          found = true
        elsif look("alternateClassName", ":")
          cfg[:alternateClassName] = ext_define_alternate_class_name
          cfg[:alternateClassNames] = ext_define_alternate_class_name
          found = true
        elsif look(:ident, ":")
          match(:ident, ":")
+8 −7
Original line number Diff line number Diff line
@@ -119,8 +119,8 @@ module JsDuck
        :name => detect_name(:class, doc_map, code, :full_name),
        :doc => detect_doc(docs),
        :extends => detect_extends(doc_map, code),
        :mixins => detect_mixins(doc_map, code),
        :alternateClassName => code[:alternateClassName] || [],
        :mixins => detect_list(:mixins, doc_map, code),
        :alternateClassNames => detect_list(:alternateClassNames, doc_map, code),
        :xtype => detect_xtype(doc_map),
        :author => detect_author(doc_map),
        :docauthor => detect_docauthor(doc_map),
@@ -262,11 +262,12 @@ module JsDuck
      end
    end

    def detect_mixins(doc_map, code)
      if doc_map[:mixins]
        doc_map[:mixins].map {|d| d[:mixins] }.flatten
      elsif code[:type] == :ext_define && code[:mixins]
        code[:mixins]
    # for detecting mixins and alternateClassNames
    def detect_list(type, doc_map, code)
      if doc_map[type]
        doc_map[type].map {|d| d[type] }.flatten
      elsif code[:type] == :ext_define && code[type]
        code[type]
      else
        []
      end
+2 −1
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ module JsDuck
    def abstract
      [
       "<table cellspacing='0'>",
        boolean_row("Alternate names:", @cls[:alternateClassNames].join(", ")),
        row("Extends:", extends_link),
        classes_row("Mixins:", @cls.mixins),
        row("Defind In:", file_link),
@@ -95,7 +96,7 @@ module JsDuck
    end

    def boolean_row(label, item)
      item ? row(label, CGI.escapeHTML(item)) : ""
      (item && item != "") ? row(label, CGI.escapeHTML(item)) : ""
    end

    def row(label, info)
Loading