Commit 257e8ff5 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Extracted ParamList class.

Removed parameter list creation code from Table class as it's
only needed for EventTable and MethodTable - so it's now in
separate class that only those table-classes use.
parent 4c2cdec7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ require 'jsduck/doc_links'
require 'jsduck/table'
require 'jsduck/cfg_table'
require 'jsduck/property_table'
require 'jsduck/param_list'
require 'jsduck/method_table'
require 'jsduck/event_table'
require 'jsduck/page'
+2 −1
Original line number Diff line number Diff line
@@ -8,10 +8,11 @@ module JsDuck
      @title = "Public Events"
      @column_title = "Event"
      @row_class = "method-row"
      @param_list = ParamList.new
    end

    def signature_suffix(item)
      " : " + short_param_list(item)
      " : " + @param_list.short(item[:params])
    end
  end

+6 −1
Original line number Diff line number Diff line
@@ -8,10 +8,15 @@ module JsDuck
      @title = "Public Methods"
      @column_title = "Method"
      @row_class = "method-row"
      @param_list = ParamList.new
    end

    def signature_suffix(item)
      short_param_list(item) + " : " + (item[:return] ? (item[:return][:type] || "void") : "void")
      @param_list.short(item[:params]) + " : " + return_type(item)
    end

    def return_type(item)
      item[:return] ? (item[:return][:type] || "void") : "void"
    end
  end

+30 −0
Original line number Diff line number Diff line
module JsDuck

  # Renders method/event parameter lists
  class ParamList
    # Creates short parameters list used in signatures.
    def short(params)
      if params.length > 0
        "( " + params.collect {|p| format_short(p) }.join(", ") + " )"
      else
        "()"
      end
    end

    def format_short(param)
      type = param[:type] || "Object"
      name = param[:name] || ""
      str = "<code>#{type} #{name}</code>"
      if optional?(param)
        "<span title='Optional' class='optional'>[" + str + "]</span>"
      else
        str
      end
    end

    def optional?(param)
      return param[:doc] =~ /\(optional\)/
    end
  end

end
+0 −20
Original line number Diff line number Diff line
@@ -45,26 +45,6 @@ module JsDuck
      return "<a id='#{id}'></a><b><a href='#{src}'>#{item[:name]}</a></b>" + signature_suffix(item)
    end

    # Creates parameter list used in method and event signature.
    def short_param_list(item)
      if item[:params].length == 0
        return "()"
      end

      params = item[:params].collect do |p|
        type = p[:type] || "Object"
        name = p[:name] || ""
        str = "<code>#{type} #{name}</code>"
        if p[:doc] =~ /\(optional\)/
          "<span title='Optional' class='optional'>[" + str + "]</span>"
        else
          str
        end
      end

      return "( " + params.join(", ") + " )"
    end

    # 116 chars is also where ext-doc makes its cut, but unlike
    # ext-doc we only make the cut when there's more than 120 chars.
    #