Commit 5fcb3ac4 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Change #process_code to take two params.

Instead of just returning the hash, process_code will now add fields
To the supplied context hash, with implementation in MemberTag covering
the base case and subclasses adding their extra logic on top of that.

Transformation of member name from "foo.bar.baz" to "baz" now
happens within MemberTag#process_code, while Class#process_code leaves
the name as is.

The #process_code now gets called for every time - both when the member
type was detected correctly and when it was not.
parent 40fe7098
Loading
Loading
Loading
Loading
+4 −11
Original line number Diff line number Diff line
@@ -33,19 +33,12 @@ 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
    # 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 = {}
      TagRegistry.get_by_name(tagname).process_code(result, code)
      result
    end
    end

    # Invokes the #merge methods of tags registered for the given
    # merge context.
+6 −6
Original line number Diff line number Diff line
@@ -47,12 +47,12 @@ module JsDuck::Tag
      h[:name] = nested[:name]
    end

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

    def to_html(cfg, cls)
+10 −4
Original line number Diff line number Diff line
@@ -21,10 +21,16 @@ module JsDuck::Tag
    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]}
    # part from code. So this method gets called by Merger.
    #
    # If we did detect code as a class use all the auto-detected
    # fields, otherwise use only the name field.
    def process_code(h, code)
      if code[:tagname] == :class
        h.merge!(code)
      else
        h[:name] = code[:name]
      end
    end

    # Ensure the empty members array.
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ module JsDuck::Tag
  # :css_mixin.
  class CssMixin < MemberTag
    def initialize
      @tagname = :css_mixin
      @member_type = {
        :name => :css_mixin,
        :category => :method_like,
+4 −6
Original line number Diff line number Diff line
@@ -27,12 +27,10 @@ module JsDuck::Tag
      h[:default] = p[:default]
    end

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

    def to_html(var, cls)
Loading