Commit 40fe7098 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add #process_code method to MemberTag class.

Also implement it on JsDuck::Tag::Class, although it's not a member.

The #process_code will extract data from code that's relevant to the
current member type.
parent 396de19b
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ module JsDuck
    # producing hash as a result.
    def merge(docset, filename="", linenr=0)
      docs = docset[:comment]
      code = docset[:code]
      code = process_code(docset[:tagname], docset[:code])

      h = {
        :tagname => docset[:tagname],
@@ -33,6 +33,20 @@ module JsDuck

    private

    # When code was detected with the correct member type, leaves it
    # as is, otherwise applies processing to extract fields relevant
    # to the member type
    def process_code(tagname, code)
      if code[:tagname] == tagname
        code
      else
        result = TagRegistry.get_by_name(tagname).process_code(code)
        result[:tagname] = code[:tagname]
        result[:autodetected] = code[:autodetected]
        result
      end
    end

    # Invokes the #merge methods of tags registered for the given
    # merge context.
    def invoke_merge_in_tags(h, docs, code)
+8 −0
Original line number Diff line number Diff line
@@ -47,6 +47,14 @@ module JsDuck::Tag
      h[:name] = nested[:name]
    end

    def process_code(code)
      return {
        :name => code[:name],
        :type => code[:type],
        :default => code[:default],
      }
    end

    def to_html(cfg, cls)
      JsDuck::Render::PropertySignature.render(cfg)
    end
+7 −0
Original line number Diff line number Diff line
@@ -20,6 +20,13 @@ module JsDuck::Tag
      h[:name] = tags[0][:name]
    end

    # Although class is not a member, it also has the auto-detected
    # part from code.  So we need this method to say that when we
    # didn't detect code as a class, we only take the name from code.
    def process_code(code)
      {:name => code[:name]}
    end

    # Ensure the empty members array.
    def merge(h, docs, code)
      h[:members] = []
+8 −0
Original line number Diff line number Diff line
@@ -27,6 +27,14 @@ module JsDuck::Tag
      h[:default] = p[:default]
    end

    def process_code(code)
      return {
        :name => code[:name],
        :type => code[:type],
        :default => code[:default],
      }
    end

    def to_html(var, cls)
      JsDuck::Render::PropertySignature.render(var)
    end
+24 −0
Original line number Diff line number Diff line
@@ -56,6 +56,30 @@ module JsDuck::Tag
    MEMBER_POS_CSS_VAR = 5
    MEMBER_POS_CSS_MIXIN = 6

    # Called when the member type detected from code doesn't match
    # with the final member type determined from code + doc-comment.
    #
    # The job of this method is then to extract the fields relevant to
    # the member type.
    #
    # The input is a hash of auto-detected data. For example:
    #
    #     {:name => "foo", :type => "String", :default => "hello"}
    #
    # In the context of method :type and :default don't make any
    # sense, so we should return just the name:
    #
    #    {:name => "foo"}
    #
    # Extracting just the :name field is also the default behavior of
    # this method.
    #
    # Note: The special :tagname and :autodetected fields are filtered
    # out automatically, no need to worry about these.
    def process_code(code)
      {:name => code[:name]}
    end

    # This method defines the signature-line of the member.
    # For example it might return something like this:
    #
Loading