Commit 50ed5844 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move part of procession in DocAst to Tag classes.

Tags can now define #key attribute and #process_doc method - the
latter will take care of combining the results of #parse.

Detection of @hide and @inheritable is now entirely done in
corresponding Tag classes.
parent 1735d1f0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -5,11 +5,16 @@ module JsDuck::Builtins
  class Hide < Tag
    def initialize
      @pattern = "hide"
      @key = :hide
    end

    # @hide
    def parse(p)
      p.add_tag(:hide)
    end

    def process_doc(docs)
      true
    end
  end
end
+5 −0
Original line number Diff line number Diff line
@@ -4,11 +4,16 @@ module JsDuck::Builtins
  class Inheritable < Tag
    def initialize
      @pattern = "inheritable"
      @key = :inheritable
    end

    # @inheritable
    def parse(p)
      p.add_tag(:inheritable)
    end

    def process_doc(docs)
      true
    end
  end
end
+10 −0
Original line number Diff line number Diff line
@@ -11,6 +11,16 @@ module JsDuck::Builtins
    def parse(p)
    end

    # Defines the symbol under which the tag data is stored in final
    # member/class hash.
    attr_reader :key

    # Gets called with array of @tag data that was generated by
    # #parse.  The return value is stored under :key in the resulting
    # member/class hash.
    def process_doc(docs)
    end

    # Defines the name of object property in Ext.define()
    # configuration which, when encountered, will cause the
    # #parse_ext_define method to be invoked.
+9 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ module JsDuck
      @patterns = {}
      @ext_define_patterns = {}
      @ext_define_defaults = {}
      @keys = {}
      load_tag_classes(File.dirname(__FILE__) + "/builtins")
      instantiate_tags
    end
@@ -33,6 +34,9 @@ module JsDuck
        if tag.ext_define_default
          @ext_define_defaults.merge!(tag.ext_define_default)
        end
        if tag.key
          @keys[tag.key] = tag
        end
      end
    end

@@ -49,6 +53,11 @@ module JsDuck
    # Default values for class config when Ext.define is encountered.
    attr_reader :ext_define_defaults

    # Accesses tag by key name - the symbol under which the tag data
    # is stored in final hash.
    def get_by_key(key)
      @keys[key]
    end
  end

end
+6 −2
Original line number Diff line number Diff line
@@ -134,12 +134,16 @@ module JsDuck
    # Detects properties common for each doc-object and adds them
    def add_shared(hash, doc_map)
      hash.merge!({
        :inheritable => !!doc_map[:inheritable],
        :hide => !!doc_map[:hide],
        :inheritdoc => extract(doc_map, :inheritdoc),
        :meta => detect_meta(doc_map),
      })

      doc_map.each_pair do |key, value|
        if tag = BuiltinsRegistry.get_by_key(key)
          hash[key] = tag.process_doc(value)
        end
      end

      # copy :private also to main hash
      hash[:private] = hash[:meta][:private] ? true : nil