Commit 0e2cf2d5 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Exporting optional property of parameters.

Detecting optionality of parameters at Merger level, so it's
automatically included in exports.
parent 3ec879ab
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -248,10 +248,13 @@ module JsDuck
      [implicit.length, explicit.length].max.times do |i|
        im = implicit[i] || {}
        ex = explicit[i] || {}
        doc = ex[:doc] || im[:doc] || ""
        params << {
          :type => ex[:type] || im[:type] || "Object",
          :name => ex[:name] || im[:name] || "",
          :doc => ex[:doc] || im[:doc] || "",
          :doc => doc,
          # convert to boolean for JavaScript export, otherwise it's 0 or nil
          :optional => !!(doc =~ /\(optional\)/),
        }
      end
      params
+1 −5
Original line number Diff line number Diff line
@@ -13,16 +13,12 @@ module JsDuck

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

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

end